Emergency 20 Dokumentation  4.2.0
EntityHelper.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Header guard ]
6 //[-------------------------------------------------------]
7 #pragma once
8 
9 
10 //[-------------------------------------------------------]
11 //[ Includes ]
12 //[-------------------------------------------------------]
13 #include "em5/Export.h"
15 
17 #include <qsf/base/WeakPtr.h>
18 #include <qsf/map/EntityHelper.h>
19 #include <qsf/time/Time.h>
20 
21 
22 //[-------------------------------------------------------]
23 //[ Forward declarations ]
24 //[-------------------------------------------------------]
25 namespace em5
26 {
27  class FreeplayEvent;
28  class GangsterBaseLogic;
29  class OrderInfo;
30  class RoadVehicleComponent;
31 }
32 namespace qsf
33 {
34  class CameraControlComponent;
35  class Component;
36  class Entity;
37  class GameLogic;
38  class Map;
39  class TransformComponent;
40  namespace game
41  {
42  class EquipmentComponent;
43  class PrototypeContainer;
44  }
45 }
46 
47 
48 //[-------------------------------------------------------]
49 //[ Namespace ]
50 //[-------------------------------------------------------]
51 namespace em5
52 {
53 
54 
55  //[-------------------------------------------------------]
56  //[ Classes ]
57  //[-------------------------------------------------------]
63  {
64 
65 
66  //[-------------------------------------------------------]
67  //[ Public definitions ]
68  //[-------------------------------------------------------]
69  public:
75  enum CarryLoad
76  {
77  CARRY_PERSON = 1, // currently also used for guide person (arresting)
78  PULL_PERSON = 2,
79  PULL_OBJECT = 4,
80 
81  ANY = 7 // adapt to contain all other types
82  };
83 
84 
85  //[-------------------------------------------------------]
86  //[ Public static methods ]
87  //[-------------------------------------------------------]
88  public:
89  static void setupEntityAsGhost(qsf::Entity& entity, uint32 playerIndex);
90  static void setupEntityAsGhost(qsf::Entity& entity, const qsf::Entity& parentEntity);
91  static void teardownEntityAsGhost(qsf::Entity& entity);
92  static bool isPositionVisibleForAnyPlayer(const glm::vec3& entityPosition, float additionalRadius = 0.0f);
93 
94 
95  //[-------------------------------------------------------]
96  //[ Public methods ]
97  //[-------------------------------------------------------]
98  public:
103  inline explicit EntityHelper(qsf::Entity& entity);
104  explicit EntityHelper(const qsf::WeakPtr<qsf::Entity>& entity); // Entity must be valid
105  EntityHelper(uint64 entityId, const qsf::Map& map); // Entity must be valid
106 
111  inline ~EntityHelper();
112 
117  bool isInsideBox(const qsf::TransformComponent& boxTransform, bool yAxisCentered) const;
118  bool isInsideBox(const qsf::Entity& boxEntity) const;
119 
124  bool isInGangsterEventArea() const;
125 
130  bool isEntityDamaged() const;
131 
132  void makeImmovable() const;
133 
138  void setInvincible(bool invincible) const;
139 
147  void applyPlacement(bool warpMovable = false) const;
148 
156  void applyPlacementToPosition(glm::vec3& position) const;
157 
165  void setPositionForMultiplay(glm::vec3& position) const;
166 
167  //[-------------------------------------------------------]
168  //[ Game logic ]
169  //[-------------------------------------------------------]
177  template<typename T>
178  T* getGameLogic() const;
179 
190  qsf::GameLogic* getGameLogicByTypeId(uint32 gameLogicTypeId) const;
191 
202  bool destroyGameLogicByTypeId(uint32 gameLogicTypeId) const;
203 
204  //[-------------------------------------------------------]
205  //[ Events ]
206  //[-------------------------------------------------------]
217  bool isEntityValidEventTarget(FreeplayEvent* freeplayEvent = nullptr) const;
218 
219  //[-------------------------------------------------------]
220  //[ Camera & Visibility ]
221  //[-------------------------------------------------------]
226  bool isEntityHidden() const;
227 
232  bool isEntityVisibleOnScreen(bool includeShadow = true) const;
233 
238  bool isEntityVisibleToCamera(qsf::CameraControlComponent& cameraControlComponent) const;
239 
244  bool isEntityVisibleForAnyPlayer() const;
245 
246  bool isInMapBoundaries() const;
247  bool isInEventBoundaries() const;
248 
249  bool isCloseToMapBoundaries(float tolerance = 1.0f) const;
250  bool isCloseToEventBoundaries(float tolerance = 1.0f) const;
251 
252  //[-------------------------------------------------------]
253  //[ Persons ]
254  //[-------------------------------------------------------]
259  bool isEntityPerson() const;
260 
265  bool isEntityAnimal() const;
266 
271  bool isCivilPerson() const;
272 
277  bool isGangsterPerson() const;
278 
283  bool isGangsterCandidate(GangsterPool gangsterPoolType, bool mustBeInGangsterEventArea = true) const;
284 
290  bool isValidGangsterEventTarget(qsf::Entity& gangsterEntity, bool needsToBeCivilTarget) const;
291 
296  bool isStunned() const;
297 
302  bool isCommandable() const;
303 
308  bool isSquadPerson() const;
309 
314  bool isPersonInjured() const;
315 
320  bool isPersonContaminated() const;
321 
326  bool isPersonWaving() const;
327 
332  bool isPersonBuried() const;
333 
338  bool isCarrying(CarryLoad type = ANY) const;
339 
344  uint64 getCarryTarget(CarryLoad type) const;
345 
350  void clearCarryTarget(CarryLoad type) const;
351 
356  bool isCarryingAnotherPerson() const;
357 
362  bool isGuidingPerson() const;
363 
364  bool isPullingPerson() const;
365 
366  bool isPullingObject() const;
367 
368  bool isCarriedByOtherPerson() const;
369 
370  bool isSquadPersonInValidState() const;
371  bool isSquadVehicleInValidState() const;
372  bool isSquadUnitInValidState() const;
373 
374  bool isCivilPersonInValidState() const;
375 
376  bool isUnitInValidState() const;
377  bool isUnitInValidAndHealthyState() const;
378 
379  bool isBuildingInValidState() const;
380 
381  bool isArrested() const;
382 
383  bool canUseUmbrella() const;
384 
389  bool isRedirectingTraffic() const;
390 
395  void disconnectFromHydrant() const;
396 
401  bool canPlaySelectionFeedback() const;
402 
407  bool canPlayCommandFeedback() const;
408 
409  //[-------------------------------------------------------]
410  //[ Gangster ]
411  //[-------------------------------------------------------]
419  GangsterBaseLogic& turnIntoGangsterByType(const qsf::StringHash& gangsterTypeId) const;
420 
431  GangsterBaseLogic& turnIntoGangster(const qsf::StringHash& gangsterLogicId, bool fleeInCar) const;
432 
437  bool isGangsterFleeing() const;
438 
439  //[-------------------------------------------------------]
440  //[ Building ]
441  //[-------------------------------------------------------]
446  bool isEntityBuilding() const;
447 
452  bool isEntityIndustrialPlant() const;
453 
458  bool isBuildingDamaged() const;
459 
464  bool isBuildingDestroyed() const;
465 
466  void placeEntityAtBuildingDoor(qsf::Entity& buildingEntity, bool lookToDoor = true) const;
467 
468  //[-------------------------------------------------------]
469  //[ Vehicle ]
470  //[-------------------------------------------------------]
475  bool isVehicle() const;
476 
481  bool isHelicopter() const;
482 
487  bool isBoat() const;
488 
493  bool isShip() const;
494 
499  bool isFlying() const;
500 
505  bool isUnit(qsf::NamedIdentifier unitName) const;
506 
507  bool isVehicleDestroyed() const;
508 
509  //[-------------------------------------------------------]
510  //[ Road vehicle ]
511  //[-------------------------------------------------------]
516  bool isRoadVehicle() const;
517 
522  bool isCivilRoadVehicle() const;
523 
528  bool isSquadRoadVehicle() const;
529 
534  bool isSquadVehicle() const;
535 
540  bool isRoadVehicleDamaged() const;
541 
546  bool isGangsterRoadVehicle() const;
547 
558  bool checkVehicleHasFreeSeats(qsf::Entity& vehicleEntity) const;
559  bool checkVehicleHasFreeSeatsForSquadPerson(qsf::Entity& vehicleEntity, OrderInfo& targetVehicleOrderInfo, const std::string& callerUnitName) const;
560  bool checkVehicleHasFreeSeatsForPassengerPerson(qsf::Entity& vehicleEntity, OrderInfo& targetVehicleOrderInfo) const;
561 
562  int countVehicleFreeSeatsForSquadPerson(qsf::Entity& vehicleEntity, OrderInfo& targetVehicleOrderInfo, const std::string& callerUnitName) const;
563  int countVehicleFreeSeatsForPassengerPerson(qsf::Entity& vehicleEntity, OrderInfo& targetVehicleOrderInfo) const;
564 
569  RoadVehicleComponent* getReachableRoadVehicleWithEquipment(const std::string& equipmentName) const;
570 
576  bool hasEquipment(const std::string& equipmentName) const;
577 
578  //[-------------------------------------------------------]
579  //[ Vegetation ]
580  //[-------------------------------------------------------]
585  bool isEntityVegetation() const;
586 
591  bool isEntityTree() const;
592 
593  //[-------------------------------------------------------]
594  //[ Fire ]
595  //[-------------------------------------------------------]
600  bool isBurning() const;
601 
606  bool isBurned() const;
607 
612  bool isBurnable() const;
613 
618  bool canBeSetOnFireNow() const;
619 
632  bool startFire(FreeplayEvent* freeplayEvent = nullptr, bool fullFire = false) const;
633 
641  bool stopFire() const;
642 
654  void setCanBurn(bool canBurn) const;
655 
656  //[-------------------------------------------------------]
657  //[ Container ]
658  //[-------------------------------------------------------]
663  bool isContainerEmpty() const;
664 
669  qsf::Entity* getContainerEntity() const;
670 
675  qsf::Entity& getContainerEntitySafe() const;
676 
681  bool isEntityInBuilding() const;
682 
687  bool isEntityInVehicle() const;
688  bool isEntityInRoadVehicle() const;
689 
690  qsf::game::PrototypeContainer* getPrototypeContainer() const;
691 
692  bool isEntityHardLinked() const;
693  void unlinkFromParent() const;
694 
706  void enterContainer(qsf::Entity& containerEntity, uint32 containerCategory = 0, bool hidden = true) const;
707  void leaveContainer(bool unhide = true) const;
708  bool isInContainer(qsf::Entity& containerEntity, uint32 containerCategory) const;
709  bool isInContainer(qsf::Entity& containerEntity) const;
710 
711  void setCollisionEnabled(bool collision) const;
712 
713  bool isEntityBuried() const;
714 
715  //[-------------------------------------------------------]
716  //[ Cleanup ]
717  //[-------------------------------------------------------]
722  bool isFireReadyToCleanup() const;
723 
728  void cleanupFire() const;
729 
730  //[-------------------------------------------------------]
731  //[ Event tag ]
732  //[-------------------------------------------------------]
733  bool checkEntityHasEventTag(const std::string& tag) const;
734 
735  //[-------------------------------------------------------]
736  //[ Event ID component ]
737  //[-------------------------------------------------------]
742  bool checkForInitializedEventIdComponent(FreeplayEvent* freeplayEvent = nullptr) const;
743 
748  bool checkForEventIdComponent() const;
749 
754  FreeplayEvent* getFreeplayEvent() const;
755 
763  uint32 getFreeplayEventId() const;
764 
765  //[-------------------------------------------------------]
766  //[ Equipment / Inventory ]
767  //[-------------------------------------------------------]
768  qsf::Entity* getActiveEquipmentEntity() const;
769  qsf::game::EquipmentComponent* getActiveEquipmentComponent() const;
770 
775  bool checkIsActiveEquipment(const std::string& equipmentName) const;
776 
777  void storeActiveEquipmentInInventory() const;
778  void storeInventoryEquipmentAsActive() const;
779 
784  void deleteActiveEquipment(qsf::Time timeToDelete = qsf::Time::ZERO) const;
785  void linkEquipmentToEntity(qsf::Entity& parent) const;
786 
798  void showEquipment(const std::string& equipmentPrefab, int forceTintColorIndex = -1) const;
799 
804  void deleteAllLinkedChild();
805 
806  void moveEntityInOwnerLayer(qsf::Entity& entityToMove) const;
807 
808  //[-------------------------------------------------------]
809  //[ Misc ]
810  //[-------------------------------------------------------]
811  uint32 getUnitPlayerIndex() const;
812 
817  bool isUnitFromLocalPlayer() const;
818 
823  bool isUnitOfDifferentPlayer() const;
824 
829  OrderInfo* getOrderInfo() const;
830 
831  void unregisterFromUnitPool() const;
832  void blockFromUnitPool() const;
833 
841  void unregisterOrBlockFromUnitPool(bool unregister) const;
842 
847  qsf::Entity* getParentEntity() const;
848 
853  void enableShineThroughEffect(bool enable = true) const;
854 
859  void setFlareActive(bool active) const;
860 
861  //[-------------------------------------------------------]
862  //[ Lights ]
863  //[-------------------------------------------------------]
871  void setLightActive(bool active) const;
872 
884  qsf::Entity* getClosestEntity(const std::vector<qsf::Entity*>& entities) const;
885 
886  //[-------------------------------------------------------]
887  //[ Fade ]
888  //[-------------------------------------------------------]
893  bool isFading() const;
894 
902  void fadeIn(qsf::Time fadeTime = qsf::Time::fromSeconds(1.0f)) const;
903 
913  void fadeOut(qsf::Time fadeTime = qsf::Time::fromSeconds(1.0f), bool deleteOwner = false) const;
914 
922  void setVisibleAndFade(bool visible, qsf::Time fadeTime = qsf::Time::fromSeconds(1.0f)) const;
923 
924  //[-------------------------------------------------------]
925  //[ Misc ]
926  //[-------------------------------------------------------]
934  void getComponentsFromChildrenById(uint32 componentId, std::vector<qsf::Component*>& output) const;
935 
943  template<typename T> void getComponentsFromChildren(std::vector<T*>& output) const;
944 
949  bool hasEnabledMeshAnimationTestComponent() const;
950 
955  void disableMeshAnimationTestComponent();
956 
957 
958  };
959 
960 
961 //[-------------------------------------------------------]
962 //[ Namespace ]
963 //[-------------------------------------------------------]
964 } // em5
965 
966 
967 //[-------------------------------------------------------]
968 //[ Implementation ]
969 //[-------------------------------------------------------]
Definition: ActionPriority.h:13
EMERGENCY 5 entity helper class.
Definition: EntityHelper.h:62
Entity class.
Definition: Entity.h:46
Map class.
Definition: Map.h:93
Order information.
Definition: OrderInfo.h:54
unsigned int uint32
Definition: PlatformTypes.h:181
Transform component class.
Definition: TransformComponent.h:33
#define EM5_API_EXPORT
Definition: Export.h:28
CarryLoad
Types of load a unit can carry. This is a bitset (not because units can carry more than one but to ch...
Definition: EntityHelper.h:75
Entity helper class.
Definition: EntityHelper.h:52
static const Time ZERO
A zero value for time.
Definition: Time.h:40
uint64_t uint64
Definition: PlatformTypes.h:184
Prototype container base class.
Definition: PrototypeContainer.h:52
Definition: PickupPersonByParamedicAction.h:21
Definition: Direction.h:25
Equipment component class.
Definition: EquipmentComponent.h:37
Base game logic for gangster.
Definition: GangsterBaseLogic.h:52
Game logic base class.
Definition: GameLogic.h:44
static Time fromSeconds(float seconds)
Definition: Time-inl.h:74
EMERGENCY 5 road vehicle component class.
Definition: RoadVehicleComponent.h:54
GangsterPool
Defines pools of gangster prefabs needed for a events. Only prefabs from the resp. pool are picked for new gangster entities.
Definition: GangsterPool.h:22
Class combining strings with their hashes.
Definition: NamedIdentifier.h:34
Abstract EMERGENCY 5 freeplay event base class.
Definition: FreeplayEvent.h:66
Compile time string hash class.
Definition: StringHash.h:59
Camera control component class.
Definition: CameraControlComponent.h:40
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32