mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-10 04:31:34 -10:00
- Add On Mission Start, On Mission End hooks; swap Warpin and Warpout to Warp In and Warp Out - Safer handle helper structs - Improved math, eg matrix interpolation and vector multiply/divide - Filesystem read AND write support - Initial scripting orders support - Better waypoints support - Assorted requested scripting functions bmpman: - Safer bm_get_filename cfile: - Support for RW, rather than just R or W, file modes. model: - Safer texture_info struct. Taylor, I know we talked about this, but I realized that it was just a lot better for what it does and it shouldn't be too much trouble to replace with the new system (operations tend to be much more concise and clear). Let me know if any unexpected difficulties arise.
132 lines
3.3 KiB
C++
132 lines
3.3 KiB
C++
#include "globalincs/linklist.h"
|
|
#include "object/waypoint.h"
|
|
#include "object/object.h"
|
|
|
|
//********************GLOBALS********************
|
|
waypoint_list Waypoint_lists[MAX_WAYPOINT_LISTS];
|
|
int Num_waypoint_lists = 0;
|
|
|
|
//********************FUNCTIONS********************
|
|
int waypoint_query_path_name_duplicate(int list)
|
|
{
|
|
int i;
|
|
|
|
for (i=0; i<Num_waypoint_lists; i++)
|
|
if (i != list)
|
|
if (!stricmp(Waypoint_lists[i].name, Waypoint_lists[list].name))
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void waypoint_get_unique_path_name(int list)
|
|
{
|
|
int i = 1;
|
|
|
|
sprintf(Waypoint_lists[list].name, "Waypoint path %d", list + 1);
|
|
while (waypoint_query_path_name_duplicate(list)) {
|
|
sprintf(Waypoint_lists[list].name, "Waypoint path U%d", i++);
|
|
}
|
|
}
|
|
|
|
int waypoint_create(vec3d *pos, int list)
|
|
{
|
|
int i, obj, index = 0;
|
|
object *ptr;
|
|
|
|
if (list == -1) { // find a new list to start.
|
|
for (list=0; list<MAX_WAYPOINT_LISTS; list++){
|
|
if (!Waypoint_lists[list].count) {
|
|
waypoint_get_unique_path_name(list);
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
index = (list & 0xffff) + 1;
|
|
list /= 65536;
|
|
}
|
|
|
|
if (list == MAX_WAYPOINT_LISTS) {
|
|
/*
|
|
Fred_main_wnd->MessageBox("Unable to create new waypoint path. You\n"
|
|
"have reached the maximum limit.", NULL, MB_OK | MB_ICONEXCLAMATION);
|
|
*/
|
|
Warning(LOCATION, "Unable to create new waypoint path. You have reached the maximum limit.");
|
|
return -1;
|
|
}
|
|
|
|
Assert((list >= 0) && (list < MAX_WAYPOINT_LISTS)); // illegal index or out of lists.
|
|
if (Waypoint_lists[list].count >= MAX_WAYPOINTS_PER_LIST) {
|
|
/*Fred_main_wnd->MessageBox("Unable to create new waypoint. You have\n"
|
|
"reached the maximum limit on waypoints per list.", NULL, MB_OK | MB_ICONEXCLAMATION);*/
|
|
Warning(LOCATION, "Unable to create new waypoint. You have reached the maximum limit on waypoints per list.");
|
|
return -1;
|
|
}
|
|
|
|
if (Waypoint_lists[list].count > index) {
|
|
i = Waypoint_lists[list].count;
|
|
while (i > index) {
|
|
Waypoint_lists[list].waypoints[i] = Waypoint_lists[list].waypoints[i - 1];
|
|
Waypoint_lists[list].flags[i] = Waypoint_lists[list].flags[i - 1];
|
|
i--;
|
|
}
|
|
}
|
|
|
|
ptr = GET_FIRST(&obj_used_list);
|
|
while (ptr != END_OF_LIST(&obj_used_list)) {
|
|
Assert(ptr->type != OBJ_NONE);
|
|
if (ptr->type == OBJ_WAYPOINT) {
|
|
i = ptr->instance;
|
|
if ((i / 65536 == list) && ((i & 0xffff) >= index)){
|
|
ptr->instance++;
|
|
}
|
|
}
|
|
|
|
ptr = GET_NEXT(ptr);
|
|
}
|
|
|
|
Waypoint_lists[list].count++;
|
|
Waypoint_lists[list].flags[index] = 0;
|
|
Waypoint_lists[list].waypoints[index] = *pos;
|
|
if (list >= Num_waypoint_lists){
|
|
Num_waypoint_lists = list + 1;
|
|
}
|
|
|
|
obj = obj_create(OBJ_WAYPOINT, -1, list * 65536 + index, NULL, pos, 0.0f, OF_RENDERS);
|
|
return obj;
|
|
}
|
|
|
|
// return object index of waypoint or -1 if no such waypoint
|
|
int waypoint_lookup(char *name)
|
|
{
|
|
char buf[128];
|
|
int i;
|
|
object *ptr;
|
|
|
|
if (name == NULL)
|
|
return -1;
|
|
|
|
ptr = GET_FIRST(&obj_used_list);
|
|
while (ptr != END_OF_LIST(&obj_used_list)) {
|
|
if (ptr->type == OBJ_WAYPOINT) {
|
|
i = ptr->instance;
|
|
sprintf(buf, "%s:%d", Waypoint_lists[i / 65536].name, (i & 0xffff) + 1);
|
|
if ( !stricmp(buf, name) )
|
|
return OBJ_INDEX(ptr);
|
|
}
|
|
|
|
ptr = GET_NEXT(ptr);
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
//Return waypoint list index
|
|
int waypoint_get_list(object *objp)
|
|
{
|
|
if(objp->type != OBJ_WAYPOINT)
|
|
return -1;
|
|
|
|
return (objp->instance/65536);
|
|
}
|