DayZ 1.24
Loading...
Searching...
No Matches
ReplaceItemWithNewLambdaBase Class Reference

base class for transformation operations (creating one item from another) More...

Inheritance diagram for ReplaceItemWithNewLambdaBase:
[legend]
Collaboration diagram for ReplaceItemWithNewLambdaBase:
[legend]

Protected Member Functions

bool WantCreateNewEntity ()
 
bool CanExecuteLambda ()
 
bool PrepareLocations ()
 Step A. - prepare inventory locations.
 
void RemoveOldItemFromLocation ()
 Step B. - free location for new item @NOTE this operation does not delete the object, only removes it from inventory location.
 
void UndoRemoveOldItemFromLocation ()
 
void RemoveNetworkObjectInfo ()
 Step C. - remove network part of the object @NOTE this operation does not delete the object, only removes its network part (and deletes it on client)
 
void UndoRemoveNetworkObjectInfo ()
 
EntityAI CreateNewEntity ()
 Step D. - create new entity (LOCAL) with specified type.
 
void CopyOldPropertiesToNew (notnull EntityAI old_item, EntityAI new_item)
 Step E. copy properties from old object to the created one.
 
void DeleteOldEntity ()
 Step F. - deletes physically old item.
 
void CreateNetworkObjectInfo (EntityAI new_item)
 Step G. - create NetworkObjectInfo for new item.
 
void OnSuccess (EntityAI new_item)
 Step H. - notification on finish.
 
void OnAbort ()
 Step Out - notification on abort.
 
void Execute (HumanInventoryWithFSM fsm_to_notify=null)
 
string DumpToString ()
 

Protected Attributes

ref InventoryLocation m_OldLocation
 
ref InventoryLocation m_NewLocation
 
bool m_RemoveFromLocationPassed = false
 

Private Member Functions

void ReplaceItemWithNewLambdaBase (EntityAI old_item, string new_item_type)
 
void OverrideNewLocation (InventoryLocation newLocation)
 
void VerifyItemTypeBySlotType ()
 

Private Attributes

EntityAI m_OldItem
 
string m_NewItemType
 
bool m_RemoveNetworkObjectInfoPassed = false
 

Detailed Description

base class for transformation operations (creating one item from another)

Definition at line 4 of file ReplaceItemWithNewLambdaBase.c.

Constructor & Destructor Documentation

◆ ReplaceItemWithNewLambdaBase()

void ReplaceItemWithNewLambdaBase::ReplaceItemWithNewLambdaBase ( EntityAI old_item,
string new_item_type )
inlineprivate

Member Function Documentation

◆ CanExecuteLambda()

bool ReplaceItemWithNewLambdaBase::CanExecuteLambda ( )
inlineprotected

Definition at line 31 of file ReplaceItemWithNewLambdaBase.c.

32 {
33 if (m_OldItem)
35 //if (WantCreateNewEntity() GameInventory.LocationTestAddEntityType(m_NewItemType, true, true, false, true))
36 return true;
37 return false;
38 }
script counterpart to engine's class Inventory
Definition Inventory.c:79
static proto native bool LocationCanRemoveEntity(notnull InventoryLocation inv_loc)
queries if the entity contained in inv_loc.m_item can be removed from ground/attachment/cargo/hands/....

References GameInventory::LocationCanRemoveEntity(), m_OldItem, and m_OldLocation.

Referenced by Execute().

◆ CopyOldPropertiesToNew()

ReplaceItemWithNewLambdaBase::CopyOldPropertiesToNew ( notnull EntityAI old_item,
EntityAI new_item )
inlineprotected

Step E. copy properties from old object to the created one.

@NOTE: This is supposed to be overriden in derived classes

Definition at line 181 of file ReplaceItemWithNewLambdaBase.c.

182 {
183 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step E) Copying props " + old_item + " --> " + new_item);
184 }
void hndDebugPrint(string s)
Definition HandFSM.c:1
static bool IsInventoryHFSMLogEnable()
Definition Debug.c:749

References hndDebugPrint(), and LogManager::IsInventoryHFSMLogEnable().

Referenced by Execute().

◆ CreateNetworkObjectInfo()

ReplaceItemWithNewLambdaBase::CreateNetworkObjectInfo ( EntityAI new_item)
inlineprotected

