//call this after CGameObject::net_Spawn BOOL CInventoryOwner::net_Spawn (CSE_Abstract* DC) { if (!m_pTrade) m_pTrade = xr_new<CTrade>(this); if (m_trade_parameters) xr_delete (m_trade_parameters); m_trade_parameters = xr_new<CTradeParameters>(trade_section()); //получить указатель на объект, InventoryOwner //m_inventory->setSlotsBlocked(false); CGameObject *pThis = smart_cast<CGameObject*>(this); if(!pThis) return FALSE; CSE_Abstract* E = (CSE_Abstract*)(DC); if ( IsGameTypeSingle() ) { CSE_ALifeTraderAbstract* pTrader = NULL; if(E) pTrader = smart_cast<CSE_ALifeTraderAbstract*>(E); if(!pTrader) return FALSE; R_ASSERT( pTrader->character_profile().size() ); //синхронизируем параметры персонажа с серверным объектом CharacterInfo().Init(pTrader); //------------------------------------- m_known_info_registry->registry().init(E->ID); //------------------------------------- CAI_PhraseDialogManager* dialog_manager = smart_cast<CAI_PhraseDialogManager*>(this); if( dialog_manager && !dialog_manager->GetStartDialog().size() ) { dialog_manager->SetStartDialog(CharacterInfo().StartDialog()); dialog_manager->SetDefaultStartDialog(CharacterInfo().StartDialog()); } m_game_name = pTrader->m_character_name; } else { CharacterInfo().m_SpecificCharacter.Load ("mp_actor"); CharacterInfo().InitSpecificCharacter ("mp_actor"); CharacterInfo().m_SpecificCharacter.data()->m_sGameName = (E->name_replace()[0]) ? E->name_replace() : *pThis->cName(); m_game_name = (E->name_replace()[0]) ? E->name_replace() : *pThis->cName(); } if(!pThis->Local()) return TRUE; return TRUE; }
void CALifeGraphRegistry::detach (CSE_Abstract &object, CSE_ALifeInventoryItem *item, GameGraph::_GRAPH_ID game_vertex_id, bool alife_query, bool remove_children) { #ifdef DEBUG if (psAI_Flags.test(aiALife)) { Msg ("[LSS] Detaching item [%s][%d] from [%s][%d]",item->base()->name_replace(),item->base()->ID,object.name_replace(),object.ID); } #endif if (alife_query) add (smart_cast<CSE_ALifeDynamicObject*>(item),game_vertex_id); else { CSE_ALifeDynamicObject *object = smart_cast<CSE_ALifeDynamicObject*>(item); VERIFY (object); object->m_tGraphID = game_vertex_id; level().add (object); } CSE_ALifeDynamicObject *dynamic_object = smart_cast<CSE_ALifeDynamicObject*>(&object); R_ASSERT2 (!alife_query || dynamic_object,"Cannot detach an item from non-alife object"); VERIFY (alife_query || !smart_cast<CSE_ALifeDynamicObject*>(&object) || (ai().game_graph().vertex(smart_cast<CSE_ALifeDynamicObject*>(&object)->m_tGraphID)->level_id() == level().level_id())); if (dynamic_object) dynamic_object->detach (item,0,alife_query,remove_children); else { #ifdef DEBUG bool value = std::find(object.children.begin(),object.children.end(),item->base()->ID) != object.children.end(); if (!value) { Msg ("! ERROR: can't detach independant object. entity[%s:%d], parent[%s:%d], section[%s]", item->base()->name_replace(),item->base()->ID,object.name_replace(),object.ID, *item->base()->s_name); } #endif // DEBUG // R_ASSERT2 (value,"Can't detach an item which is not on my own"); } }
void xrServer::Process_save(NET_Packet& P, ClientID sender) { xrClientData* CL = ID_to_client(sender); if (CL) CL->net_Ready = TRUE; R_ASSERT(CL->flags.bLocal); // while has information while (!P.r_eof()) { // find entity u16 ID; u16 size; P.r_u16 (ID); P.r_u16 (size); s32 _pos_start = P.r_tell (); CSE_Abstract *E = ID_to_entity(ID); if (E) { E->net_Ready = TRUE; E->load (P); } else P.r_advance (size); s32 _pos_end = P.r_tell (); s32 _size = size; if (_size != (_pos_end-_pos_start)) { Msg ("! load/save mismatch, object: '%s'",E?E->name_replace():"unknown"); s32 _rollback = _pos_start+_size; P.r_seek (_rollback); } } }
void CALifeGraphRegistry::attach (CSE_Abstract &object, CSE_ALifeInventoryItem *item, GameGraph::_GRAPH_ID game_vertex_id, bool alife_query, bool add_children) { #ifdef DEBUG if (psAI_Flags.test(aiALife)) { Msg ("[LSS] Attaching item [%s][%d] to [%s][%d]",item->base()->name_replace(),item->base()->ID,object.name_replace(),object.ID); } #endif if (alife_query) remove (smart_cast<CSE_ALifeDynamicObject*>(item),game_vertex_id); else level().remove (smart_cast<CSE_ALifeDynamicObject*>(item)); CSE_ALifeDynamicObject *dynamic_object = smart_cast<CSE_ALifeDynamicObject*>(&object); R_ASSERT2 (!alife_query || dynamic_object,"Cannot attach an item to a non-alife object object"); dynamic_object->attach (item,alife_query,add_children); }
CLevelGameGraph ( LPCSTR graph_file_name, LPCSTR raw_cross_table_file_name, CGameGraph::SLevel *tLevel, LPCSTR S, u32 dwOffset, u32 dwLevelID, CInifile *Ini ) { m_tLevel = *tLevel; m_dwOffset = dwOffset; m_tpLevelPoints.clear (); FILE_NAME caFileName; // loading graph strcpy_s (caFileName,graph_file_name); m_tpGraph = new CGameGraph(caFileName); strcpy_s (caFileName,raw_cross_table_file_name); CGameLevelCrossTable *l_tpCrossTable = new CGameLevelCrossTable(caFileName); CLevelGraph *l_tpAI_Map = new CLevelGraph(S); VERIFY2 (l_tpCrossTable->header().level_guid() == l_tpAI_Map->header().guid(), "cross table doesn't correspond to the AI-map, rebuild graph!"); VERIFY2 (l_tpCrossTable->header().game_guid() == m_tpGraph->header().guid(), "cross table doesn't correspond to the graph, rebuild graph!"); VERIFY2 (m_tpGraph->header().level(GameGraph::_LEVEL_ID(0)).guid() == l_tpAI_Map->header().guid(), "cross table doesn't correspond to the AI-map, rebuild graph!"); VERIFY (l_tpAI_Map->header().vertex_count() == l_tpCrossTable->header().level_vertex_count()); VERIFY (m_tpGraph->header().vertex_count() == l_tpCrossTable->header().game_vertex_count()); tLevel->m_guid = l_tpAI_Map->header().guid(); { for (GameGraph::_GRAPH_ID i=0, n = m_tpGraph->header().vertex_count(); i<n; ++i) if ((!l_tpAI_Map->valid_vertex_id(m_tpGraph->vertex(i)->level_vertex_id()) || (l_tpCrossTable->vertex(m_tpGraph->vertex(i)->level_vertex_id()).game_vertex_id() != i) || !l_tpAI_Map->inside(m_tpGraph->vertex(i)->level_vertex_id(),m_tpGraph->vertex(i)->level_point()))) { Msg ("! Graph doesn't correspond to the cross table"); R_ASSERT2 (false,"Graph doesn't correspond to the cross table"); } } m_tpVertices.resize (m_tpGraph->header().vertex_count()); GRAPH_VERTEX_IT B = m_tpVertices.begin(); GRAPH_VERTEX_IT I = B; GRAPH_VERTEX_IT E = m_tpVertices.end(); for ( ; I != E; I++) { (*I).tLocalPoint = m_tpGraph->vertex(int(I - B))->level_point(); (*I).tGlobalPoint.add (m_tpGraph->vertex(int(I - B))->game_point(),m_tLevel.offset()); (*I).tLevelID = dwLevelID; (*I).tNodeID = m_tpGraph->vertex(int(I - B))->level_vertex_id(); Memory.mem_copy ((*I).tVertexTypes,m_tpGraph->vertex(int(I - B))->vertex_type(),GameGraph::LOCATION_TYPE_COUNT*sizeof(GameGraph::_LOCATION_ID)); (*I).tNeighbourCount = m_tpGraph->vertex(int(I - B))->edge_count(); CGameGraph::const_iterator b,i,e; m_tpGraph->begin (int(I - B),i,e); (*I).tpaEdges = (CGameGraph::CEdge*)xr_malloc((*I).tNeighbourCount*sizeof(CGameGraph::CEdge)); b = i; for ( ; i != e; ++i) { GameGraph::CEdge &edge = (*I).tpaEdges[i - b]; edge = *i; VERIFY ((edge.vertex_id() + dwOffset) < (u32(1) << (8*sizeof(GameGraph::_GRAPH_ID)))); edge.m_vertex_id = (GameGraph::_GRAPH_ID)(edge.m_vertex_id + dwOffset); } (*I).dwPointOffset = 0; vfGenerateDeathPoints (int(I - B),l_tpCrossTable,l_tpAI_Map,(*I).tDeathPointCount); } xr_delete (l_tpCrossTable); xr_delete (l_tpAI_Map); // updating cross-table { strcpy_s (caFileName,raw_cross_table_file_name); CGameLevelCrossTable *tpCrossTable = new CGameLevelCrossTable(caFileName); xr_vector<CGameLevelCrossTable::CCell> tCrossTableUpdate; tCrossTableUpdate.resize(tpCrossTable->header().level_vertex_count()); for (int i=0; i<(int)tpCrossTable->header().level_vertex_count(); i++) { tCrossTableUpdate[i] = tpCrossTable->vertex(i); VERIFY (u32(tCrossTableUpdate[i].tGraphIndex) < tpCrossTable->header().game_vertex_count()); tCrossTableUpdate[i].tGraphIndex = tCrossTableUpdate[i].tGraphIndex + (GameGraph::_GRAPH_ID)dwOffset; } CGameLevelCrossTable::CHeader tCrossTableHeader; tCrossTableHeader.dwVersion = XRAI_CURRENT_VERSION; tCrossTableHeader.dwNodeCount = tpCrossTable->m_tCrossTableHeader.dwNodeCount; tCrossTableHeader.dwGraphPointCount = tpCrossTable->m_tCrossTableHeader.dwGraphPointCount; tCrossTableHeader.m_level_guid = tpCrossTable->m_tCrossTableHeader.m_level_guid; tCrossTableHeader.m_game_guid = tGraphHeader.m_guid; xr_delete (tpCrossTable); m_cross_table.w(&tCrossTableHeader,sizeof(tCrossTableHeader)); for (int i=0; i<(int)tCrossTableHeader.dwNodeCount; i++) m_cross_table.w(&(tCrossTableUpdate[i]),sizeof(tCrossTableUpdate[i])); } // fill vertex map { string_path fName; strconcat (sizeof(fName),fName,S,"level.spawn"); IReader *F = FS.r_open(fName); u32 id; IReader *O = F->open_chunk_iterator(id); for (int i=0; O; O = F->open_chunk_iterator(id,O)) { NET_Packet P; P.B.count = O->length(); O->r (P.B.data,P.B.count); u16 ID; P.r_begin (ID); R_ASSERT (M_SPAWN==ID); P.r_stringZ (fName); CSE_Abstract *E = F_entity_Create(fName); R_ASSERT3 (E,"Can't create entity.",fName); // E->Spawn_Read (P); CSE_ALifeGraphPoint *tpGraphPoint = smart_cast<CSE_ALifeGraphPoint*>(E); if (tpGraphPoint) { E->Spawn_Read (P); Fvector tVector; tVector = tpGraphPoint->o_Position; GameGraph::_GRAPH_ID tGraphID = GameGraph::_GRAPH_ID(-1); float fMinDistance = 1000000.f; { GRAPH_VERTEX_IT B = m_tpVertices.begin(); GRAPH_VERTEX_IT I = B; GRAPH_VERTEX_IT E = m_tpVertices.end(); for ( ; I != E; I++) { float fDistance = (*I).tLocalPoint.distance_to(tVector); if (fDistance < fMinDistance) { fMinDistance = fDistance; tGraphID = GameGraph::_GRAPH_ID(I - B); if (fMinDistance < EPS_L) break; } } } if (fMinDistance < EPS_L) { SConnectionVertex T; LPSTR S; S = xr_strdup(tpGraphPoint->name_replace()); T.caConnectName = xr_strdup(*tpGraphPoint->m_caConnectionPointName); T.dwLevelID = dwfGetIDByLevelName(Ini,*tpGraphPoint->m_caConnectionLevelName); // T.tGraphID = (GameGraph::_GRAPH_ID)i; // T.tOldGraphID = tGraphID; T.tOldGraphID = (GameGraph::_GRAPH_ID)i; T.tGraphID = tGraphID; bool ok = true; VERTEX_MAP::const_iterator II = m_tVertexMap.begin(); VERTEX_MAP::const_iterator EE = m_tVertexMap.end(); for ( ; II != EE; ++II) if (T.tOldGraphID == (*II).second.tOldGraphID) { ok = false; Msg ("Graph point %s is removed,because it has the same position as some another graph point",E->name_replace()); break; } if (ok) { m_tVertexMap.insert (mk_pair(S,T)); i++; } } } F_entity_Destroy (E); } if (i != m_tpGraph->header().vertex_count()) Msg ("Graph for the level %s doesn't correspond to the graph points from Level Editor! (%d : %d)",*m_tLevel.name(),i,m_tpGraph->header().vertex_count()); VERTEX_MAP::const_iterator I = m_tVertexMap.begin(); VERTEX_MAP::const_iterator E = m_tVertexMap.end(); for ( ; I != E; ++I) { R_ASSERT3 (!xr_strlen((*I).second.caConnectName) || ((*I).second.tGraphID < m_tpVertices.size()),"Rebuild graph for the level",*m_tLevel.name()); } // VERIFY3 (i == m_tpGraph->header().vertex_count(), "Rebuild graph for the level ",m_tLevel.name()); O->close (); FS.r_close (F); } };
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); }
BOOL CGameObject::net_Spawn (CSE_Abstract* DC) { VERIFY (!m_spawned); m_spawned = true; m_spawn_time = Device.dwFrame; m_ai_obstacle = xr_new<ai_obstacle>(this); CSE_Abstract *E = (CSE_Abstract*)DC; VERIFY (E); const CSE_Visual *visual = smart_cast<const CSE_Visual*>(E); if (visual) { cNameVisual_set (visual_name(E)); if (visual->flags.test(CSE_Visual::flObstacle)) { ISpatial *self = smart_cast<ISpatial*>(this); self->spatial.type |= STYPE_OBSTACLE; } } // Naming cName_set (E->s_name); cNameSect_set (E->s_name); if (E->name_replace()[0]) cName_set (E->name_replace()); bool demo_spectator = false; if (Level().IsDemoPlayStarted() && E->ID == u16(-1)) { Msg("* Spawning demo spectator ..."); demo_spectator = true; } else { R_ASSERT(Level().Objects.net_Find(E->ID) == NULL); } setID (E->ID); // if (GameID() != eGameIDSingle) // Msg ("CGameObject::net_Spawn -- object %s[%x] setID [%d]", *(E->s_name), this, E->ID); // XForm XFORM().setXYZ (E->o_Angle); Position().set (E->o_Position); #ifdef DEBUG if(ph_dbg_draw_mask1.test(ph_m1_DbgTrackObject)&&stricmp(PH_DBG_ObjectTrackName(),*cName())==0) { Msg("CGameObject::net_Spawn obj %s Position set from CSE_Abstract %f,%f,%f",PH_DBG_ObjectTrackName(),Position().x,Position().y,Position().z); } #endif VERIFY (_valid(renderable.xform)); VERIFY (!fis_zero(DET(renderable.xform))); CSE_ALifeObject *O = smart_cast<CSE_ALifeObject*>(E); if (O && xr_strlen(O->m_ini_string)) { #pragma warning(push) #pragma warning(disable:4238) m_ini_file = xr_new<CInifile>( &IReader ( (void*)(*(O->m_ini_string)), O->m_ini_string.size() ), FS.get_path("$game_config$")->m_Path ); #pragma warning(pop) } m_story_id = ALife::_STORY_ID(-1); if (O) m_story_id = O->m_story_id; // Net params setLocal (E->s_flags.is(M_SPAWN_OBJECT_LOCAL)); if (Level().IsDemoPlay()) //&& OnClient()) { if (!demo_spectator) { setLocal(FALSE); } }; setReady (TRUE); if (!demo_spectator) g_pGameLevel->Objects.net_Register (this); m_server_flags.one (); if (O) { m_server_flags = O->m_flags; if (O->m_flags.is(CSE_ALifeObject::flVisibleForAI)) spatial.type |= STYPE_VISIBLEFORAI; else spatial.type = (spatial.type | STYPE_VISIBLEFORAI) ^ STYPE_VISIBLEFORAI; } reload (*cNameSect()); if(!g_dedicated_server) CScriptBinder::reload (*cNameSect()); reinit (); if(!g_dedicated_server) CScriptBinder::reinit (); #ifdef DEBUG if(ph_dbg_draw_mask1.test(ph_m1_DbgTrackObject)&&stricmp(PH_DBG_ObjectTrackName(),*cName())==0) { Msg("CGameObject::net_Spawn obj %s After Script Binder reinit %f,%f,%f",PH_DBG_ObjectTrackName(),Position().x,Position().y,Position().z); } #endif //load custom user data from server if(!E->client_data.empty()) { // Msg ("client data is present for object [%d][%s], load is processed",ID(),*cName()); IReader ireader = IReader(&*E->client_data.begin(), E->client_data.size()); net_Load (ireader); } else { // Msg ("no client data for object [%d][%s], load is skipped",ID(),*cName()); } // if we have a parent if ( ai().get_level_graph() ) { if ( E->ID_Parent == 0xffff ) { CSE_ALifeObject* l_tpALifeObject = smart_cast<CSE_ALifeObject*>(E); if (l_tpALifeObject && ai().level_graph().valid_vertex_id(l_tpALifeObject->m_tNodeID)) ai_location().level_vertex (l_tpALifeObject->m_tNodeID); else { CSE_Temporary* l_tpTemporary = smart_cast<CSE_Temporary*> (E); if (l_tpTemporary && ai().level_graph().valid_vertex_id(l_tpTemporary->m_tNodeID)) ai_location().level_vertex (l_tpTemporary->m_tNodeID); } if (l_tpALifeObject && ai().game_graph().valid_vertex_id(l_tpALifeObject->m_tGraphID)) ai_location().game_vertex (l_tpALifeObject->m_tGraphID); validate_ai_locations (false); // validating position if ( UsedAI_Locations() && ai().level_graph().inside( ai_location().level_vertex_id(), Position() ) && can_validate_position_on_spawn() ) Position().y = EPS_L + ai().level_graph().vertex_plane_y(*ai_location().level_vertex(),Position().x,Position().z); } else { CSE_ALifeObject* const alife_object = smart_cast<CSE_ALifeObject*>(E); if ( alife_object && ai().level_graph().valid_vertex_id(alife_object->m_tNodeID) ) { ai_location().level_vertex (alife_object->m_tNodeID); ai_location().game_vertex (alife_object->m_tGraphID); } } } inherited::net_Spawn (DC); m_bObjectRemoved = false; spawn_supplies (); #ifdef DEBUG if(ph_dbg_draw_mask1.test(ph_m1_DbgTrackObject)&&stricmp(PH_DBG_ObjectTrackName(),*cName())==0) { Msg("CGameObject::net_Spawn obj %s Before CScriptBinder::net_Spawn %f,%f,%f",PH_DBG_ObjectTrackName(),Position().x,Position().y,Position().z); } BOOL ret =CScriptBinder::net_Spawn(DC); #else return (CScriptBinder::net_Spawn(DC)); #endif #ifdef DEBUG if(ph_dbg_draw_mask1.test(ph_m1_DbgTrackObject)&&stricmp(PH_DBG_ObjectTrackName(),*cName())==0) { Msg("CGameObject::net_Spawn obj %s Before CScriptBinder::net_Spawn %f,%f,%f",PH_DBG_ObjectTrackName(),Position().x,Position().y,Position().z); } return ret; #endif }