Skip to content
Draft
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
14 changes: 6 additions & 8 deletions code/hud/hudtargetbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1322,13 +1322,11 @@ void HudGaugeTargetBox::renderTargetJumpNode(object *target_objp)
matrix camera_orient = IDENTITY_MATRIX;
float factor, dist;
int hx = 0, hy = 0, w, h;
SCP_list<CJumpNode>::iterator jnp;

for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
if(jnp->GetSCPObject() != target_objp)
for (auto &jnp : Jump_nodes) {
if(jnp.GetSCPObject() != target_objp)
continue;
if ( jnp->IsHidden() ) {

if ( jnp.IsHidden() ) {
set_target_objnum( Player_ai, -1 );
return;
}
Expand Down Expand Up @@ -1357,7 +1355,7 @@ void HudGaugeTargetBox::renderTargetJumpNode(object *target_objp)
gr_stencil_set(GR_STENCIL_READ);
}

jnp->Render( &obj_pos );
jnp.Render( &obj_pos );

if ( Monitor_mask >= 0 ) {
gr_stencil_set(GR_STENCIL_NONE);
Expand All @@ -1370,7 +1368,7 @@ void HudGaugeTargetBox::renderTargetJumpNode(object *target_objp)
renderTargetIntegrity(1);
setGaugeColor();

renderString(position[0] + Name_offsets[0], position[1] + Name_offsets[1], EG_TBOX_NAME, jnp->GetDisplayName());
renderString(position[0] + Name_offsets[0], position[1] + Name_offsets[1], EG_TBOX_NAME, jnp.GetDisplayName());

dist = Player_ai->current_target_distance;
if ( Hud_unit_multiplier > 0.0f ) { // use a different displayed distance scale
Expand Down
87 changes: 50 additions & 37 deletions code/jumpnode/jumpnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,46 @@
#include "model/model.h"
#include "model/modelrender.h"

SCP_list<CJumpNode> Jump_nodes;
SCP_vector<CJumpNode> Jump_nodes;

/**
* Constructor for CJumpNode class, default
*/
CJumpNode::CJumpNode()
{
{
gr_init_alphacolor(&m_display_color, 0, 255, 0, 255);

m_name[0] = '\0';
m_display[0] = '\0';

m_pos.xyz.x = 0.0f;
m_pos.xyz.y = 0.0f;
m_pos.xyz.z = 0.0f;
}

/**
* Constructor for CJumpNode class, with world position argument
*/
CJumpNode::CJumpNode(const vec3d* position)
{
Assert(position != NULL);

{
Assertion(position != nullptr, "Position should not be null!");
if (position == nullptr)
position = &vmd_zero_vector;

gr_init_alphacolor(&m_display_color, 0, 255, 0, 255);

// Set m_name and m_display
sprintf(m_name, XSTR( "Jump Node %d", 632), Jump_nodes.size());
m_display[0] = '\0';

// Set m_modelnum and m_radius
m_modelnum = model_load(NOX(JN_DEFAULT_MODEL), nullptr, ErrorType::WARNING);
if (m_modelnum == -1) {
Warning(LOCATION, "Could not load default model for %s", m_name);
} else {
m_radius = model_get_radius(m_modelnum);
}

m_pos.xyz.x = position->xyz.x;
m_pos.xyz.y = position->xyz.y;
m_pos.xyz.z = position->xyz.z;


// Create the object
flagset<Object::Object_Flags> default_flags;
default_flags.set(Object::Object_Flags::Renders);
m_objnum = obj_create(OBJ_JUMP_NODE, -1, -1, NULL, &m_pos, m_radius, default_flags);
flagset<Object::Object_Flags> default_flags;
default_flags.set(Object::Object_Flags::Renders);
m_objnum = obj_create(OBJ_JUMP_NODE, -1, -1, nullptr, position, m_radius, default_flags);

if (m_modelnum >= 0) {
// set up animation in case of instrinsic_rotate
Expand All @@ -81,7 +75,6 @@ CJumpNode::CJumpNode(CJumpNode&& other) noexcept
other.m_fred_layer = "Default";

m_display_color = other.m_display_color;
m_pos = other.m_pos;

strcpy_s(m_name, other.m_name);
strcpy_s(m_display, other.m_display);
Expand All @@ -106,7 +99,6 @@ CJumpNode& CJumpNode::operator=(CJumpNode&& other) noexcept
other.m_fred_layer = "Default";

m_display_color = other.m_display_color;
m_pos = other.m_pos;

strcpy_s(m_name, other.m_name);
strcpy_s(m_display, other.m_display);
Expand Down Expand Up @@ -160,6 +152,14 @@ int CJumpNode::GetModelNumber() const
return m_modelnum;
}

/**
* @return Radius of jump node model
*/
float CJumpNode::GetRadius() const
{
return m_radius;
}

/**
* @return Index into Objects[]
*/
Expand Down Expand Up @@ -190,7 +190,8 @@ const color &CJumpNode::GetColor() const
*/
const vec3d *CJumpNode::GetPosition() const
{
return &m_pos;
Assert(m_objnum != -1);
return &Objects[m_objnum].pos;
}

/*
Expand Down Expand Up @@ -474,16 +475,32 @@ void CJumpNode::Render(model_draw_list *scene, const vec3d *pos, const vec3d *vi
CJumpNode *jumpnode_get_by_name(const char* name)
{
Assert(name != NULL);
SCP_list<CJumpNode>::iterator jnp;

for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
if(!stricmp(jnp->GetName(), name))
return &(*jnp);
for (auto &jnp : Jump_nodes) {
if(!stricmp(jnp.GetName(), name))
return &jnp;
}

return NULL;
}

/**
* Get jump node index by given name
*
* @param name Name of jump node
* @return Jump node index
*/
int jumpnode_lookup(const char *name)
{
Assert(name != nullptr);

for (size_t i = 0; i < Jump_nodes.size(); i++)
if (!stricmp(Jump_nodes[i].GetName(), name))
return sz2i(i);

return -1;
}

/**
* Get jump node object by the object number
*
Expand Down Expand Up @@ -529,17 +546,15 @@ CJumpNode *jumpnode_get_by_objp(const object *objp)
CJumpNode *jumpnode_get_which_in(const object *objp)
{
Assert(objp != NULL);
SCP_list<CJumpNode>::iterator jnp;
float radius, dist;

for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
if(jnp->GetModelNumber() < 0)
for (auto &jnp : Jump_nodes) {
if(jnp.GetModelNumber() < 0)
continue;

radius = model_get_radius( jnp->GetModelNumber() );
dist = vm_vec_dist( &objp->pos, &jnp->GetSCPObject()->pos );
float radius = jnp.GetRadius();
float dist = vm_vec_dist( &objp->pos, &jnp.GetSCPObject()->pos );
if ( dist <= radius ) {
return &(*jnp);
return &jnp;
}
}

Expand All @@ -553,10 +568,8 @@ CJumpNode *jumpnode_get_which_in(const object *objp)
*/
void jumpnode_render_all()
{
SCP_list<CJumpNode>::iterator jnp;

for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
jnp->Render(&jnp->GetSCPObject()->pos);
for (auto &jnp : Jump_nodes) {
jnp.Render(&jnp.GetSCPObject()->pos);
}
}

Expand Down
5 changes: 3 additions & 2 deletions code/jumpnode/jumpnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class CJumpNode

int m_flags {0};
color m_display_color; // Color node will be shown in (Default:0/255/0/255)
vec3d m_pos;
SCP_string m_fred_layer = "Default"; // FRED view layer assignment

CJumpNode(const CJumpNode&);
Expand All @@ -65,6 +64,7 @@ class CJumpNode
const char *GetName() const;
const char *GetDisplayName() const;
int GetModelNumber() const;
float GetRadius() const;
int GetSCPObjectNumber() const;
int GetPolymodelInstanceNum() const;
const object *GetSCPObject() const;
Expand Down Expand Up @@ -94,10 +94,11 @@ class CJumpNode
};

//-----Globals------
extern SCP_list<CJumpNode> Jump_nodes;
extern SCP_vector<CJumpNode> Jump_nodes;

//-----Functions-----
CJumpNode *jumpnode_get_by_name(const char *name);
int jumpnode_lookup(const char *name);
CJumpNode *jumpnode_get_by_objnum(int objnum);
CJumpNode *jumpnode_get_by_objp(const object *objp);
CJumpNode *jumpnode_get_which_in(const object *objp);
Expand Down
29 changes: 14 additions & 15 deletions code/missioneditor/missionsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4791,74 +4791,73 @@ int Fred_mission_save::save_waypoints()
parse_comments(2);
fout("\t\t;! %d lists total\n", Waypoint_lists.size());

SCP_list<CJumpNode>::iterator jnp;
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
for (auto &jn : Jump_nodes) {
required_string_fred("$Jump Node:", "$Jump Node Name:");
parse_comments(2);
save_vector(jnp->GetSCPObject()->pos);
save_vector(jn.GetSCPObject()->pos);

required_string_fred("$Jump Node Name:", "$Jump Node:");
parse_comments();
fout(" %s", jnp->GetName());
fout(" %s", jn.GetName());

if (save_config.save_format != MissionFormat::RETAIL) {

// The display name is only written if there was one at the start to avoid introducing inconsistencies
if (save_config.always_save_display_names || jnp->HasDisplayName()) {
if (save_config.always_save_display_names || jn.HasDisplayName()) {
char truncated_name[NAME_LENGTH];
strcpy_s(truncated_name, jnp->GetName());
strcpy_s(truncated_name, jn.GetName());
end_string_at_first_hash_symbol(truncated_name);

// Also, the display name is not written if it's just the truncation of the name at the hash
if (save_config.always_save_display_names || strcmp(jnp->GetDisplayName(), truncated_name) != 0) {
if (save_config.always_save_display_names || strcmp(jn.GetDisplayName(), truncated_name) != 0) {
if (optional_string_fred("+Display Name:", "$Jump Node:")) {
parse_comments();
} else {
fout("\n+Display Name:");
}

fout_ext("", "%s", jnp->GetDisplayName());
fout_ext("", "%s", jn.GetDisplayName());
}
}

if (jnp->IsSpecialModel()) {
if (jn.IsSpecialModel()) {
if (optional_string_fred("+Model File:", "$Jump Node:")) {
parse_comments();
} else {
fout("\n+Model File:");
}

int model = jnp->GetModelNumber();
int model = jn.GetModelNumber();
polymodel* pm = model_get(model);
fout(" %s", pm->filename);
}

if (jnp->IsColored()) {
if (jn.IsColored()) {
if (optional_string_fred("+Alphacolor:", "$Jump Node:")) {
parse_comments();
} else {
fout("\n+Alphacolor:");
}

const auto& jn_color = jnp->GetColor();
const auto& jn_color = jn.GetColor();
fout(" %u %u %u %u", jn_color.red, jn_color.green, jn_color.blue, jn_color.alpha);
}

int hidden_is_there = optional_string_fred("+Hidden:", "$Jump Node:");
if (hidden_is_there)
parse_comments();

if (hidden_is_there || jnp->IsHidden()) {
if (hidden_is_there || jn.IsHidden()) {
if (!hidden_is_there)
fout("\n+Hidden:");

if (jnp->IsHidden())
if (jn.IsHidden())
fout(" %s", "true");
else
fout(" %s", "false");
}

const SCP_string& jn_layer = jnp->GetFredLayer();
const SCP_string& jn_layer = jn.GetFredLayer();
if (!jn_layer.empty() && !lcase_equal(jn_layer, "Default")) {
if (optional_string_fred("+Layer:", "$Jump Node:"))
parse_comments();
Expand Down
6 changes: 3 additions & 3 deletions code/object/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1941,12 +1941,12 @@ void obj_queue_render(object* obj, model_draw_list* scene)
asteroid_render(obj, scene);
break;
case OBJ_JUMP_NODE:
for ( SCP_list<CJumpNode>::iterator jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp ) {
if ( jnp->GetSCPObject() != obj ) {
for ( auto &jnp : Jump_nodes ) {
if ( jnp.GetSCPObject() != obj ) {
continue;
}

jnp->Render(scene, &obj->pos, &Eye_position);
jnp.Render(scene, &obj->pos, &Eye_position);
}
break;
case OBJ_WAYPOINT:
Expand Down
5 changes: 2 additions & 3 deletions fred2/dumpstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,8 @@ void DumpStats::get_object_stats(CString &buffer)
// Jumpnodes
buffer += "\r\nJUMPNODES\r\n";

SCP_list<CJumpNode>::iterator jnp;
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
temp.Format("\tJumpnode: %s\r\n", jnp->GetName());
for (auto &jnp : Jump_nodes) {
temp.Format("\tJumpnode: %s\r\n", jnp.GetName());
buffer += temp;
}

Expand Down
10 changes: 4 additions & 6 deletions fred2/jumpnodedlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,18 @@ BOOL jumpnode_dlg::Create()
void jumpnode_dlg::OnInitMenu(CMenu* pMenu)
{
int i;
SCP_list<CJumpNode>::iterator jnp;
CMenu *m;

m = pMenu->GetSubMenu(0);
clear_menu(m);

i = 0;
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
m->AppendMenu(MF_ENABLED | MF_STRING, ID_JUMP_NODE_MENU + i, jnp->GetName());
if (jnp->GetSCPObjectNumber() == cur_object_index) {
i = 0;
for (auto &jnp : Jump_nodes) {
m->AppendMenu(MF_ENABLED | MF_STRING, ID_JUMP_NODE_MENU + i, jnp.GetName());
if (jnp.GetSCPObjectNumber() == cur_object_index) {
m->CheckMenuItem(ID_JUMP_NODE_MENU + i, MF_BYCOMMAND | MF_CHECKED);
}
i++;

}

m->DeleteMenu(ID_PLACEHOLDER, MF_BYCOMMAND);
Expand Down
Loading
Loading