Step G. - create NetworkObjectInfo for new item.

@NOTE: new_item can be null if the lambda did not create any item (intentionaly)

Definition at line 200 of file ReplaceItemWithNewLambdaBase.c.

201 {
202 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step G) CreateNetworkObjectInfo =" + new_item);
203 if (new_item)
204 GetGame().RemoteObjectTreeCreate(new_item); // G) this forces server to send CreateVehicle Message to client. This is needed for preserving the appearance of network operations on client (so that DeleteObject(old) arrives before CreateVehicle(new)). @NOTE: this does not delete the object on server, only it's network representation.
205 }
proto native CGame GetGame()

References GetGame(), hndDebugPrint(), and LogManager::IsInventoryHFSMLogEnable().

Referenced by Execute().

◆ CreateNewEntity()

ReplaceItemWithNewLambdaBase::CreateNewEntity ( )
inlineprotected

Step D. - create new entity (LOCAL) with specified type.

@NOTE: if (!m_NewLocation || m_NewItemType.Empty) ==> this function does not create a new entity

Definition at line 121 of file ReplaceItemWithNewLambdaBase.c.

122 {
124 {
127
128 switch (m_NewLocation.GetType())
129 {
130 case InventoryLocationType.GROUND:
132 string path = "" + CFG_VEHICLESPATH + " " + m_NewItemType + " inherit_rotation";
133 bool keep_rotation = GetGame().ConfigIsExisting(path) && GetGame().ConfigGetInt(path) > 0;
134 if (keep_rotation)
135 {
136 new_item.SetOrientation(m_OldItem.GetOrientation()); //this one actually works...debug InventoryLocation
137 }
138 break;
139 case InventoryLocationType.ATTACHMENT:
140 // forces rawlocation in C++ to make location Valid
141 m_NewLocation.SetAttachment(m_NewLocation.GetParent(), null, m_NewLocation.GetSlot());
143 break;
144 default:
146 break;
147 }
148
149 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step D) Created new new_item=" + new_item);
150 if (new_item)
151 return new_item;
152 else
153 {
154 return null;
155
156 /*InventoryLocation backupLocation = new InventoryLocation;
157 vector mtx[4];
158 Math3D.MatrixIdentity4(mtx);
159 mtx[3] = m_OldItem.GetPosition();
160 backupLocation.SetGround(null, mtx);
161 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step D) plan B - creating=" + m_NewItemType + " at bkp loc=" + backupLocation.DumpToString() + ", but failed");
162 new_item = GameInventory.LocationCreateLocalEntity(backupLocation, m_NewItemType,ECE_OBJECT_SWAP,RF_NONE); // create LOCAL new one on ground
163 if (!new_item)
164 {
165 Error("[inv] ReplaceItemWithNewLambdaBase Step D) plan B - wanted to create=" + m_NewItemType + " at bkp loc=" + backupLocation.DumpToString() + ", but failed");
166 return null;
167 }
168 return new_item;*/
169 }
170 }
171
172 // user did not asked for new entity
173 return null;
174 }
const int RF_NONE
const int ECE_OBJECT_SWAP
const int ECE_LOCAL
const int ECE_PLACE_ON_SURFACE
InventoryLocationType
types of Inventory Location
static proto native EntityAI LocationCreateLocalEntity(notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation)
creates new local item directly at location @NOTE: the item is created localy, i.e....
static proto native EntityAI LocationCreateEntity(notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation)
creates new item directly at location
const string CFG_VEHICLESPATH
Definition constants.c:209

References CFG_VEHICLESPATH, ECE_LOCAL, ECE_OBJECT_SWAP, ECE_PLACE_ON_SURFACE, GetGame(), hndDebugPrint(), LogManager::IsInventoryHFSMLogEnable(), GameInventory::LocationCreateEntity(), GameInventory::LocationCreateLocalEntity(), m_NewItemType, m_NewLocation, m_OldItem, path, RF_NONE, VerifyItemTypeBySlotType(), and WantCreateNewEntity().

Referenced by Execute().

◆ DeleteOldEntity()

ReplaceItemWithNewLambdaBase::DeleteOldEntity ( )
inlineprotected

Step F. - deletes physically old item.

