/**
 * Constructor for CJumpNode class, with world position argument
 */
CJumpNode::CJumpNode(vec3d *position) : m_radius(0.0f), m_modelnum(-1), m_objnum(-1), m_flags(0)
{	
	Assert(position != NULL);
	
	gr_init_alphacolor(&m_display_color, 0, 255, 0, 255);
	
	// Set m_name
	sprintf(m_name, XSTR( "Jump Node %d", 632), Jump_nodes.size());
	
	// Set m_modelnum and m_radius
	m_modelnum = model_load(NOX("subspacenode.pof"), 0, NULL, 0);
	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
    m_objnum = obj_create(OBJ_JUMP_NODE, -1, -1, NULL, &m_pos, m_radius, OF_RENDERS);
}
Beispiel #2
0
void waypoint_remove(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);

	// special case... this is the only waypoint on its list
	if (wp_list->get_waypoints().size() == 1)
	{
		wp_list->get_waypoints().clear();

		// special special case... this is the only waypoint list!
		if (Waypoint_lists.size() == 1)
		{
			Waypoint_lists.clear();
		}
		// shift the other waypoint lists down
		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;
				}
			}
			Assert(ii != Waypoint_lists.end());

			// 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
			for (object *objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp))
			{
				if ((objp->type == OBJ_WAYPOINT) && (calc_waypoint_list_index(objp->instance) > this_list))
					objp->instance -= 0x10000;
			}
		}
	}
	// shift the other waypoints down
	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;
			}
		}
		Assert(ii != wp_list->get_waypoints().end());

		// iterate through all waypoints that are later than this one,
		// and edit their instances so that they point to a waypoint one place lower
		for (object *objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp))
		{
			if ((objp->type == OBJ_WAYPOINT) && (calc_waypoint_list_index(objp->instance) == this_list) && (calc_waypoint_index(objp->instance) > this_index))
				objp->instance--;
		}
	}

	// FRED has its own object removal logic
	if (!Fred_running)
		obj_delete(objnum);
}
Beispiel #3
0
int waypoint_add(vec3d *pos, int waypoint_instance)
{
	Assert(pos != NULL);
	waypoint_list *wp_list;
	waypoint *wpt;
	int i, wp_list_index, wp_index;

	// find a new list to start
	if (waypoint_instance < 0)
	{
		// get a name for it
		char buf[NAME_LENGTH];
		waypoint_find_unique_name(buf, Waypoint_lists.size() + 1);

		// add new list with that name
		waypoint_list new_list(buf);
		Waypoint_lists.push_back(new_list);
		wp_list = &Waypoint_lists.back();

		// set up references
		wp_list_index = Waypoint_lists.size() - 1;
		wp_index = wp_list->get_waypoints().size();
	}
	// create the waypoint on the same list as, and immediately after, waypoint_instance
	else
	{
		calc_waypoint_indexes(waypoint_instance, wp_list_index, wp_index);
		wp_list = find_waypoint_list_at_index(wp_list_index);

		// theoretically waypoint_instance points to a current waypoint, so advance past it
		wp_index++;

		// it has to be on, or at the end of, an existing list
		Assert(wp_list != NULL);
		Assert((uint) wp_index <= wp_list->get_waypoints().size());

		// iterate through all waypoints that are at this index or later,
		// and edit their instances so that they point to a waypoint one place higher
		for (object *objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp))
		{
			if ((objp->type == OBJ_WAYPOINT) && (calc_waypoint_list_index(objp->instance) == wp_list_index) && (calc_waypoint_index(objp->instance) >= wp_index))
				objp->instance++;
		}
	}

	// so that masking in the other function works
	// (though if you actually hit this Assert, you have other problems)
	Assert(wp_index < 0x10000);

	// create the waypoint object
	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);
	wpt = find_waypoint_at_index(wp_list, wp_index);

	// apparently we create it in-game too; this is called by both scripting and FRED
	waypoint_create_game_object(wpt, wp_list_index, wp_index);

	return wpt->get_objnum();
}