Skip to content

Commit

Permalink
OMP Stuff (Resolve #70)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiX225 authored and Drombeys committed Sep 29, 2024
1 parent 31030cf commit 12547f5
Show file tree
Hide file tree
Showing 18 changed files with 360 additions and 49 deletions.
3 changes: 1 addition & 2 deletions src/xrGame/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,8 +1545,7 @@ void CActor::shedule_Update (u32 DT)
}
else
{
if (m_pPersonWeLookingAt && pEntityAlive->g_Alive() && m_pPersonWeLookingAt->IsTalkEnabled())
{
if (m_pPersonWeLookingAt && pEntityAlive->g_Alive() && m_pPersonWeLookingAt->IsTalkEnabled() && !pEntityAlive->cast_actor()) {
m_sDefaultObjAction = m_sCharacterUseAction;
}
else if ( pEntityAlive && !pEntityAlive->g_Alive() )
Expand Down
37 changes: 36 additions & 1 deletion src/xrGame/FreeMP/game_cl_freemp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "stdafx.h"
#include "stdafx.h"
#include "game_cl_freemp.h"
#include "clsid_game.h"
#include "../../xrEngine/xr_level_controller.h"
Expand Down Expand Up @@ -62,6 +62,36 @@ void game_cl_freemp::net_import_update(NET_Packet& P)
inherited::net_import_update(P);
}

void game_cl_freemp::shedule_Update(u32 dt)
{
if (!local_player)
return;

for (auto cl : players)
{
game_PlayerState* ps = cl.second;
if (!ps || ps->testFlag(GAME_PLAYER_FLAG_VERY_VERY_DEAD)) continue;

CActor* pActor = smart_cast<CActor*>(Level().Objects.net_Find(ps->GameID));
if (!pActor || !pActor->g_Alive()) continue;

pActor->SetName(ps->getName());
pActor->cName_set(ps->getName());

if (ps->team != pActor->Community())
{
CHARACTER_COMMUNITY community;
community.set(ps->team);
pActor->SetCommunity(community.index());
pActor->ChangeTeam(community.team(), 0, 0);
}

if (local_player->GameID == ps->GameID)
{
pActor->set_money((u32)ps->money_for_round, false);
}
}
}
bool game_cl_freemp::OnKeyboardPress(int key)
{
if (kJUMP == key)
Expand Down Expand Up @@ -116,6 +146,11 @@ BOOL game_sv_freemp::OnTouch(u16 eid_who, u16 eid_what, BOOL bForced)
if (!e_entity)
return FALSE;

if (e_entity->m_tClassID == CLSID_OBJECT_PLAYERS_BAG)
{
return OnTouchPlayersBag(e_who, e_entity);
}

return TRUE;
}

Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/FreeMP/game_cl_freemp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class game_cl_freemp :public game_cl_mp
virtual void net_import_state(NET_Packet& P);
virtual void net_import_update(NET_Packet& P);

virtual void shedule_Update(u32 dt);

virtual bool OnKeyboardPress(int key);
virtual void OnConnected();

Expand Down
39 changes: 39 additions & 0 deletions src/xrGame/FreeMP/game_sv_freemp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "alife_time_manager.h"

#include "restriction_space.h"
#include "../xrServerEntities/clsid_game.h"

game_sv_freemp::game_sv_freemp()
:pure_relcase(&game_sv_freemp::net_Relcase)
Expand Down Expand Up @@ -246,6 +247,39 @@ void game_sv_freemp::OnPlayerReady(ClientID id_who)
};
}

void game_sv_freemp::RespawnPlayer(ClientID id_who, bool NoSpectator)
{
inherited::RespawnPlayer(id_who, NoSpectator);

xrClientData* xrCData = (xrClientData*)m_server->ID_to_client(id_who);
if (!xrCData) return;

game_PlayerState* ps = xrCData->ps;
if (!ps) return;

CSE_ALifeCreatureActor* pA = smart_cast<CSE_ALifeCreatureActor*>(xrCData->owner);
if (!pA) return;

SpawnWeapon4Actor(pA->ID, "mp_players_rukzak", 0, ps->pItemList);
}

void game_sv_freemp::OnDetach(u16 eid_who, u16 eid_what)
{
CSE_ActorMP* e_who = smart_cast<CSE_ActorMP*>(m_server->ID_to_entity(eid_who));
if (!e_who)
return;

CSE_Abstract* e_entity = m_server->ID_to_entity(eid_what);
if (!e_entity)
return;

// drop players bag
if (e_entity->m_tClassID == CLSID_OBJECT_PLAYERS_BAG)
{
OnDetachPlayersBag(e_who, e_entity);
}
}

// player disconnect
void game_sv_freemp::OnPlayerDisconnect(ClientID id_who, LPSTR Name, u16 GameID)
{
Expand Down Expand Up @@ -274,6 +308,11 @@ void game_sv_freemp::OnEvent(NET_Packet& P, u16 type, u32 time, ClientID sender)
KillPlayer(l_pC->ID, l_pC->ps->GameID);
}
break;
case GAME_EVENT_TRANSFER_MONEY:
{
OnTransferMoney(P, sender);
}
break;
default:
inherited::OnEvent(P, type, time, sender);
};
Expand Down
9 changes: 9 additions & 0 deletions src/xrGame/FreeMP/game_sv_freemp.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,14 @@ class game_sv_freemp : public game_sv_mp, private pure_relcase
virtual void OnEvent(NET_Packet& tNetPacket, u16 type, u32 time, ClientID sender);

