Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions code/object/waypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const int INVALID_WAYPOINT_POSITION = INT_MAX;
//********************CLASS MEMBERS********************
waypoint::waypoint()
{
this->m_position.xyz.x = 0.0f;
this->m_position.xyz.y = 0.0f;
this->m_position.xyz.z = 0.0f;
this->m_parsed_position.xyz.x = 0.0f;
this->m_parsed_position.xyz.y = 0.0f;
this->m_parsed_position.xyz.z = 0.0f;

this->m_objnum = -1;
}
Expand All @@ -31,9 +31,9 @@ waypoint::waypoint(const vec3d *position)
{
Assert(position != NULL);

this->m_position.xyz.x = position->xyz.x;
this->m_position.xyz.y = position->xyz.y;
this->m_position.xyz.z = position->xyz.z;
this->m_parsed_position.xyz.x = position->xyz.x;
this->m_parsed_position.xyz.y = position->xyz.y;
this->m_parsed_position.xyz.z = position->xyz.z;

this->m_objnum = -1;
}
Expand All @@ -45,7 +45,10 @@ waypoint::~waypoint()

const vec3d *waypoint::get_pos() const
{
return &m_position;
if (m_objnum >= 0)
return &Objects[m_objnum].pos;

return &m_parsed_position;
}

int waypoint::get_objnum() const
Expand Down Expand Up @@ -90,7 +93,11 @@ int waypoint::get_index() const
void waypoint::set_pos(const vec3d *pos)
{
Assert(pos != NULL);
this->m_position = *pos;

if (m_objnum >= 0)
Objects[m_objnum].pos = *pos;
else
this->m_parsed_position = *pos;
}

waypoint_list::waypoint_list()
Expand Down
2 changes: 1 addition & 1 deletion code/object/waypoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class waypoint
void set_pos(const vec3d *pos);

private:
vec3d m_position;
vec3d m_parsed_position; // only relevant until the game object is created, after which the waypoint delegates to the object position
int m_objnum;

friend void waypoint_create_game_object(waypoint *wpt, int list_index, int wpt_index);
Expand Down
2 changes: 0 additions & 2 deletions code/parse/sexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9512,7 +9512,6 @@ void sexp_set_object_position(int n)

case OSWPT_TYPE_WAYPOINT:
{
oswpt.objp()->pos = target_vec;
oswpt.waypointp()->set_pos(&target_vec);
Current_sexp_network_packet.start_callback();
Current_sexp_network_packet.send_ushort(oswpt.objp()->net_signature);
Expand Down Expand Up @@ -9600,7 +9599,6 @@ void multi_sexp_set_object_position()
Current_sexp_network_packet.get_float(wp_vec.xyz.z);
objp = multi_get_network_object(obj_sig);
if (objp->type == OBJ_WAYPOINT) {
objp->pos = wp_vec;
waypoint *wpt = find_waypoint_with_instance(objp->instance);
wpt->set_pos(&wp_vec);
}
Expand Down
3 changes: 2 additions & 1 deletion code/scripting/api/objs/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ ADE_VIRTVAR(Position, l_Object, "vector", "Object world position (World vector)"
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));

if(ADE_SETTING_VAR && v3 != NULL) {
objh->objp()->pos = *v3;
if (objh->objp()->type == OBJ_WAYPOINT) {
waypoint *wpt = find_waypoint_with_instance(objh->objp()->instance);
wpt->set_pos(v3);
} else {
objh->objp()->pos = *v3;
}

if (objh->objp()->flags[Object::Object_Flags::Collides])
Expand Down
Loading