MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / CreateObject

Method CreateObject

engine/Poseidon/AI/AIUnit.cpp:980–1043  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

978}
979
980AIUnit* AIUnit::CreateObject(NetworkMessageContext& ctx)
981{
982 AI_ERROR(dynamic_cast<const IndicesCreateAIUnit*>(ctx.GetIndices()))
983 const IndicesCreateAIUnit* indices = static_cast<const IndicesCreateAIUnit*>(ctx.GetIndices());
984
985 Person* person;
986 if (ctx.IdxTransferRef(indices->person, person) != TMOK)
987 {
988 return nullptr;
989 }
990 if (!person)
991 {
992 return nullptr;
993 }
994 AISubgroup* subgrp;
995 if (ctx.IdxTransferRef(indices->subgroup, subgrp) != TMOK)
996 {
997 return nullptr;
998 }
999 if (!subgrp)
1000 {
1001 return nullptr;
1002 }
1003 AIGroup* grp = subgrp->GetGroup();
1004 if (!grp)
1005 {
1006 return nullptr;
1007 }
1008 int id;
1009 if (ctx.IdxTransfer(indices->id, id) != TMOK)
1010 {
1011 return nullptr;
1012 }
1013 AIUnit* unit = person->Brain();
1014 unit->_id = id;
1015 grp->SetUnit(id - 1, unit);
1016 subgrp->AddUnit(unit);
1017
1018 // temporary select leader (avoid diag output)
1019 if (!grp->Leader())
1020 {
1021 grp->GetCenter()->SelectLeader(grp);
1022 }
1023 if (!subgrp->Leader())
1024 {
1025 subgrp->SelectLeader();
1026 }
1027
1028 NetworkId objectId;
1029 if (ctx.IdxTransfer(indices->objectCreator, objectId.creator) != TMOK)
1030 {
1031 return nullptr;
1032 }
1033 if (ctx.IdxTransfer(indices->objectId, objectId.id) != TMOK)
1034 {
1035 return nullptr;
1036 }
1037 unit->SetNetworkId(objectId);

Callers 2

ProcessJoinGroupsFunction · 0.45
IssueCommandMethod · 0.45

Calls 13

IdxTransferRefMethod · 0.80
BrainMethod · 0.80
SetUnitMethod · 0.80
GetIndicesMethod · 0.45
GetGroupMethod · 0.45
IdxTransferMethod · 0.45
AddUnitMethod · 0.45
LeaderMethod · 0.45
SelectLeaderMethod · 0.45
GetCenterMethod · 0.45
SetNetworkIdMethod · 0.45
SetLocalMethod · 0.45

Tested by

no test coverage detected