Definition at line 189 of file ReplaceItemWithNewLambdaBase.c.

190 {
191 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step F) delete old item=" + m_OldItem);
192 m_OldItem.DeleteSafe();
193 }

References hndDebugPrint(), LogManager::IsInventoryHFSMLogEnable(), and m_OldItem.

Referenced by Execute().

◆ DumpToString()

string ReplaceItemWithNewLambdaBase::DumpToString ( )
inlineprotected

Definition at line 294 of file ReplaceItemWithNewLambdaBase.c.

295 {
296 string s = "{ old=" + m_OldItem + " newType=" + m_NewItemType + "}";
297 return s;
298 }

References m_NewItemType, and m_OldItem.

◆ Execute()

void ReplaceItemWithNewLambdaBase::Execute ( HumanInventoryWithFSM fsm_to_notify = null)
inlineprotected

Definition at line 227 of file ReplaceItemWithNewLambdaBase.c.

228 {
229 int t = GetGame().GetTime();
230 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[syncinv] t=" + t + " lambda.Execute start ");
231
232 // A) init
233 bool prepared = PrepareLocations();
234
235 if (prepared && CanExecuteLambda())
236 {
237 // B) rm old (and delete on client)
240 {
241 Error("[inv] ReplaceItemWithNewLambdaBase Step B) ABORT - failed while rm old item from loc=" + InventoryLocation.DumpToStringNullSafe(m_OldLocation));
242
243 if (fsm_to_notify)
244 fsm_to_notify.ProcessHandAbortEvent(new HandEventHumanCommandActionAborted(fsm_to_notify.GetManOwner()));
245 OnAbort();
246 return;
247 }
248
249 // C) rm NetworkObjectInfo from old item (+ send delete object tree to clients)
251
252 // D) mk new in place of old
255 {
256 //Error("[inv] ReplaceItemWithNewLambdaBase Step D) ABORT - wanted to create=" + m_NewItemType + " at loc=" + m_NewLocation.DumpToString() + ", but failed");
257 Print("Error [inv] ReplaceItemWithNewLambdaBase Step D) ABORT - wanted to create=" + m_NewItemType + " at loc=" + InventoryLocation.DumpToStringNullSafe(m_NewLocation) + ", but failed");
262
263 OnAbort();
264 if (fsm_to_notify)
265 fsm_to_notify.ProcessHandAbortEvent(new HandEventHumanCommandActionAborted(fsm_to_notify.GetManOwner()));
266 return;
267 }
268
269 // E) cpy props
271
272 // F) del old
274
275 // G) mk new NetworkObjectInfo
277
278 // H) notification
280 }
281 else
282 {
283 Print("[syncinv] warning, lambda cannot be executed, skipping!");
284 if (fsm_to_notify)
285 fsm_to_notify.ProcessHandAbortEvent(new HandEventHumanCommandActionAborted(fsm_to_notify.GetManOwner()));
286 OnAbort();
287 return;
288 }
289 int te = GetGame().GetTime();
290 int dt = te - t;
291 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[syncinv] te=" + te + " lambda.Execute end, exec time=" + dt);
292 }
InventoryLocation.
static string DumpToStringNullSafe(InventoryLocation loc)
void RemoveOldItemFromLocation()
Step B. - free location for new item @NOTE this operation does not delete the object,...
void OnSuccess(EntityAI new_item)
Step H. - notification on finish.
void DeleteOldEntity()
Step F. - deletes physically old item.
void RemoveNetworkObjectInfo()
Step C. - remove network part of the object @NOTE this operation does not delete the object,...
bool PrepareLocations()
Step A. - prepare inventory locations.
EntityAI CreateNewEntity()
Step D. - create new entity (LOCAL) with specified type.
void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
Step E. copy properties from old object to the created one.
void OnAbort()
Step Out - notification on abort.
void CreateNetworkObjectInfo(EntityAI new_item)
Step G. - create NetworkObjectInfo for new item.
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
proto void Print(void var)
Prints content of variable to console/log.

