mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-07 22:56:30 -10:00
waypoint upgrades
This commit is contained in:
1 parent
f9591b3a92
commit
42fc9891e3
4 files changed
+76
-113
No files matched your search
@@ -504,8 +504,8 @@ void obj_free(int objnum)
|
||||
* The object will be a non-rendering, non-physics object. Pass -1 if no parent.
|
||||
* @return the object number
|
||||
*/
|
||||
int obj_create(ubyte type,int parent_obj,int instance, matrix * orient,
|
||||
vec3d * pos, float radius, const flagset<Object::Object_Flags> &flags, bool essential)
|
||||
int obj_create(ubyte type, int parent_obj, int instance, const matrix *orient,
|
||||
const vec3d *pos, float radius, const flagset<Object::Object_Flags> &flags, bool essential)
|
||||
{
|
||||
int objnum;
|
||||
object *obj;
|
||||
|
||||
@@ -263,7 +263,7 @@ void obj_shutdown();
|
||||
//object. Returns 0 if failed, otherwise object index.
|
||||
//You can pass 0 for parent if you don't care about that.
|
||||
//You can pass null for orient and/or pos if you don't care.
|
||||
int obj_create(ubyte type,int parent_obj, int instance, matrix * orient, vec3d * pos, float radius, const flagset<Object::Object_Flags> &flags, bool essential = true );
|
||||
int obj_create(ubyte type, int parent_obj, int instance, const matrix *orient, const vec3d *pos, float radius, const flagset<Object::Object_Flags> &flags, bool essential = true);
|
||||
|
||||
void obj_render(object* obj);
|
||||
|
||||
|
||||
+59
-98
@@ -7,14 +7,14 @@
|
||||
#include "network/multiutil.h"
|
||||
|
||||
//********************GLOBALS********************
|
||||
SCP_list<waypoint_list> Waypoint_lists;
|
||||
SCP_vector<waypoint_list> Waypoint_lists;
|
||||
|
||||
// In order to restore ai_info to a plain-old-data struct, ai_info->wp_index
|
||||
// now uses size_t rather than iterator to index into the list. If ai_info
|
||||
// eventually becomes an actual class, we ought to go back to using iterators.
|
||||
//SCP_list<waypoint> dummy_waypoint;
|
||||
//const SCP_list<waypoint>::iterator INVALID_WAYPOINT_POSITION = dummy_waypoint.end();
|
||||
const size_t INVALID_WAYPOINT_POSITION = (size_t) -1;
|
||||
// 2023 addendum - Perhaps not; iterators don't gain us much compared to
|
||||
// indexes. See commit b4cc5d72f4 for the historical context.
|
||||
const int INVALID_WAYPOINT_POSITION = INT_MAX;
|
||||
|
||||
//********************CLASS MEMBERS********************
|
||||
waypoint::waypoint()
|
||||
@@ -27,7 +27,7 @@ waypoint::waypoint()
|
||||
this->m_parent_list = NULL;
|
||||
}
|
||||
|
||||
waypoint::waypoint(vec3d *position, waypoint_list *parent_list)
|
||||
waypoint::waypoint(const vec3d *position, waypoint_list *parent_list)
|
||||
{
|
||||
Assert(position != NULL);
|
||||
|
||||
@@ -44,22 +44,27 @@ waypoint::~waypoint()
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
vec3d *waypoint::get_pos()
|
||||
const vec3d *waypoint::get_pos() const
|
||||
{
|
||||
return &m_position;
|
||||
}
|
||||
|
||||
int waypoint::get_objnum()
|
||||
int waypoint::get_objnum() const
|
||||
{
|
||||
return objnum;
|
||||
}
|
||||
|
||||
const waypoint_list *waypoint::get_parent_list() const
|
||||
{
|
||||
return m_parent_list;
|
||||
}
|
||||
|
||||
waypoint_list *waypoint::get_parent_list()
|
||||
{
|
||||
return m_parent_list;
|
||||
}
|
||||
|
||||
void waypoint::set_pos(vec3d *pos)
|
||||
void waypoint::set_pos(const vec3d *pos)
|
||||
{
|
||||
Assert(pos != NULL);
|
||||
this->m_position = *pos;
|
||||
@@ -82,11 +87,16 @@ waypoint_list::~waypoint_list()
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
char *waypoint_list::get_name()
|
||||
const char *waypoint_list::get_name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
const SCP_vector<waypoint> &waypoint_list::get_waypoints() const
|
||||
{
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
SCP_vector<waypoint> &waypoint_list::get_waypoints()
|
||||
{
|
||||
return waypoints;
|
||||
@@ -144,16 +154,13 @@ void waypoint_create_game_object(waypoint *wpt, int list_index, int wpt_index)
|
||||
// done immediately after mission load; originally found in aicode.cpp
|
||||
void waypoint_create_game_objects()
|
||||
{
|
||||
SCP_list<waypoint_list>::iterator ii;
|
||||
SCP_vector<waypoint>::iterator jj;
|
||||
|
||||
int list = 0;
|
||||
for (ii = Waypoint_lists.begin(); ii != Waypoint_lists.end(); ++ii)
|
||||
for (auto &ii: Waypoint_lists)
|
||||
{
|
||||
int wpt = 0;
|
||||
for (jj = ii->get_waypoints().begin(); jj != ii->get_waypoints().end(); ++jj)
|
||||
for (auto &jj: ii.get_waypoints())
|
||||
{
|
||||
waypoint_create_game_object(&(*jj), list, wpt);
|
||||
waypoint_create_game_object(&jj, list, wpt);
|
||||
wpt++;
|
||||
}
|
||||
list++;
|
||||
@@ -163,12 +170,11 @@ void waypoint_create_game_objects()
|
||||
waypoint_list *find_matching_waypoint_list(const char *name)
|
||||
{
|
||||
Assert(name != NULL);
|
||||
SCP_list<waypoint_list>::iterator ii;
|
||||
|
||||
for (ii = Waypoint_lists.begin(); ii != Waypoint_lists.end(); ++ii)
|
||||
for (auto &ii: Waypoint_lists)
|
||||
{
|
||||
if (!stricmp(ii->get_name(), name))
|
||||
return &(*ii);
|
||||
if (!stricmp(ii.get_name(), name))
|
||||
return ⅈ
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -178,14 +184,13 @@ waypoint_list *find_matching_waypoint_list(const char *name)
|
||||
waypoint *find_matching_waypoint(const char *name)
|
||||
{
|
||||
Assert(name != NULL);
|
||||
SCP_list<waypoint_list>::iterator ii;
|
||||
|
||||
for (ii = Waypoint_lists.begin(); ii != Waypoint_lists.end(); ++ii)
|
||||
for (auto &ii: Waypoint_lists)
|
||||
{
|
||||
auto len = strlen(ii->get_name());
|
||||
auto len = strlen(ii.get_name());
|
||||
|
||||
// the first half (before the :) matches
|
||||
if (!strnicmp(ii->get_name(), name, len))
|
||||
if (!strnicmp(ii.get_name(), name, len))
|
||||
{
|
||||
// this is ok because it could be "Waypoint path 1" vs. "Waypoint path 10"
|
||||
if (*(name + len) != ':')
|
||||
@@ -217,13 +222,13 @@ waypoint *find_matching_waypoint(const char *name)
|
||||
|
||||
// get the number and make sure it's in range
|
||||
uint index = atoi(index_str);
|
||||
if (index < 1 || index > ii->get_waypoints().size())
|
||||
if (index < 1 || index > ii.get_waypoints().size())
|
||||
{
|
||||
nprintf(("waypoints", "possible error with waypoint name '%s': waypoint number is out of range\n", name));
|
||||
continue;
|
||||
}
|
||||
|
||||
return find_waypoint_at_index(&(*ii), index - 1);
|
||||
return find_waypoint_at_index(&ii, index - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,15 +240,12 @@ waypoint *find_waypoint_with_objnum(int objnum)
|
||||
if (objnum < 0 || Objects[objnum].type != OBJ_WAYPOINT)
|
||||
return NULL;
|
||||
|
||||
SCP_list<waypoint_list>::iterator ii;
|
||||
SCP_vector<waypoint>::iterator jj;
|
||||
|
||||
for (ii = Waypoint_lists.begin(); ii != Waypoint_lists.end(); ++ii)
|
||||
for (auto &ii: Waypoint_lists)
|
||||
{
|
||||
for (jj = ii->get_waypoints().begin(); jj != ii->get_waypoints().end(); ++jj)
|
||||
for (auto &jj: ii.get_waypoints())
|
||||
{
|
||||
if (jj->get_objnum() == objnum)
|
||||
return &(*jj);
|
||||
if (jj.get_objnum() == objnum)
|
||||
return &jj;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,14 +293,8 @@ waypoint_list *find_waypoint_list_at_index(int index)
|
||||
{
|
||||
Assert(index >= 0);
|
||||
|
||||
int i = 0;
|
||||
SCP_list<waypoint_list>::iterator ii;
|
||||
|
||||
for (ii = Waypoint_lists.begin(); ii != Waypoint_lists.end(); ++i, ++ii)
|
||||
{
|
||||
if (i == index)
|
||||
return &(*ii);
|
||||
}
|
||||
if (index >= 0 && index < (int)Waypoint_lists.size())
|
||||
return &Waypoint_lists[index];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -308,47 +304,33 @@ waypoint *find_waypoint_at_index(waypoint_list *list, int index)
|
||||
Assert(list != NULL);
|
||||
Assert(index >= 0);
|
||||
|
||||
int i = 0;
|
||||
SCP_vector<waypoint>::iterator ii;
|
||||
|
||||
for (ii = list->get_waypoints().begin(); ii != list->get_waypoints().end(); ++i, ++ii)
|
||||
{
|
||||
if (i == index)
|
||||
return &(*ii);
|
||||
}
|
||||
if (index >= 0 && index < (int)list->get_waypoints().size())
|
||||
return &list->get_waypoints()[index];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int find_index_of_waypoint_list(waypoint_list *wp_list)
|
||||
int find_index_of_waypoint_list(const waypoint_list *wp_list)
|
||||
{
|
||||
Assert(wp_list != NULL);
|
||||
SCP_list<waypoint_list>::iterator ii;
|
||||
|
||||
int index = 0;
|
||||
for (ii = Waypoint_lists.begin(); ii != Waypoint_lists.end(); ++ii)
|
||||
{
|
||||
if (&(*ii) == wp_list)
|
||||
return index;
|
||||
index++;
|
||||
}
|
||||
auto index = wp_list - Waypoint_lists.data();
|
||||
|
||||
if (index >= 0 && index < Waypoint_lists.size())
|
||||
return (int)index;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int find_index_of_waypoint(waypoint_list *wp_list, waypoint *wpt)
|
||||
int find_index_of_waypoint(const waypoint_list *wp_list, const waypoint *wpt)
|
||||
{
|
||||
Assert(wp_list != NULL);
|
||||
Assert(wpt != NULL);
|
||||
SCP_vector<waypoint>::iterator ii;
|
||||
|
||||
int index = 0;
|
||||
for (ii = wp_list->get_waypoints().begin(); ii != wp_list->get_waypoints().end(); ++ii)
|
||||
{
|
||||
if (&(*ii) == wpt)
|
||||
return index;
|
||||
index++;
|
||||
}
|
||||
auto index = wpt - wp_list->get_waypoints().data();
|
||||
|
||||
if (index >= 0 && index < wp_list->get_waypoints().size())
|
||||
return (int)index;
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -370,7 +352,7 @@ void waypoint_find_unique_name(char *dest_name, int start_index)
|
||||
} while (collision != NULL);
|
||||
}
|
||||
|
||||
void waypoint_add_list(const char *name, SCP_vector<vec3d> &vec_list)
|
||||
void waypoint_add_list(const char *name, const SCP_vector<vec3d> &vec_list)
|
||||
{
|
||||
Assert(name != NULL);
|
||||
|
||||
@@ -385,10 +367,9 @@ void waypoint_add_list(const char *name, SCP_vector<vec3d> &vec_list)
|
||||
waypoint_list *wp_list = &Waypoint_lists.back();
|
||||
|
||||
wp_list->get_waypoints().reserve(vec_list.size());
|
||||
SCP_vector<vec3d>::iterator ii;
|
||||
for (ii = vec_list.begin(); ii != vec_list.end(); ++ii)
|
||||
for (const auto &ii: vec_list)
|
||||
{
|
||||
waypoint new_waypoint(&(*ii), wp_list);
|
||||
waypoint new_waypoint(&ii, wp_list);
|
||||
wp_list->get_waypoints().push_back(new_waypoint);
|
||||
}
|
||||
|
||||
@@ -397,7 +378,7 @@ void waypoint_add_list(const char *name, SCP_vector<vec3d> &vec_list)
|
||||
Assert(wp_list->get_waypoints().size() <= 0xffff);
|
||||
}
|
||||
|
||||
int waypoint_add(vec3d *pos, int waypoint_instance)
|
||||
int waypoint_add(const vec3d *pos, int waypoint_instance)
|
||||
{
|
||||
Assert(pos != NULL);
|
||||
waypoint_list *wp_list;
|
||||
@@ -450,10 +431,7 @@ int waypoint_add(vec3d *pos, int waypoint_instance)
|
||||
waypoint new_waypoint(pos, wp_list);
|
||||
|
||||
// add it at its appropriate spot, which may be the end of the list
|
||||
SCP_vector<waypoint>::iterator ii = wp_list->get_waypoints().begin();
|
||||
for (i = 0; i < wp_index; i++)
|
||||
++ii;
|
||||
wp_list->get_waypoints().insert(ii, new_waypoint);
|
||||
wp_list->get_waypoints().insert(wp_list->get_waypoints().begin() + wp_index, new_waypoint);
|
||||
wpt = find_waypoint_at_index(wp_list, wp_index);
|
||||
|
||||
// apparently we create it in-game too; this is called by both scripting and FRED
|
||||
@@ -462,14 +440,15 @@ int waypoint_add(vec3d *pos, int waypoint_instance)
|
||||
return wpt->get_objnum();
|
||||
}
|
||||
|
||||
void waypoint_remove(waypoint *wpt)
|
||||
void waypoint_remove(const waypoint *wpt)
|
||||
{
|
||||
int objnum = wpt->get_objnum();
|
||||
waypoint_list *wp_list = wpt->get_parent_list();
|
||||
|
||||
int this_list = calc_waypoint_list_index(Objects[objnum].instance);
|
||||
int this_index = calc_waypoint_index(Objects[objnum].instance);
|
||||
|
||||
waypoint_list *wp_list = find_waypoint_list_at_index(this_list);
|
||||
Assert(wp_list == wpt->get_parent_list());
|
||||
|
||||
// special case... this is the only waypoint on its list
|
||||
if (wp_list->get_waypoints().size() == 1)
|
||||
{
|
||||
@@ -484,16 +463,7 @@ void waypoint_remove(waypoint *wpt)
|
||||
else
|
||||
{
|
||||
// remove this particular waypoint list
|
||||
SCP_list<waypoint_list>::iterator ii;
|
||||
int i;
|
||||
for (i = 0, ii = Waypoint_lists.begin(); ii != Waypoint_lists.end(); ++i, ++ii)
|
||||
{
|
||||
if (i == this_list)
|
||||
{
|
||||
Waypoint_lists.erase(ii);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Waypoint_lists.erase(Waypoint_lists.begin() + this_list);
|
||||
|
||||
// iterate through all waypoints that are in lists later than this one,
|
||||
// and edit their instances so that they point to a list one place lower
|
||||
@@ -508,16 +478,7 @@ void waypoint_remove(waypoint *wpt)
|
||||
else
|
||||
{
|
||||
// remove this particular waypoint
|
||||
SCP_vector<waypoint>::iterator ii;
|
||||
int i;
|
||||
for (i = 0, ii = wp_list->get_waypoints().begin(); ii != wp_list->get_waypoints().end(); ++i, ++ii)
|
||||
{
|
||||
if (i == this_index)
|
||||
{
|
||||
wp_list->get_waypoints().erase(ii);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wp_list->get_waypoints().erase(wp_list->get_waypoints().begin() + this_index);
|
||||
|
||||
// iterate through all waypoints that are later than this one,
|
||||
// and edit their instances so that they point to a waypoint one place lower
|
||||
|
||||
+14
-12
@@ -11,16 +11,17 @@ class waypoint
|
||||
{
|
||||
public:
|
||||
waypoint();
|
||||
waypoint(vec3d *pos, waypoint_list *parent_list);
|
||||
waypoint(const vec3d *pos, waypoint_list *parent_list);
|
||||
~waypoint();
|
||||
|
||||
// accessors
|
||||
vec3d *get_pos();
|
||||
int get_objnum();
|
||||
const vec3d *get_pos() const;
|
||||
int get_objnum() const;
|
||||
const waypoint_list *get_parent_list() const;
|
||||
waypoint_list *get_parent_list();
|
||||
|
||||
// mutators
|
||||
void set_pos(vec3d *pos);
|
||||
void set_pos(const vec3d *pos);
|
||||
|
||||
private:
|
||||
vec3d m_position;
|
||||
@@ -38,7 +39,8 @@ class waypoint_list
|
||||
~waypoint_list();
|
||||
|
||||
// accessors
|
||||
char *get_name();
|
||||
const char *get_name() const;
|
||||
const SCP_vector<waypoint> &get_waypoints() const;
|
||||
SCP_vector<waypoint> &get_waypoints();
|
||||
|
||||
// mutators
|
||||
@@ -50,10 +52,10 @@ class waypoint_list
|
||||
};
|
||||
|
||||
//********************GLOBALS********************
|
||||
extern SCP_list<waypoint_list> Waypoint_lists;
|
||||
extern SCP_vector<waypoint_list> Waypoint_lists;
|
||||
|
||||
// bah
|
||||
extern const size_t INVALID_WAYPOINT_POSITION;
|
||||
extern const int INVALID_WAYPOINT_POSITION;
|
||||
|
||||
//********************FUNCTIONS********************
|
||||
void waypoint_level_close();
|
||||
@@ -81,20 +83,20 @@ waypoint *find_waypoint_with_instance(int waypoint_instance);
|
||||
// Find something at the specified index
|
||||
waypoint_list *find_waypoint_list_at_index(int index);
|
||||
waypoint *find_waypoint_at_index(waypoint_list *list, int index);
|
||||
int find_index_of_waypoint_list(waypoint_list *wp_list);
|
||||
int find_index_of_waypoint(waypoint_list *wp_list, waypoint *wpt);
|
||||
int find_index_of_waypoint_list(const waypoint_list *wp_list);
|
||||
int find_index_of_waypoint(const waypoint_list *wp_list, const waypoint *wpt);
|
||||
|
||||
// Find a name that doesn't conflict with any current waypoint list
|
||||
void waypoint_find_unique_name(char *dest_name, int start_index);
|
||||
|
||||
// Add a new list of waypoints. Called from mission parsing.
|
||||
void waypoint_add_list(const char *name, SCP_vector<vec3d> &vec_list);
|
||||
void waypoint_add_list(const char *name, const SCP_vector<vec3d> &vec_list);
|
||||
|
||||
// Attempts to create a waypoint with the specified instance (used to calculate list and index).
|
||||
// Returns the object number, or -1 on failure. Used by scripting and FRED.
|
||||
int waypoint_add(vec3d *pos, int waypoint_instance);
|
||||
int waypoint_add(const vec3d *pos, int waypoint_instance);
|
||||
|
||||
// Removes a waypoint, including its entire list if it's the last waypoint remaining.
|
||||
void waypoint_remove(waypoint *wpt);
|
||||
void waypoint_remove(const waypoint *wpt);
|
||||
|
||||
#endif //_WAYPOINT_H
|
||||
Reference in new issue
Block a user