virtual void Update();

virtual void RespawnPlayer(ClientID id_who, bool NoSpectator);
virtual BOOL OnTouch(u16 eid_who, u16 eid_what, BOOL bForced = false);
virtual void OnDetach(u16 eid_who, u16 eid_what);

// drop items after death
virtual void FillDeathActorRejectItems(CSE_ActorMP* actor, xr_vector<CSE_Abstract*>& to_reject);
BOOL OnTouchPlayersBag(CSE_ActorMP* actor, CSE_Abstract* item);
void OnDetachPlayersBag(CSE_ActorMP* actor, CSE_Abstract* item);

};
156 changes: 156 additions & 0 deletions src/xrGame/FreeMP/game_sv_freemp_drop_items.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#include "stdafx.h"
#include "game_sv_freemp.h"
#include "clsid_game.h"
#include "actor_mp_client.h"
#include "Inventory.h"

void game_sv_freemp::FillDeathActorRejectItems(CSE_ActorMP* actor, xr_vector<CSE_Abstract*>& to_reject)
{
R_ASSERT(actor);
CActor* pActor = smart_cast<CActor*>(Level().Objects.net_Find(actor->ID));

VERIFY2(pActor, make_string<const char*>("Actor not found. actor_id = [%d]", actor->ID));
if (!pActor) {
Msg("! ERROR: Actor not found. actor_id = [%d]", actor->ID);
return;
}

u16 active_slot = pActor->inventory().GetActiveSlot();
if (active_slot == KNIFE_SLOT || active_slot == BOLT_SLOT || active_slot == BINOCULAR_SLOT)
{
active_slot = NO_ACTIVE_SLOT;
}

if (active_slot != NO_ACTIVE_SLOT)
{
PIItem item = pActor->inventory().ItemFromSlot(active_slot);
if (!item)
{
return;
}
CSE_Abstract* server_item = m_server->ID_to_entity(item->object_id());
if (!server_item)
{
return;
}

to_reject.push_back(server_item);
}
}

BOOL game_sv_freemp::OnTouchPlayersBag(CSE_ActorMP* actor, CSE_Abstract* item)
{
R_ASSERT(actor);
R_ASSERT(item);

if (item->ID_Parent != 0xffff)
{
return TRUE;
}

//move all items from rukzak to player

if (!item->children.empty())
{
NET_Packet EventPack;
NET_Packet PacketReject;
NET_Packet PacketTake;

EventPack.w_begin(M_EVENT_PACK);

while (!item->children.empty())
{
CSE_Abstract* e_child_item = get_entity_from_eid(item->children.back());
if (e_child_item)
{
if (!OnTouch(actor->ID, e_child_item->ID, FALSE))
{
NET_Packet P;
u_EventGen(P, GE_OWNERSHIP_REJECT, item->ID);
P.w_u16(e_child_item->ID);

m_server->Process_event_reject(P, m_server->GetServerClient()->ID, 0, item->ID, e_child_item->ID);
continue;
}
}

m_server->Perform_transfer(PacketReject, PacketTake, e_child_item, item, actor);

EventPack.w_u8(u8(PacketReject.B.count));
EventPack.w(&PacketReject.B.data, PacketReject.B.count);
EventPack.w_u8(u8(PacketTake.B.count));
EventPack.w(&PacketTake.B.data, PacketTake.B.count);
}
if (EventPack.B.count > 2)
u_EventSend(EventPack);
}

//destroy the BAG
DestroyGameItem(item);

return FALSE;
}

void game_sv_freemp::OnDetachPlayersBag(CSE_ActorMP* actor, CSE_Abstract* item)
{
R_ASSERT(actor);
R_ASSERT(item);

//move all items from player to rukzak
xr_vector<u16>::const_iterator it_e = actor->children.end();

xr_vector<CSE_Abstract*> to_transfer;
xr_vector<CSE_Abstract*> to_destroy;
xr_vector<CSE_Abstract*> to_reject;

// may be there is a sense to move next invokation into the ProcessDeath method...
FillDeathActorRejectItems(actor, to_reject);

for (auto it = actor->children.cbegin(); it != it_e; ++it)
{
u16 ItemID = *it;
CSE_Abstract* e_item = get_entity_from_eid(ItemID);

R_ASSERT(e_item->ID_Parent == actor->ID);

if (std::find(to_reject.begin(), to_reject.end(), e_item) != to_reject.end())
continue;

if ((e_item->m_tClassID == CLSID_OBJECT_W_KNIFE) ||
(e_item->m_tClassID == CLSID_DEVICE_TORCH) ||
(e_item->m_tClassID == CLSID_IITEM_BOLT))
{
to_destroy.push_back(e_item);
}
else
{
if (!smart_cast<CSE_ALifeItemCustomOutfit*>(e_item) && e_item->m_tClassID != CLSID_OBJECT_PLAYERS_BAG)
{
to_transfer.push_back(e_item);
}
}
}

NET_Packet EventPack;
NET_Packet PacketReject;
NET_Packet PacketTake;
EventPack.w_begin(M_EVENT_PACK);

for (auto it = to_transfer.cbegin(); it != to_transfer.cend(); ++it)
{
m_server->Perform_transfer(PacketReject, PacketTake, *it, actor, item);
EventPack.w_u8(u8(PacketReject.B.count));
EventPack.w(&PacketReject.B.data, PacketReject.B.count);
EventPack.w_u8(u8(PacketTake.B.count));
EventPack.w(&PacketTake.B.data, PacketTake.B.count);
}

if (EventPack.B.count > 2)
u_EventSend(EventPack);

for (const auto& el : to_destroy)
DestroyGameItem(el);

for (const auto& el : to_reject)
RejectGameItem(el);
}
52 changes: 26 additions & 26 deletions src/xrGame/HUDTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,11 @@ void CHUDTarget::CursorOnFrame ()
if(Level().ObjectSpace.RayQuery(RQR,RD, pick_trace_callback, &PP, nullptr, Level().CurrentEntity()))
clamp (PP.RQ.range, NEAR_LIM, PP.RQ.range);
}

}

extern ENGINE_API BOOL g_bRendering;
void CHUDTarget::Render()
{

BOOL b_do_rendering = ( psHUD_Flags.is(HUD_CROSSHAIR|HUD_CROSSHAIR_RT|HUD_CROSSHAIR_RT2) );

if(!b_do_rendering)
Expand Down Expand Up @@ -186,37 +184,39 @@ void CHUDTarget::Render()
CEntityAlive* E_ = smart_cast<CEntityAlive*>(PP.RQ.O);
CEntityAlive* pCurEnt = smart_cast<CEntityAlive*>(Level().CurrentEntity());
PIItem l_pI = smart_cast<PIItem>(PP.RQ.O);

CActor* pActor = smart_cast<CActor*> (PP.RQ.O);
CInventoryOwner* our_inv_owner = smart_cast<CInventoryOwner*>(pCurEnt);

if (E_ && E_->g_Alive() && E_->cast_base_monster())
if (E_ && E_->g_Alive())
{
C = C_ON_ENEMY;
}
else if (E_ && E_->g_Alive() && !E_->cast_base_monster())
{
CInventoryOwner* others_inv_owner = smart_cast<CInventoryOwner*>(E_);

if (our_inv_owner && others_inv_owner) {

switch (RELATION_REGISTRY().GetRelationType(others_inv_owner, our_inv_owner))
{
case ALife::eRelationTypeEnemy:
C = C_ON_ENEMY; break;
case ALife::eRelationTypeNeutral:
C = C_ON_NEUTRAL; break;
case ALife::eRelationTypeFriend:
C = C_ON_FRIEND; break;
}
if (E_->cast_base_monster())
{
C = C_ON_ENEMY;
}
else if (!pActor || (pActor && IsGameTypeSingleCompatible()))
{
CInventoryOwner* others_inv_owner = smart_cast<CInventoryOwner*>(E_);

if (fuzzyShowInfo > 0.5f)
if (our_inv_owner && others_inv_owner)
{
F->SetColor(subst_alpha(C, u8(iFloor(255.f * (fuzzyShowInfo - 0.5f) * 2.f))));
F->OutNext("%s", *g_pStringTable->translate(others_inv_owner->Name()));
F->OutNext("%s", *g_pStringTable->translate(others_inv_owner->CharacterInfo().Community().id()));
switch (RELATION_REGISTRY().GetRelationType(others_inv_owner, our_inv_owner))
{
case ALife::eRelationTypeEnemy:
C = C_ON_ENEMY; break;
case ALife::eRelationTypeNeutral:
C = C_ON_NEUTRAL; break;
case ALife::eRelationTypeFriend:
C = C_ON_FRIEND; break;
}

if (fuzzyShowInfo > 0.5f)
{
F->SetColor(subst_alpha(C, u8(iFloor(255.f * (fuzzyShowInfo - 0.5f) * 2.f))));
F->OutNext("%s", *g_pStringTable->translate(others_inv_owner->Name()));
F->OutNext("%s", *g_pStringTable->translate(others_inv_owner->CharacterInfo().Community().id()));
}
}
}

fuzzyShowInfo += SHOW_INFO_SPEED * Device.fTimeDelta;
}
else if (l_pI && our_inv_owner && PP.RQ.range < 2.0f * 2.0f)
Expand Down
5 changes: 5 additions & 0 deletions src/xrGame/InventoryOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ LPCSTR CInventoryOwner::Name () const
return m_game_name.c_str();
}

void CInventoryOwner::SetName(LPCSTR name)
{
m_game_name = name;
}

LPCSTR CInventoryOwner::IconName () const
{
return CharacterInfo().IconName().c_str();
Expand Down
Loading

0 comments on commit 12547f5

Please sign in to comment.