void CLevel::g_cl_Spawn (LPCSTR name, u8 rp, u16 flags, Fvector pos) { // Create CSE_Abstract* E = F_entity_Create(name); VERIFY (E); // Fill E->s_name = name; E->set_name_replace (""); //. E->s_gameid = u8(GameID()); E->s_RP = rp; E->ID = 0xffff; E->ID_Parent = 0xffff; E->ID_Phantom = 0xffff; E->s_flags.assign (flags); E->RespawnTime = 0; E->o_Position = pos; // Send NET_Packet P; E->Spawn_Write (P,TRUE); Send (P,net_flags(TRUE)); // Destroy F_entity_Destroy (E); }
/////////spawn object representing destroyed item////////////////////////////////////////////////////////////////////////////////// void CPHDestroyable::GenSpawnReplace(u16 ref_id,LPCSTR section,shared_str visual_name) { CSE_Abstract *D = F_entity_Create(section);//*cNameSect() VERIFY (D); CSE_Visual *V =smart_cast<CSE_Visual*>(D); V->set_visual (*visual_name); CSE_PHSkeleton *l_tpPHSkeleton = smart_cast<CSE_PHSkeleton*>(D); VERIFY (l_tpPHSkeleton); l_tpPHSkeleton->source_id = ref_id; //init // Send D->s_name = section;//*cNameSect() D->ID_Parent = u16(-1); InitServerObject (D); if (OnServer()) { NET_Packet P; D->Spawn_Write (P,TRUE); Level().Send (P,net_flags(TRUE)); // Destroy F_entity_Destroy (D); m_depended_objects++; }; };
void CWeapon::SpawnAmmo(u32 boxCurr, LPCSTR ammoSect, u32 ParentID) { if(!m_ammoTypes.size()) return; if (OnClient()) return; m_bAmmoWasSpawned = true; int l_type = 0; l_type %= m_ammoTypes.size(); if(!ammoSect) ammoSect = m_ammoTypes[l_type].c_str(); ++l_type; l_type %= m_ammoTypes.size(); CSE_Abstract *D = F_entity_Create(ammoSect); { CSE_ALifeItemAmmo *l_pA = smart_cast<CSE_ALifeItemAmmo*>(D); R_ASSERT (l_pA); l_pA->m_boxSize = (u16)pSettings->r_s32(ammoSect, "box_size"); D->s_name = ammoSect; D->set_name_replace (""); //. D->s_gameid = u8(GameID()); D->s_RP = 0xff; D->ID = 0xffff; if (ParentID == 0xffffffff) D->ID_Parent = (u16)H_Parent()->ID(); else D->ID_Parent = (u16)ParentID; D->ID_Phantom = 0xffff; D->s_flags.assign (M_SPAWN_OBJECT_LOCAL); D->RespawnTime = 0; l_pA->m_tNodeID = g_dedicated_server ? u32(-1) : ai_location().level_vertex_id(); if(boxCurr == 0xffffffff) boxCurr = l_pA->m_boxSize; while(boxCurr) { l_pA->a_elapsed = (u16)(boxCurr > l_pA->m_boxSize ? l_pA->m_boxSize : boxCurr); NET_Packet P; D->Spawn_Write (P, TRUE); Level().Send (P,net_flags(TRUE)); if(boxCurr > l_pA->m_boxSize) boxCurr -= l_pA->m_boxSize; else boxCurr = 0; } } F_entity_Destroy (D); }
CSE_Abstract* game_sv_GameState::spawn_begin (LPCSTR N) { CSE_Abstract* A = F_entity_Create(N); R_ASSERT(A); // create SE A->s_name = N; // ltx-def //. A->s_gameid = u8(m_type); // game-type A->s_RP = 0xFE; // use supplied A->ID = 0xffff; // server must generate ID A->ID_Parent = 0xffff; // no-parent A->ID_Phantom = 0xffff; // no-phantom A->RespawnTime = 0; // no-respawn return A; }
u16 GetSpawnInfo(NET_Packet &P, u16 &parent_id) { u16 dummy16, id; P.r_begin(dummy16); shared_str s_name; P.r_stringZ(s_name); CSE_Abstract* E = F_entity_Create(*s_name); E->Spawn_Read(P); if (E->s_flags.is(M_SPAWN_UPDATE)) E->UPDATE_Read(P); id = E->ID; parent_id = E->ID_Parent; F_entity_Destroy(E); P.r_pos = 0; return id; }
//процесс отсоединения вещи заключается в спауне новой вещи //в инвентаре и установке соответствующих флагов в родительском //объекте, поэтому функция должна быть переопределена bool CInventoryItem::Detach(const char* item_section_name, bool b_spawn_item) { if (OnClient()) return true; if(b_spawn_item) { CSE_Abstract* D = F_entity_Create(item_section_name); R_ASSERT (D); CSE_ALifeDynamicObject *l_tpALifeDynamicObject = smart_cast<CSE_ALifeDynamicObject*>(D); R_ASSERT (l_tpALifeDynamicObject); l_tpALifeDynamicObject->m_tNodeID = object().ai_location().level_vertex_id(); // Fill D->s_name = item_section_name; D->set_name_replace (""); D->s_gameid = u8(GameID()); D->s_RP = 0xff; D->ID = 0xffff; if (GameID() == GAME_SINGLE) { D->ID_Parent = u16(object().H_Parent()->ID()); } else // i'm not sure this is right { // but it is simpliest way to avoid exception in MP BuyWnd... [Satan] if (object().H_Parent()) D->ID_Parent = u16(object().H_Parent()->ID()); else D->ID_Parent = NULL; } D->ID_Phantom = 0xffff; D->o_Position = object().Position(); D->s_flags.assign (M_SPAWN_OBJECT_LOCAL); D->RespawnTime = 0; // Send NET_Packet P; D->Spawn_Write (P,TRUE); Level().Send (P,net_flags(TRUE)); // Destroy F_entity_Destroy (D); } return true; }
void CPHSkeleton::SpawnCopy() { if(PPhysicsShellHolder()->Local()) { CSE_Abstract* D = F_entity_Create("ph_skeleton_object");//*cNameSect() R_ASSERT (D); ///////////////////////////////////////////////////////////////////////////////////////////// CSE_ALifePHSkeletonObject *l_tpALifePhysicObject = smart_cast<CSE_ALifePHSkeletonObject*>(D); R_ASSERT (l_tpALifePhysicObject); l_tpALifePhysicObject->_flags.set (CSE_PHSkeleton::flSpawnCopy,1); //SetNotNeedSave() ///////////////////////////////////////////////////////////////////////////////////////////// InitServerObject (D); // Send NET_Packet P; D->Spawn_Write (P,TRUE); Level().Send (P,net_flags(TRUE)); // Destroy F_entity_Destroy (D); } }
CSE_Abstract *CLevelSpawnConstructor::create_object (IReader *chunk) { NET_Packet net_packet; net_packet.B.count = chunk->length(); chunk->r (net_packet.B.data,net_packet.B.count); // we do not need to close chunk since we iterate on them // chunk->close (); u16 ID; net_packet.r_begin (ID); R_ASSERT2 (M_SPAWN==ID,"ID doesn't match to the spawn-point ID!"); string64 section_name; net_packet.r_stringZ (section_name); CSE_Abstract *abstract = F_entity_Create(section_name); if (!abstract) { string256 temp; sprintf (temp,"Can't create entity '%s' !\n",section_name); R_ASSERT2 (abstract,temp); } abstract->Spawn_Read (net_packet); return (abstract); }
CSE_Abstract *CLevel::spawn_item (LPCSTR section, const Fvector &position, u32 level_vertex_id, u16 parent_id, bool return_item) { CSE_Abstract *abstract = F_entity_Create(section); R_ASSERT3 (abstract,"Cannot find item with section",section); CSE_ALifeDynamicObject *dynamic_object = smart_cast<CSE_ALifeDynamicObject*>(abstract); if (dynamic_object && ai().get_level_graph()) { dynamic_object->m_tNodeID = level_vertex_id; if (ai().level_graph().valid_vertex_id(level_vertex_id) && ai().get_game_graph() && ai().get_cross_table()) dynamic_object->m_tGraphID = ai().cross_table().vertex(level_vertex_id).game_vertex_id(); } //оружие спавним с полным магазинои CSE_ALifeItemWeapon* weapon = smart_cast<CSE_ALifeItemWeapon*>(abstract); if(weapon) weapon->a_elapsed = weapon->get_ammo_magsize(); // Fill abstract->s_name = section; abstract->set_name_replace (section); //. abstract->s_gameid = u8(GameID()); abstract->o_Position = position; abstract->s_RP = 0xff; abstract->ID = 0xffff; abstract->ID_Parent = parent_id; abstract->ID_Phantom = 0xffff; abstract->s_flags.assign(M_SPAWN_OBJECT_LOCAL); abstract->RespawnTime = 0; if (!return_item) { NET_Packet P; abstract->Spawn_Write (P,TRUE); Send (P,net_flags(TRUE)); F_entity_Destroy (abstract); return (0); } else return (abstract); }
void CLevel::cl_Process_Spawn(NET_Packet& P) { // Begin analysis shared_str s_name; P.r_stringZ (s_name); // Create DC (xrSE) CSE_Abstract* E = F_entity_Create (*s_name); R_ASSERT2(E, *s_name); E->Spawn_Read (P); if (E->s_flags.is(M_SPAWN_UPDATE)) E->UPDATE_Read (P); if (!E->match_configuration()) { F_entity_Destroy(E); return; } //------------------------------------------------- //. Msg ("M_SPAWN - %s[%d][%x] - %d %d", *s_name, E->ID, E,E->ID_Parent, Device.dwFrame); //------------------------------------------------- //force object to be local for server client if (OnServer()) { E->s_flags.set(M_SPAWN_OBJECT_LOCAL, TRUE); }; /* game_spawn_queue.push_back(E); if (g_bDebugEvents) ProcessGameSpawns(); /*/ g_sv_Spawn (E); F_entity_Destroy (E); //*/ };
FACTORY_API ISE_Abstract* __stdcall create_entity (LPCSTR section) { return (F_entity_Create(section)); }
void CGameGraphBuilder::load_graph_point (NET_Packet &net_packet) { string256 section_id; u16 id; net_packet.r_begin (id); R_ASSERT (M_SPAWN == id); net_packet.r_stringZ (section_id); // if (xr_strcmp("graph_point",section_id)) // return; CSE_Abstract *entity = F_entity_Create(section_id); if (!entity) { Msg ("Cannot create entity from section %s, skipping",section_id); return; } CSE_ALifeGraphPoint *graph_point = smart_cast<CSE_ALifeGraphPoint*>(entity); if (!graph_point) { F_entity_Destroy (entity); return; } entity->Spawn_Read (net_packet); vertex_type vertex; vertex.tLocalPoint = graph_point->o_Position; // check for duplicate graph point positions { graph_type::const_vertex_iterator I = graph().vertices().begin(); graph_type::const_vertex_iterator E = graph().vertices().end(); for ( ; I != E; ++I) { if ((*I).second->data().tLocalPoint.distance_to_sqr(vertex.tLocalPoint) < EPS_L) { Msg ("! removing graph point [%s][%f][%f][%f] because it is too close to the another graph point",entity->name_replace(),VPUSH(entity->o_Position)); return; } } } vertex.tGlobalPoint = graph_point->o_Position; vertex.tNodeID = level_graph().valid_vertex_position(vertex.tLocalPoint) ? level_graph().vertex_id(vertex.tLocalPoint) : u32(-1); if (!level_graph().valid_vertex_id(vertex.tNodeID)) { Msg ("! removing graph point [%s][%f][%f][%f] because it is outside of the AI map",entity->name_replace(),VPUSH(entity->o_Position)); return; } { graph_type::const_vertex_iterator I = graph().vertices().begin(); graph_type::const_vertex_iterator E = graph().vertices().end(); for ( ; I != E; ++I) { if ((*I).second->data().tNodeID == vertex.tNodeID) { Msg ("! removing graph point [%s][%f][%f][%f] because it has the same AI node as another graph point",entity->name_replace(),VPUSH(entity->o_Position)); return; } } } vertex.tNeighbourCount = 0; Memory.mem_copy (vertex.tVertexTypes,graph_point->m_tLocations,GameGraph::LOCATION_TYPE_COUNT*sizeof(GameGraph::_LOCATION_ID)); vertex.tLevelID = 0; vertex.tDeathPointCount = 0; vertex.dwPointOffset = 0; graph().add_vertex (vertex,graph().vertices().size()); F_entity_Destroy (entity); }
//-------------------------------------------------------------------- CSE_Abstract* xrServer::entity_Create (LPCSTR name) { return F_entity_Create(name); }