References CanExecuteLambda(), CopyOldPropertiesToNew(), CreateNetworkObjectInfo(), CreateNewEntity(), DeleteOldEntity(), InventoryLocation::DumpToStringNullSafe(), Error(), GetGame(), hndDebugPrint(), LogManager::IsInventoryHFSMLogEnable(), m_NewItemType, m_NewLocation, m_OldItem, m_OldLocation, m_RemoveFromLocationPassed, m_RemoveNetworkObjectInfoPassed, OnAbort(), OnSuccess(), PrepareLocations(), Print(), RemoveNetworkObjectInfo(), RemoveOldItemFromLocation(), UndoRemoveNetworkObjectInfo(), UndoRemoveOldItemFromLocation(), and WantCreateNewEntity().

◆ OnAbort()

ReplaceItemWithNewLambdaBase::OnAbort ( )
inlineprotected

Step Out - notification on abort.

@NOTE: new_item can be null if the lambda did not create any item (intentionaly)

Definition at line 222 of file ReplaceItemWithNewLambdaBase.c.

223 {
224 Print("Error [inv] ReplaceItemWithNewLambdaBase OnAbort");
225 }

References Print().

Referenced by Execute().

◆ OnSuccess()

ReplaceItemWithNewLambdaBase::OnSuccess ( EntityAI new_item)
inlineprotected

Step H. - notification on finish.

@NOTE: new_item can be null if the lambda did not create any item (intentionaly)

Definition at line 212 of file ReplaceItemWithNewLambdaBase.c.

213 {
214 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step H) OnSuccess=" + new_item);
215 }

References hndDebugPrint(), and LogManager::IsInventoryHFSMLogEnable().

Referenced by Execute().

◆ OverrideNewLocation()

void ReplaceItemWithNewLambdaBase::OverrideNewLocation ( InventoryLocation newLocation)
inlineprivate

Definition at line 19 of file ReplaceItemWithNewLambdaBase.c.

20 {
22 }

References m_NewLocation.

◆ PrepareLocations()

ReplaceItemWithNewLambdaBase::PrepareLocations ( )
inlineprotected

Step A. - prepare inventory locations.

Definition at line 43 of file ReplaceItemWithNewLambdaBase.c.

44 {
45 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step A) Prepare inventory locations, old_item=" + m_OldItem);
47 if (m_OldItem.GetInventory().GetCurrentInventoryLocation(m_OldLocation)) // A.1) store old location
48 {
49 if (m_NewLocation == null)
50 {
52 m_NewLocation.CopyLocationFrom(m_OldLocation, true); // A.2) prepare new location from old
53
54 //setting proper location type for ground pos
55 if (!m_NewLocation.GetParent())
56 {
57 vector m4[4];
59 m4[3] = m_NewLocation.GetPos();
60 string path = "" + CFG_VEHICLESPATH + " " + m_NewItemType + " inherit_rotation";
61 bool keep_rotation = GetGame().ConfigIsExisting(path) && GetGame().ConfigGetInt(path) > 0;
62
63 if (m_OldLocation.GetType() == InventoryLocationType.GROUND && keep_rotation)
64 {
65 float dir[4];
66 m_OldLocation.GetDir(dir);
67 m_NewLocation.SetGroundEx(null, m_NewLocation.GetPos(), dir);
68 }
69 else
70 m_NewLocation.SetGround(null, m4);
71 }
72 }
73 return true;
74 }
75 else
76 Error("[inv] ReplaceItemWithNewLambdaBase Step A.1) failed to get old_item inventory location");
77 return false;
78 }
static void MatrixIdentity4(out vector mat[4])
Creates identity matrix.
Definition EnMath3D.c:233

References CFG_VEHICLESPATH, Error(), GetGame(), hndDebugPrint(), LogManager::IsInventoryHFSMLogEnable(), m_NewItemType, m_NewLocation, m_OldItem, m_OldLocation, Math3D::MatrixIdentity4(), and path.

Referenced by Execute().

◆ RemoveNetworkObjectInfo()

ReplaceItemWithNewLambdaBase::RemoveNetworkObjectInfo ( )
inlineprotected

Step C. - remove network part of the object @NOTE this operation does not delete the object, only removes its network part (and deletes it on client)

Definition at line 105 of file ReplaceItemWithNewLambdaBase.c.

106 {
107 GetGame().RemoteObjectTreeDelete(m_OldItem); // C) this forces server to send DeleteObject Message to client. This is needed for preserving the appearance of network operations on client (so that DeleteObject(old) arrives before CreateVehicle(new)). @NOTE: this does not delete the object on server, only it's network representation.
108 // @NOTE: the item is not deleted right now on server, but rather after copying the properties in Step E)
110 }

