--'****************************************************** --'* Реестр персонажей. --'****************************************************** --' Таблица содержащая объекты и данные о них в формате: --' npc = { smart_id, squad_id, flags} local objects = {} --' Таблица содержащая объекты сгрупированные по squad_id: local squad_objects = {} --' Значения флагов: --' alive - живой персонаж или мертвый --' marked - помечен ли он мапспотом. --' Регистрация нового персонажа. function register_object(obj) if objects[obj.id] ~= nil then abort("Object already exist in list [%s]", obj:name()) end objects[obj.id] = {smart_id = -1, squad_id = nil, flags = {}} objects[obj.id].flags.alive = obj:alive() set_obj_squad(obj, -1) show_object_spot(obj) --' ВРЕМЕННО. Здесь будем выбирать смарттеррейн. local obj_ini = obj:spawn_ini() local smart = utils.cfg_get_string(obj_ini, "logic", "smart_terrain", obj, false, "", "") printf("SMART = %s", smart) local smart_obj = sim_board.get_sim_board():get_smart_by_name(smart) if smart_obj == nil then return end printf("SMART_ID = %s ", smart_obj.id) alife():object(smart_obj.id):register_npc(obj) --obj.m_smart_terrain_id = tonumber(smart_id) end --' АнРегистрация персонажа. function unregister_object(obj) if objects[obj.id] == nil then abort("Trying to unregister nil object [%s]", obj:name()) end hide_object_spot(obj) objects[obj.id] = nil end --' Отметить объект как померший. function object_die(obj) objects[obj.id].flags.alive = false hide_object_spot(obj) --' Убрать объект из отряда. local squad_id = objects[obj.id].squad_id squad_objects[squad_id][obj.id] = nil objects[obj.id].squad_id = nil printf("Object %s died:", obj:name()) print_table(objects[obj.id]) end --' Показать объект на карте function show_object_spot(obj) if objects[obj.id].flags.marked then return end if not objects[obj.id].flags.alive then return end objects[obj.id].flags.marked = true local community = getObjComunity(obj) if(_G.dev_debug) then level.map_add_object_spot(obj.id, "alife_presentation_"..community, obj:name()) end end --' Убрать объект с карты function hide_object_spot(obj) if not objects[obj.id].flags.marked then return end objects[obj.id].flags.marked = false local community = getObjComunity(obj) if(_G.dev_debug) then level.map_remove_object_spot(obj.id, "alife_presentation_"..community) end end --' Получить группировку объекта function getObjComunity(obj) if obj:clsid() == clsid.script_stalker then return obj:community() else return "monster" end end --' Обнуление списка на создании игры. function clear() objects = {} squad_objects = {} end --' Тестовые функции function print() printf("Object list:") print_table(objects) printf("Squad list:") print_table(squad_objects) end