void CUICharacterInfo::Update() { inherited::Update(); if ( hasOwner() && ( m_bForceUpdate ||(Device.dwFrame%50 == 0) ) ) { m_bForceUpdate = false; CSE_ALifeTraderAbstract* T = detail::object_exists_in_alife_registry(m_ownerID) ? ch_info_get_from_id(m_ownerID) : NULL; if (NULL==T){ m_ownerID = u16(-1); return; } else { UpdateRelation(); } if ( m_icons[eIcon] ) { CSE_ALifeCreatureAbstract* pCreature = smart_cast<CSE_ALifeCreatureAbstract*>(T); if ( pCreature && !pCreature->g_Alive() ) { m_icons[eIcon]->SetTextureColor(color_argb(255,255,160,160)); } } } }
bool se_obj_is_alive(CSE_ALifeObject *O) { CSE_ALifeCreatureAbstract *cr = smart_cast<CSE_ALifeCreatureAbstract *> (O); if (cr) return cr->g_Alive(); else return false; }
void game_sv_GameState::on_death (CSE_Abstract *e_dest, CSE_Abstract *e_src) { CSE_ALifeCreatureAbstract *creature = smart_cast<CSE_ALifeCreatureAbstract*>(e_dest); if (!creature) return; VERIFY (creature->get_killer_id() == ALife::_OBJECT_ID(-1)); creature->set_killer_id ( e_src->ID ); }
virtual void Execute (LPCSTR args) { typedef CSafeMapIterator<ALife::_OBJECT_ID,CSE_ALifeDynamicObject>::_REGISTRY::const_iterator const_iterator; const_iterator I = ai().alife().graph().level().objects().begin(); const_iterator E = ai().alife().graph().level().objects().end(); for ( ; I != E; ++I) { CSE_ALifeCreatureAbstract *obj = smart_cast<CSE_ALifeCreatureAbstract *>(I->second); if (obj) { Msg("\"%s\",",obj->name_replace()); } } }
void CALifeSimulatorBase::on_death (CSE_Abstract *killed, CSE_Abstract *killer) { typedef CSE_ALifeOnlineOfflineGroup::MEMBER GROUP_MEMBER; CSE_ALifeCreatureAbstract *creature = smart_cast<CSE_ALifeCreatureAbstract*>(killed); if (creature) creature->on_death (killer); GROUP_MEMBER *member = smart_cast<GROUP_MEMBER*>(killed); if (!member) return; if (member->m_group_id == 0xffff) return; groups().object(member->m_group_id).notify_on_member_death (member); }
void CALifeUpdateManager::add_restriction (ALife::_OBJECT_ID id, ALife::_OBJECT_ID restriction_id, const RestrictionSpace::ERestrictorTypes &restriction_type) { CSE_ALifeDynamicObject *object = objects().object(id,true); if (!object) { Msg ("! cannot add restriction with id %d to the entity with id %d, because there is no creature with the specified id",restriction_id,id); return; } CSE_ALifeDynamicObject *object_restrictor = objects().object(restriction_id,true); if (!object_restrictor) { Msg ("! cannot add restriction with id %d to the entity with id %d, because there is no space restrictor with the specified id",restriction_id,id); return; } CSE_ALifeCreatureAbstract *creature = smart_cast<CSE_ALifeCreatureAbstract*>(object); if (!creature) { Msg ("! cannot add restriction with id %d to the entity with id %d, because there is an object with the specified id, but it is not a creature",restriction_id,id); return; } CSE_ALifeSpaceRestrictor *restrictor = smart_cast<CSE_ALifeSpaceRestrictor*>(object_restrictor); if (!restrictor) { Msg ("! cannot add restriction with id %d to the entity with id %d, because there is an object with the specified id, but it is not a space restrictor",restriction_id,id); return; } switch (restriction_type) { case RestrictionSpace::eRestrictorTypeOut : { #ifdef DEBUG if (std::find(creature->m_dynamic_out_restrictions.begin(),creature->m_dynamic_out_restrictions.end(),restriction_id) != creature->m_dynamic_out_restrictions.end()) { Msg ("! cannot add out-restriction with id %d, name %s to the entity with id %d, name %s, because it is already added",restriction_id,restrictor->name_replace(),id,creature->name_replace()); return; } #endif creature->m_dynamic_out_restrictions.push_back(restriction_id); break; } case RestrictionSpace::eRestrictorTypeIn : { #ifdef DEBUG if (std::find(creature->m_dynamic_in_restrictions.begin(),creature->m_dynamic_in_restrictions.end(),restriction_id) != creature->m_dynamic_in_restrictions.end()) { Msg ("! cannot add in-restriction with id %d, name %s to the entity with id %d, name %s, because it is already added",restriction_id,restrictor->name_replace(),id,creature->name_replace()); return; } #endif creature->m_dynamic_in_restrictions.push_back(restriction_id); break; } default : { Msg ("! Invalid restriction type!"); return; } } }
void game_sv_GameState::assign_RP (CSE_Abstract* E, game_PlayerState* ps_who) { VERIFY (E); u8 l_uc_team = u8(-1); CSE_Spectator *tpSpectator = smart_cast<CSE_Spectator*>(E); if (tpSpectator) { l_uc_team = tpSpectator->g_team(); #ifdef DEBUG Msg("--- game_sv_GameState RPoint for Spectators uses team [%d]", l_uc_team); #endif // #ifdef DEBUG } else { CSE_ALifeCreatureAbstract *tpTeamed = smart_cast<CSE_ALifeCreatureAbstract*>(E); if (tpTeamed) { l_uc_team = tpTeamed->g_team(); #ifdef DEBUG Msg("--- game_sv_GameState RPoint for AlifeCreature uses team [%d]", l_uc_team); #endif // #ifdef DEBUG } else { R_ASSERT2(false/*tpTeamed*/,"Non-teamed object is assigning to respawn point!"); } } R_ASSERT2(l_uc_team < TEAM_COUNT, make_string("not found rpoint for team [%d]", l_uc_team).c_str()); xr_vector<RPoint>& rp = rpoints[l_uc_team]; #ifdef DEBUG Msg("---Size of rpoints of team [%d] is [%d]", l_uc_team, rp.size()); #endif //----------------------------------------------------------- xr_vector<u32> xrp;// = rpoints[l_uc_team]; for (u32 i=0; i<rp.size(); i++) { if (rp[i].TimeToUnfreeze < Level().timeServer()) xrp.push_back(i); } u32 rpoint = 0; if (xrp.size() && !tpSpectator) { rpoint = xrp[::Random.randI((int)xrp.size())]; } else { if (!tpSpectator) { for (u32 i=0; i<rp.size(); i++) { rp[i].TimeToUnfreeze = 0; }; }; rpoint = ::Random.randI((int)rp.size()); } //----------------------------------------------------------- #ifdef DEBUG Msg("--- Result rpoint is [%d]", rpoint); #endif // #ifdef DEBUG RPoint& r = rp[rpoint]; if (!tpSpectator) { r.TimeToUnfreeze = Level().timeServer() + g_sv_base_dwRPointFreezeTime; }; E->o_Position.set (r.P); E->o_Angle.set (r.A); }
void xrServer::Process_event (NET_Packet& P, ClientID sender) { # ifdef SLOW_VERIFY_ENTITIES VERIFY (verify_entities()); # endif u32 timestamp; u16 type; u16 destination; u32 MODE = net_flags(TRUE,TRUE); // correct timestamp with server-unique-time (note: direct message correction) P.r_u32 (timestamp ); // read generic info P.r_u16 (type ); P.r_u16 (destination); CSE_Abstract* receiver = game->get_entity_from_eid (destination); if (receiver) { R_ASSERT(receiver->owner); receiver->OnEvent (P,type,timestamp,sender); }; switch (type) { case GE_GAME_EVENT: { u16 game_event_type; P.r_u16(game_event_type); game->AddDelayedEvent(P,game_event_type,timestamp,sender); }break; case GE_INFO_TRANSFER: case GE_WPN_STATE_CHANGE: case GE_ZONE_STATE_CHANGE: case GE_ACTOR_JUMPING: case GEG_PLAYER_PLAY_HEADSHOT_PARTICLE: case GEG_PLAYER_ATTACH_HOLDER: case GEG_PLAYER_DETACH_HOLDER: case GEG_PLAYER_ITEM2SLOT: case GEG_PLAYER_ITEM2BELT: case GEG_PLAYER_ITEM2RUCK: case GE_GRENADE_EXPLODE: { SendBroadcast (BroadcastCID,P,MODE); }break; case GEG_PLAYER_ACTIVATEARTEFACT: { Process_event_activate (P,sender,timestamp,destination,P.r_u16(), true); break; }; case GE_INV_ACTION: { xrClientData* CL = ID_to_client(sender); if (CL) CL->net_Ready = TRUE; if (SV_Client) SendTo(SV_Client->ID, P, net_flags(TRUE, TRUE)); }break; case GE_RESPAWN: { CSE_Abstract* E = receiver; if (E) { R_ASSERT (E->s_flags.is(M_SPAWN_OBJECT_PHANTOM)); svs_respawn R; R.timestamp = timestamp + E->RespawnTime*1000; R.phantom = destination; q_respawn.insert (R); } } break; case GE_TRADE_BUY: case GE_OWNERSHIP_TAKE: { Process_event_ownership (P,sender,timestamp,destination); VERIFY (verify_entities()); }break; case GE_OWNERSHIP_TAKE_MP_FORCED: { Process_event_ownership (P,sender,timestamp,destination,TRUE); VERIFY (verify_entities()); }break; case GE_TRADE_SELL: case GE_OWNERSHIP_REJECT: case GE_LAUNCH_ROCKET: { Process_event_reject (P,sender,timestamp,destination,P.r_u16()); VERIFY (verify_entities()); }break; case GE_DESTROY: { Process_event_destroy (P,sender,timestamp,destination, NULL); VERIFY (verify_entities()); } break; case GE_TRANSFER_AMMO: { u16 id_entity; P.r_u16 (id_entity); CSE_Abstract* e_parent = receiver; // кто забирает (для своих нужд) CSE_Abstract* e_entity = game->get_entity_from_eid (id_entity); // кто отдает if (!e_entity) break; if (0xffff != e_entity->ID_Parent) break; // this item already taken xrClientData* c_parent = e_parent->owner; xrClientData* c_from = ID_to_client (sender); R_ASSERT (c_from == c_parent); // assure client ownership of event // Signal to everyone (including sender) SendBroadcast (BroadcastCID,P,MODE); // Perfrom real destroy entity_Destroy (e_entity ); VERIFY (verify_entities()); } break; case GE_HIT: case GE_HIT_STATISTIC: { P.r_pos -=2; if (type == GE_HIT_STATISTIC) { P.B.count -= 4; P.w_u32(sender.value()); }; game->AddDelayedEvent(P,GAME_EVENT_ON_HIT, 0, ClientID() ); } break; case GE_ASSIGN_KILLER: { u16 id_src; P.r_u16 (id_src); CSE_Abstract *e_dest = receiver; // кто умер // this is possible when hit event is sent before destroy event if (!e_dest) break; CSE_ALifeCreatureAbstract *creature = smart_cast<CSE_ALifeCreatureAbstract*>(e_dest); if (creature) creature->set_killer_id( id_src ); // Msg ("[%d][%s] killed [%d][%s]",id_src,id_src==u16(-1) ? "UNKNOWN" : game->get_entity_from_eid(id_src)->name_replace(),id_dest,e_dest->name_replace()); break; } case GE_CHANGE_VISUAL: { CSE_Visual* visual = smart_cast<CSE_Visual*>(receiver); VERIFY(visual); string256 tmp; P.r_stringZ (tmp); visual->set_visual (tmp); }break; case GE_DIE: { // Parse message u16 id_dest = destination, id_src; P.r_u16 (id_src); xrClientData *l_pC = ID_to_client(sender); VERIFY (game && l_pC); #ifndef MASTER_GOLD if ((game->Type() != eGameIDSingle) && l_pC && l_pC->owner) { Msg ("* [%2d] killed by [%2d] - sended by [%s:%2d]", id_dest, id_src, game->get_option_s(*l_pC->name,"name","Player"), l_pC->owner->ID); } #endif // #ifndef MASTER_GOLD CSE_Abstract* e_dest = receiver; // кто умер // this is possible when hit event is sent before destroy event if (!e_dest) break; #ifndef MASTER_GOLD if (game->Type() != eGameIDSingle) Msg ("* [%2d] is [%s:%s]", id_dest, *e_dest->s_name, e_dest->name_replace()); #endif // #ifndef MASTER_GOLD CSE_Abstract* e_src = game->get_entity_from_eid (id_src ); // кто убил if (!e_src) { xrClientData* C = (xrClientData*) game->get_client(id_src); if (C) e_src = C->owner; }; VERIFY (e_src); if (!e_src) { Msg("! ERROR: SV: src killer not exist."); return; } // R_ASSERT2 (e_dest && e_src, "Killer or/and being killed are offline or not exist at all :("); #ifndef MASTER_GOLD if (game->Type() != eGameIDSingle) Msg ("* [%2d] is [%s:%s]", id_src, *e_src->s_name, e_src->name_replace()); #endif // #ifndef MASTER_GOLD game->on_death (e_dest,e_src); xrClientData* c_src = e_src->owner; // клиент, чей юнит убил if (c_src->owner->ID == id_src) { // Main unit P.w_begin (M_EVENT); P.w_u32 (timestamp); P.w_u16 (type); P.w_u16 (destination); P.w_u16 (id_src); P.w_clientID (c_src->ID); } SendBroadcast (BroadcastCID,P,MODE); ////////////////////////////////////////////////////////////////////////// // if (game->Type() == eGameIDSingle) { P.w_begin (M_EVENT); P.w_u32 (timestamp); P.w_u16 (GE_KILL_SOMEONE); P.w_u16 (id_src); P.w_u16 (destination); SendTo (c_src->ID, P, net_flags(TRUE, TRUE)); } ////////////////////////////////////////////////////////////////////////// VERIFY (verify_entities()); } break; case GE_ADDON_ATTACH: case GE_ADDON_DETACH: case GE_CHANGE_POS: { SendTo(SV_Client->ID, P, net_flags(TRUE, TRUE)); }break; case GE_INSTALL_UPGRADE: { shared_str upgrade_id; P.r_stringZ ( upgrade_id ); CSE_ALifeInventoryItem* iitem = smart_cast<CSE_ALifeInventoryItem*>( receiver ); if ( !iitem ) { break; } iitem->add_upgrade ( upgrade_id ); }break; case GEG_PLAYER_DISABLE_SPRINT: case GEG_PLAYER_WEAPON_HIDE_STATE: { SendTo (SV_Client->ID, P, net_flags(TRUE, TRUE)); # ifdef SLOW_VERIFY_ENTITIES VERIFY (verify_entities()); # endif }break; case GEG_PLAYER_ACTIVATE_SLOT: case GEG_PLAYER_ITEM_EAT: { SendTo(SV_Client->ID, P, net_flags(TRUE, TRUE)); # ifdef SLOW_VERIFY_ENTITIES VERIFY (verify_entities()); # endif }break; case GEG_PLAYER_ITEM_SELL: { game->OnPlayer_Sell_Item(sender, P); }break; case GE_TELEPORT_OBJECT: { game->teleport_object (P,destination); }break; case GE_ADD_RESTRICTION: { game->add_restriction (P,destination); }break; case GE_REMOVE_RESTRICTION: { game->remove_restriction(P,destination); }break; case GE_REMOVE_ALL_RESTRICTIONS: { game->remove_all_restrictions(P,destination); }break; case GE_MONEY: { CSE_Abstract *e_dest = receiver; CSE_ALifeTraderAbstract* pTa = smart_cast<CSE_ALifeTraderAbstract*>(e_dest); pTa->m_dwMoney = P.r_u32(); }break; case GE_FREEZE_OBJECT: break; default: R_ASSERT2 (0,"Game Event not implemented!!!"); break; } }
bool CRelationMapLocation::Update() { if (false==inherited::Update() ) return false; bool bAlive = true; m_last_relation = ALife::eRelationTypeFriend; if(m_owner_se_object) { CSE_ALifeTraderAbstract* pEnt = NULL; CSE_ALifeTraderAbstract* pAct = NULL; pEnt = smart_cast<CSE_ALifeTraderAbstract*>(m_owner_se_object); pAct = smart_cast<CSE_ALifeTraderAbstract*>(ai().alife().objects().object(m_pInvOwnerActorID,true)); if(!pEnt || !pAct) return false; m_last_relation = RELATION_REGISTRY().GetRelationType(pEnt, pAct); CSE_ALifeCreatureAbstract* pCreature = smart_cast<CSE_ALifeCreatureAbstract*>(m_owner_se_object); if(pCreature) //maybe trader ? bAlive = pCreature->g_Alive (); }else { CInventoryOwner* pEnt = NULL; CInventoryOwner* pAct = NULL; pEnt = smart_cast<CInventoryOwner*>(Level().Objects.net_Find(m_objectID)); pAct = smart_cast<CInventoryOwner*>(Level().Objects.net_Find(m_pInvOwnerActorID)); if(!pEnt || !pAct) return false; m_last_relation = RELATION_REGISTRY().GetRelationType(pEnt, pAct); CEntityAlive* pEntAlive = smart_cast<CEntityAlive*>(pEnt); if(pEntAlive) bAlive = !!pEntAlive->g_Alive (); } shared_str sname; if(bAlive==false) sname = "deadbody_location"; else sname = RELATION_REGISTRY().GetSpotName(m_last_relation); if(m_curr_spot_name != sname){ LoadSpot(*sname, true); m_curr_spot_name = sname; } // update visibility bool vis_res = true; if(m_last_relation==ALife::eRelationTypeEnemy || m_last_relation==ALife::eRelationTypeWorstEnemy) { CObject* _object_ = Level().Objects.net_Find(m_objectID); if(_object_) { CEntityAlive* ea = smart_cast<CEntityAlive*>(_object_); if(ea&&!ea->g_Alive()) vis_res = true; else { const CGameObject* pObj = smart_cast<const CGameObject*>(_object_); CActor* pAct = smart_cast<CActor*>(Level().Objects.net_Find(m_pInvOwnerActorID)); CHelmet* helm = smart_cast<CHelmet*>(pAct->inventory().ItemFromSlot(HELMET_SLOT)); if(helm && helm->m_fShowNearestEnemiesDistance) { if(pAct->Position().distance_to(pObj->Position()) < helm->m_fShowNearestEnemiesDistance) vis_res = true; else vis_res = Actor()->memory().visual().visible_now(pObj); } else vis_res = Actor()->memory().visual().visible_now(pObj); } } else vis_res = false; } if(bAlive==false) { CObject* _object_ = Level().Objects.net_Find(m_objectID); if(_object_) { const CGameObject* pObj = smart_cast<const CGameObject*>(_object_); CActor* pAct = smart_cast<CActor*>(Level().Objects.net_Find(m_pInvOwnerActorID)); if(/*pAct->Position().distance_to_sqr(pObj->Position()) < 100.0F && */abs(pObj->Position().y-pAct->Position().y)<3.0f) vis_res = true; else vis_res = false; } else vis_res = false; } if(m_b_visible==false && vis_res==true) m_minimap_spot->ResetXformAnimation(); m_b_visible = vis_res; if(m_b_visible) { m_b_minimap_visible = true; m_b_levelmap_visible = true; if (Level().MapManager().GetMapLocationsForObject(m_objectID, find_locations_res) ) { xr_vector<CMapLocation*>::iterator it = find_locations_res.begin(); xr_vector<CMapLocation*>::iterator it_e = find_locations_res.end(); for(;it!=it_e;++it) { CMapLocation* ml = (*it); if(ml==this) continue; m_b_minimap_visible = m_b_minimap_visible && (ml->MiniMapSpot()==NULL); m_b_levelmap_visible= m_b_levelmap_visible && (ml->LevelMapSpot()==NULL); } } } return true; }
BOOL CEntity::net_Spawn (CSE_Abstract* DC) { m_level_death_time = 0; m_game_death_time = 0; m_killer_id = ALife::_OBJECT_ID(-1); CSE_Abstract *e = (CSE_Abstract*)(DC); CSE_ALifeCreatureAbstract *E = smart_cast<CSE_ALifeCreatureAbstract*>(e); // Initialize variables if (E) { SetfHealth (E->get_health()); R_ASSERT2(!((E->get_killer_id() != ALife::_OBJECT_ID(-1)) && g_Alive()), make_string("server entity [%s][%d] has an killer [%d] and not dead", E->name_replace(), E->ID, E->get_killer_id()).c_str()); m_killer_id = E->get_killer_id(); if (m_killer_id == ID()) m_killer_id = ALife::_OBJECT_ID(-1); } else SetfHealth (1.0f); // load damage params if (!E) { // Car or trader only!!!! CSE_ALifeCar *C = smart_cast<CSE_ALifeCar*>(e); CSE_ALifeTrader *T = smart_cast<CSE_ALifeTrader*>(e); CSE_ALifeHelicopter *H = smart_cast<CSE_ALifeHelicopter*>(e); R_ASSERT2 (C||T||H,"Invalid entity (no inheritance from CSE_CreatureAbstract, CSE_ALifeItemCar and CSE_ALifeTrader and CSE_ALifeHelicopter)!"); id_Team = id_Squad = id_Group = 0; } else { id_Team = E->g_team(); id_Squad = E->g_squad(); id_Group = E->g_group(); CSE_ALifeMonsterBase *monster = smart_cast<CSE_ALifeMonsterBase*>(E); if (monster) { MONSTER_COMMUNITY monster_community; monster_community.set (pSettings->r_string(*cNameSect(), "species")); if(monster_community.team() != 255) id_Team = monster_community.team(); } } if (g_Alive() && IsGameTypeSingle()) { m_registered_member = true; Level().seniority_holder().team(g_Team()).squad(g_Squad()).group(g_Group()).register_member(this); ++Level().seniority_holder().team(g_Team()).squad(g_Squad()).group(g_Group()).m_dwAliveCount; } if(!g_Alive()) { m_level_death_time = Device.dwTimeGlobal; m_game_death_time = E->m_game_death_time;; } if (!inherited::net_Spawn(DC)) return (FALSE); // SetfHealth (E->fHealth); IKinematics* pKinematics=smart_cast<IKinematics*>(Visual()); CInifile* ini = NULL; if(pKinematics) ini = pKinematics->LL_UserData(); if (ini) { if (ini->section_exist("damage_section") && !use_simplified_visual()) CDamageManager::reload(pSettings->r_string("damage_section","damage"),ini); CParticlesPlayer::LoadParticles(pKinematics); } return TRUE; }