References GetGame(), m_OldItem, and m_RemoveNetworkObjectInfoPassed.

Referenced by Execute().

◆ RemoveOldItemFromLocation()

ReplaceItemWithNewLambdaBase::RemoveOldItemFromLocation ( )
inlineprotected

Step B. - free location for new item @NOTE this operation does not delete the object, only removes it from inventory location.

Definition at line 84 of file ReplaceItemWithNewLambdaBase.c.

85 {
86 if (!GameInventory.LocationRemoveEntity(m_OldLocation)) // B) remove entity from old inventory location (making it free for new item)
87 {
88 Error("[inv] ReplaceItemWithNewLambdaBase Step B) failed to remove old_item rom current inventory location");
90 }
91 Print("[inv] ReplaceItemWithNewLambdaBase Step B) remove OK, loc=" + InventoryLocation.DumpToStringNullSafe(m_OldLocation));
93 }
static proto native bool LocationRemoveEntity(notnull InventoryLocation inv_loc)
removes item from inventory location

References InventoryLocation::DumpToStringNullSafe(), Error(), GameInventory::LocationRemoveEntity(), m_OldLocation, m_RemoveFromLocationPassed, and Print().

Referenced by Execute().

◆ UndoRemoveNetworkObjectInfo()

void ReplaceItemWithNewLambdaBase::UndoRemoveNetworkObjectInfo ( )
inlineprotected

Definition at line 111 of file ReplaceItemWithNewLambdaBase.c.

112 {
113 GetGame().RemoteObjectTreeCreate(m_OldItem);
114 }

References GetGame(), and m_OldItem.

Referenced by Execute().

◆ UndoRemoveOldItemFromLocation()

void ReplaceItemWithNewLambdaBase::UndoRemoveOldItemFromLocation ( )
inlineprotected

Definition at line 94 of file ReplaceItemWithNewLambdaBase.c.

95 {
97 Error("[inv] ReplaceItemWithNewLambdaBase Step B) failed to undo remove");
98 Print("[inv] ReplaceItemWithNewLambdaBase Step B) undo remove OK, loc=" + InventoryLocation.DumpToStringNullSafe(m_OldLocation));
99 }
static proto native bool LocationAddEntity(notnull InventoryLocation inv_loc)
adds item to inventory location

References InventoryLocation::DumpToStringNullSafe(), Error(), GameInventory::LocationAddEntity(), m_OldLocation, and Print().

Referenced by Execute().

◆ VerifyItemTypeBySlotType()

void ReplaceItemWithNewLambdaBase::VerifyItemTypeBySlotType ( )
inlineprivate

Definition at line 24 of file ReplaceItemWithNewLambdaBase.c.

24{}

Referenced by CreateNewEntity().

◆ WantCreateNewEntity()

bool ReplaceItemWithNewLambdaBase::WantCreateNewEntity ( )
inlineprotected

Definition at line 26 of file ReplaceItemWithNewLambdaBase.c.

27 {
28 return m_NewLocation && m_NewItemType != string.Empty;
29 }
static const string Empty
Definition EnString.c:7

References string::Empty, m_NewItemType, and m_NewLocation.

Referenced by CreateNewEntity(), and Execute().

Member Data Documentation

◆ m_NewItemType

◆ m_NewLocation

◆ m_OldItem

◆ m_OldLocation

ref InventoryLocation ReplaceItemWithNewLambdaBase::m_OldLocation
protected

◆ m_RemoveFromLocationPassed

bool ReplaceItemWithNewLambdaBase::m_RemoveFromLocationPassed = false
protected

Definition at line 10 of file ReplaceItemWithNewLambdaBase.c.

Referenced by Execute(), and RemoveOldItemFromLocation().

◆ m_RemoveNetworkObjectInfoPassed

bool ReplaceItemWithNewLambdaBase::m_RemoveNetworkObjectInfoPassed = false
private

Definition at line 11 of file ReplaceItemWithNewLambdaBase.c.

Referenced by Execute(), and RemoveNetworkObjectInfo().


The documentation for this class was generated from the following file: