Exemplo n.º 1
0
Actor *ActorManager::get_multi_tile_actor(uint16 x, uint16 y, uint8 z)
{
	Actor *actor = get_actor(x+1,y+1,z,false); //search for 2x2 tile actor.
	if(actor)
	{
		Tile *tile = actor->get_tile();
		if(tile->dbl_width && tile->dbl_height)
			return actor;
	}

	actor = get_actor(x,y+1,z,false); //search for 1x2 tile actor.
	if(actor)
	{
		Tile *tile = actor->get_tile();
		if(tile->dbl_height)
			return actor;
	}

	actor = get_actor(x+1,y,z,false); //search for 1x2 tile actor.
	if(actor)
	{
		Tile *tile = actor->get_tile();
		if(tile->dbl_width)
			return actor;
	}


	return NULL;
}
Exemplo n.º 2
0
ActorSharedPtr MLNetwork::add_actor(const std::string& name)  {
	ActorSharedPtr check = get_actor(name);
	if (check) return NULL;
	actor_id aid = ++max_actor_id;
	ActorSharedPtr actor_ptr(new actor(aid,name));
	actors.insert(aid,actor_ptr);
	cidx_actor_by_name[name] = actor_ptr;
	return actor_ptr;
}
Exemplo n.º 3
0
bool ActorManager::can_put_actor(MapCoord location)
{
	if(!map->is_passable(location.x, location.y, location.z))
		return false;

	if(get_actor(location.x, location.y, location.z) != NULL)
		return false;

	return true;
}
Exemplo n.º 4
0
bool ActorManager::resurrect_actor(Obj *actor_obj, MapCoord new_position)
{
 Actor *actor;
 
 if(!is_temp_actor(actor_obj->quality))
  {
   actor = get_actor(actor_obj->quality);
   actor->resurrect(new_position, actor_obj);
  }

 return true;
}
Exemplo n.º 5
0
/* Find a location to put actor within range.
 * Returns true when tossed.
 */
bool ActorManager::toss_actor_get_location(uint16 start_x, uint16 start_y, uint8 start_z, uint16 xrange, uint16 yrange, MapCoord *location)
{
    // maximum number of tries
    const uint32 toss_max = MAX(xrange, yrange) * MIN(xrange, yrange) * 2;
    uint32 t = 0;
    LineTestResult lt;
    if(xrange > 0) --xrange; // range includes the starting location
    if(yrange > 0) --yrange;
    while(t++ < toss_max) // TRY RANDOM LOCATION
    {
        sint16 x = (start_x-xrange) + (NUVIE_RAND() % ((start_x+xrange) - (start_x-xrange) + 1)),
               y = (start_y-yrange) + (NUVIE_RAND() % ((start_y+yrange) - (start_y-yrange) + 1));
        if(!map->lineTest(start_x, start_y, x, y, start_z, LT_HitUnpassable, lt))
        {
        	if(!get_actor(x, y, start_z))
        	{
        		location->x = x;
        		location->y = y;
        		location->z = start_z;
        		return can_put_actor(*location);
        	}

        }
    }
    // TRY ANY LOCATION
    for(int y = start_y-yrange; y < start_y+yrange; y++)
        for(int x = start_x-xrange; x < start_x+xrange; x++)
            if(!map->lineTest(start_x, start_y, x, y, start_z, LT_HitUnpassable, lt))
            {
            	if(!get_actor(x, y, start_z))
            	{
            		location->x = x;
            		location->y = y;
            		location->z = start_z;
            		return can_put_actor(*location);
            	}
            }

    return(false);
}
Exemplo n.º 6
0
/* Move an actor to a random location within range.
 * Returns true when tossed.
 */
bool ActorManager::toss_actor(Actor *actor, uint16 xrange, uint16 yrange)
{
    // maximum number of tries
    const uint32 toss_max = MAX(xrange, yrange) * MIN(xrange, yrange) * 2;
    uint32 t = 0;
    LineTestResult lt;
    if(xrange > 0) --xrange; // range includes the starting location
    if(yrange > 0) --yrange;
    while(t++ < toss_max) // TRY RANDOM LOCATION
    {
        sint16 x = (actor->x-xrange) + (NUVIE_RAND() % ((actor->x+xrange) - (actor->x-xrange) + 1)),
               y = (actor->y-yrange) + (NUVIE_RAND() % ((actor->y+yrange) - (actor->y-yrange) + 1));
        if(!map->lineTest(actor->x, actor->y, x, y, actor->z, LT_HitUnpassable, lt))
            if(!get_actor(x, y, actor->z))
                return(actor->move(x, y, actor->z));
    }
    // TRY ANY LOCATION
    for(int y = actor->y-yrange; y < actor->y+yrange; y++)
        for(int x = actor->x-xrange; x < actor->x+xrange; x++)
            if(!map->lineTest(actor->x, actor->y, x, y, actor->z, LT_HitUnpassable, lt))
                if(!get_actor(x, y, actor->z))
                    return(actor->move(x, y, actor->z));
    return(false);
}
Exemplo n.º 7
0
Actor *ActorManager::get_avatar()
{
	return get_actor(ACTOR_AVATAR_ID_N);
}