static int Lua_Monster_Set_Visible(lua_State *L) {
    int monster_index = Lua_Monster::Index(L, 1);
    monster_data *monster = get_monster_data(monster_index);
    object_data *object = get_object_data(monster->object_index);
    int invisible = !lua_toboolean(L, 2);
    if(monster->action == _monster_is_teleporting_out) return 0;
    if(MONSTER_IS_ACTIVE(monster) || monster->vitality >= 0) {
        // Cool stuff happens if you just set an active
        // monster to invisible.  What we should do instead of
        // the below is expose teleports_out_when_deactivated
        /*if(invisible) {
          monster->flags |= (uint16)_monster_teleports_out_when_deactivated;
          deactivate_monster(monster_index);
          }*/
        return luaL_error(L, "visible: monster already activated");
    }
    else {
        // No real possibility of messing stuff up here.
        SET_OBJECT_INVISIBILITY(object, invisible);
    }
    return 0;
}
Example #2
0
short new_item(struct object_location *location,short type)
{
	short object_index;
	item_definition *definition= get_item_definition(type);
	// LP change: added idiot-proofing
	if (!definition) 
		return false;
	
	bool add_item = true;

	assert(sizeof(item_definitions)/sizeof(struct item_definition)==NUMBER_OF_DEFINED_ITEMS);

	/* Do NOT add items that are network-only in a single player game, and vice-versa */
	if (dynamic_world->player_count>1)
	{
		if (definition->invalid_environments & _environment_network) 
			add_item = false;
		if (get_item_kind(type)==_ball && !current_game_has_balls()) 
			add_item = false;
	} 
	else
	{
		if (definition->invalid_environments & _environment_single_player) add_item= false;
	}

	if (add_item)
	{
		/* add the object to the map */
		object_index= new_map_object(location, definition->base_shape);
		if (object_index!=NONE)
		{
			object_data *object= get_object_data(object_index);
			
			// LP addition: using the facing direction as a flag in the "unanimated" case:
			// will be initially zero, but will become nonzero when initialized,
			// so that the shape randomization will be done only once.
			
			SET_OBJECT_OWNER(object, _object_is_item);
			object->permutation= type;
			
			if ((location->flags&_map_object_is_network_only) && dynamic_world->player_count<=1)
			{

				SET_OBJECT_INVISIBILITY(object, true);
				object->permutation= NONE;
			}
			else if ((get_item_kind(type) == _ball) && !static_world->ball_in_play)
			{
				static_world->ball_in_play = true;
				SoundManager::instance()->PlayLocalSound(_snd_got_ball);
			}
			
			/* let PLACEMENT.C keep track of how many there are */
			object_was_just_added(_object_is_item, type);
			// and let Lua know too
			L_Call_Item_Created(object_index);
 		}
	}
	else
		object_index = NONE;
	
	return object_index;
}