Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_TransportUnitComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Misc", description: "")]
5
6void OnTransportUnitVehicleChangedDelegate(Vehicle currentVehicle, Vehicle previousVehicle);
8typedef ScriptInvokerBase<OnTransportUnitVehicleChangedDelegate> OnTransportUnitVehicleChangedInvoker;
9
11{
12 [Attribute(desc: "Name of the source base entity used to set source base. If empty, the base is not set.")]
13 protected string m_sSourceBaseEntityName;
14
15 [Attribute("100", desc: "Radius in meters within which the unit is searching for the vehicle.", params: "0 inf")]
16 protected float m_fSearchTruckRadius;
17
18 [Attribute("0", desc: "Should the transport group be teleported into the vehicle just before the task solving?")]
20
21 [Attribute("#AR-SuppliesTransportSystem_TransportGroup_NoDestination", desc: "Localization key for cases where the transport group has no destination.")]
23
24 [Attribute("{349C8E58C5ACAF4D}Prefabs/Tasks/TransportUnitHelpTaskEntity.et", desc: "Task to be created if the transport unit fails to deliver supplies.", params: "et")]
26
27 [RplProp()]
29
30 [RplProp(onRplName: "OnSourceBaseCallsignSet")]
31 protected int m_iSourceBaseCallsign = SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN;
32
33 [RplProp(onRplName: "OnDestinationCallsignSet")]
34 protected int m_iSuppliedBaseCallsign = SCR_CampaignMilitaryBaseComponent.INVALID_BASE_CALLSIGN;
35
36 [RplProp()]
37 protected RplId m_VehicleRplId = RplId.Invalid();
38
39 [RplProp(onRplName: "OnPreferableResupplyTaskSet")]
41
42 [RplProp(onRplName: "OnVehicleAggregatedResourceValueSet")]
44
45 [RplProp(onRplName: "OnIsVehicleUsableSet")]
46 protected bool m_bIsVehicleUsable;
47
48 [RplProp()]
50
52
53 protected SCR_ResupplyCampaignMilitaryBaseTaskEntity m_PreferableResupplyTask;
54
55 protected ref set<Vehicle> m_NearbySupplyTrucks = new set<Vehicle>();
56
58
59 protected SCR_TaskSolverManagerComponent m_TaskSolverManager;
60
62
64
65 protected Vehicle m_Vehicle;
66
68
70
72
74
76
78 protected SCR_TransportUnitHelpTaskEntity m_TransportUnitHelpTaskEntity;
79
82
87
88 protected static int s_iLastGeneratedTaskId;
89
90 protected static const string TRANSPORT_UNIT_HELP_TASK_ID = "%1_TransportUnitHelpTask_%2";
91
92 //------------------------------------------------------------------------------------------------
100
101 //------------------------------------------------------------------------------------------------
109
110 //------------------------------------------------------------------------------------------------
118
119 //------------------------------------------------------------------------------------------------
127
128 //------------------------------------------------------------------------------------------------
130 {
131 if (!m_AIGroup)
132 return null;
133
134 return m_AIGroup.GetFaction();
135 }
136
137 //------------------------------------------------------------------------------------------------
142
143 //------------------------------------------------------------------------------------------------
144 string GetName()
145 {
146 return m_AIGroup.GetCustomNameWithOriginal();
147 }
148
149 //------------------------------------------------------------------------------------------------
154
155 //------------------------------------------------------------------------------------------------
157 {
158 if (m_SourceBase && m_TaskSolver.GetResupplyTaskSolverState() == SCR_EResupplyTaskSolverState.MOVING_TO_SOURCE_BASE)
159 return m_SourceBase.GetCallsignDisplayName();
160
161 if (m_SuppliedBase && m_TaskSolver.GetResupplyTaskSolverState() == SCR_EResupplyTaskSolverState.MOVING_TO_SUPPLIED_BASE)
162 return m_SuppliedBase.GetCallsignDisplayName();
163
165 }
166
167 //------------------------------------------------------------------------------------------------
169 {
170 if (m_SourceBase == sourceBase)
171 return;
172
173 m_SourceBase = sourceBase;
174 if (m_SourceBase)
175 m_iSourceBaseCallsign = m_SourceBase.GetCallsign();
176 else
178 m_TaskSolver.SetSourceBase(m_SourceBase);
179
180 Replication.BumpMe();
181 }
182
183 //------------------------------------------------------------------------------------------------
185 {
186 if (m_SuppliedBase == suppliedBase)
187 return;
188
189 m_SuppliedBase = suppliedBase;
190 if (m_SuppliedBase)
192 else
194
195 Replication.BumpMe();
196 }
197
198 //------------------------------------------------------------------------------------------------
199 void SelectForTaskSolving(SCR_ResupplyCampaignMilitaryBaseTaskEntity task)
200 {
202 m_TaskSolverManager.StartSolverTask(m_TaskSolver, task, resupplyTaskContext);
203
204 SetTruckFuel(0.75);
205
207
209 {
211 }
212 }
213
214 //------------------------------------------------------------------------------------------------
216 {
217 return m_VehicleRplId.IsValid();
218 }
219
220 //------------------------------------------------------------------------------------------------
225
226 //------------------------------------------------------------------------------------------------
228 {
229 return m_Vehicle;
230 }
231
232 //------------------------------------------------------------------------------------------------
234 {
235 return m_bIsVehicleUsable;
236 }
237
238 //------------------------------------------------------------------------------------------------
243
244 //------------------------------------------------------------------------------------------------
246 {
247 return m_AIGroup;
248 }
249
250 //------------------------------------------------------------------------------------------------
252 {
253 return m_eState;
254 }
255
256 //------------------------------------------------------------------------------------------------
258 {
259 return m_TaskSolver.GetResupplyTaskSolverState();
260 }
261
262 //------------------------------------------------------------------------------------------------
264 {
265 if (!m_SourceBase)
266 return false;
267
269 return false;
270
271 if (!m_VehicleConditionManager.IsVehicleUsable(m_Vehicle))
272 return false;
273
274 if (GetState() == SCR_ETransportUnitState.ON_TASK)
275 return false;
276
277 return true;
278 }
279
280 //------------------------------------------------------------------------------------------------
281 void Update(float timeSlice)
282 {
283 m_TaskSolver.Update(timeSlice);
284
285 if (GetState() != SCR_ETransportUnitState.ON_TASK)
286 {
289 SetSuppliedBase(m_PreferableResupplyTask.GetMilitaryBase());
290
291 if (!m_Vehicle || !m_VehicleConditionManager.IsVehicleUsable(m_Vehicle))
292 {
294 }
295 }
296
297 SCR_ETransportUnitState previousState = GetState();
298 UpdateState();
299 }
300
301 //------------------------------------------------------------------------------------------------
303 {
304 if (m_eState != SCR_ETransportUnitState.INACTIVE || m_TaskSolver.GetResupplyTaskSolverState() != SCR_EResupplyTaskSolverState.INACTIVE)
305 return;
306
308 return;
309
310 if (!m_VehicleConditionManager.IsVehicleUsable(m_Vehicle))
311 return;
312
313 if (m_SuppliesTransportSystem.IsVehicleBoarded(m_Vehicle, this))
314 return;
315
316 float sourceBaseRadius = m_SourceBase.GetRadius();
317 bool isCloseToSourceBase = vector.DistanceSq(m_SourceBase.GetOwner().GetOrigin(), m_Vehicle.GetOrigin()) <= (sourceBaseRadius * sourceBaseRadius);
318 if (isCloseToSourceBase)
319 return;
320
321 m_TaskSolver.SetVehicle(m_Vehicle);
322 m_TaskSolver.SetSourceBase(m_SourceBase);
323
324 m_AIGroup.CompleteAllWaypoints();
325
326 if (m_AiVehicleUsage.IsOccupiedByGroup(m_AIGroup))
327 {
329 }
330 else
331 {
334 return;
335
336 m_AIGroup.GetOnWaypointCompleted().Insert(OnBoardingCompleted);
337 }
338 }
339
340 //------------------------------------------------------------------------------------------------
341 protected void OnBoardingCompleted(AIWaypoint waypoint)
342 {
343 if (!waypoint || waypoint != m_BoardingWaypoint)
344 return;
345
346 m_AIGroup.GetOnWaypointCompleted().Remove(OnBoardingCompleted);
347
349 return;
350
351 if (m_AiVehicleUsage.IsOccupiedByGroup(m_AIGroup))
353 }
354
355 //------------------------------------------------------------------------------------------------
356 protected void OnMoveToSourceBaseWaypointCompleted(AIWaypoint waypoint)
357 {
358 if (!waypoint || waypoint != m_MoveToSourceBaseWaypoint)
359 return;
360
361 m_AIGroup.GetOnWaypointCompleted().Remove(OnMoveToSourceBaseWaypointCompleted);
362
363 m_TaskSolver.ResetToInitialState();
364 }
365
366 //------------------------------------------------------------------------------------------------
367 protected static int GenerateTaskID()
368 {
369 return s_iLastGeneratedTaskId++;
370 }
371
372 //------------------------------------------------------------------------------------------------
373 protected void TeleportGroupToVehicle()
374 {
375 if (!m_Vehicle)
376 return;
377
378 array<AIAgent> agents = {};
379 m_AIGroup.GetAgents(agents);
380 SCR_CompartmentAccessComponent compartmentAccess;
381 foreach (AIAgent agent : agents)
382 {
383 compartmentAccess = SCR_CompartmentAccessComponent.Cast(agent.GetControlledEntity().FindComponent(SCR_CompartmentAccessComponent));
384 if (!compartmentAccess)
385 continue;
386
387 compartmentAccess.MoveInVehicleAny(m_Vehicle);
388 }
389 }
390
391 //------------------------------------------------------------------------------------------------
394 {
395 m_PreferableResupplyTask = SCR_ResupplyCampaignMilitaryBaseTaskEntity.Cast(Replication.FindItem(m_PreferableResupplyTaskRplId));
396 }
397
398 //------------------------------------------------------------------------------------------------
399 protected void SetPreferableResupplyTask(SCR_ResupplyCampaignMilitaryBaseTaskEntity preferableTask)
400 {
401 if (m_PreferableResupplyTask == preferableTask)
402 return;
403
404 m_PreferableResupplyTask = preferableTask;
405
407 Replication.BumpMe();
408 }
409
410 //------------------------------------------------------------------------------------------------
411 protected void SetTruckFuel(float percentage)
412 {
413 if (!m_FuelManager)
414 return;
415
416 m_FuelManager.SetTotalFuelPercentage(percentage);
417 }
418
419 //------------------------------------------------------------------------------------------------
420 protected void OnVehicleDeleted(SCR_AIVehicleUsageComponent vehicleUsageComponent)
421 {
422 SetVehicle(null);
423 }
424
425 //------------------------------------------------------------------------------------------------
431
432 //------------------------------------------------------------------------------------------------
433 protected void OnVehicleResourceValueChanged(SCR_ResourceInteractor interactor, float previousValue)
434 {
435 if (!interactor)
436 return;
437
438 m_fVehicleAggregatedResourceValue = interactor.GetAggregatedResourceValue();
439 Replication.BumpMe();
440
443 }
444
445 //------------------------------------------------------------------------------------------------
446 protected SCR_ResourceConsumer GetVehicleSuppliesConsumer(Vehicle vehicle)
447 {
448 SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.FindResourceComponent(vehicle);
449 if (!resourceComponent)
450 return null;
451
452 return resourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_UNLOAD, EResourceType.SUPPLIES);
453 }
454
455 //------------------------------------------------------------------------------------------------
456 protected void SetVehicle(Vehicle vehicle)
457 {
458 if (vehicle == m_Vehicle)
459 return;
460
461 if (m_Vehicle)
462 {
464
466 m_AiVehicleUsage.GetOnDeleted().Remove(OnVehicleDeleted);
467
468 SCR_ResourceConsumer consumer = GetVehicleSuppliesConsumer(m_Vehicle);
469 if (consumer)
470 consumer.GetOnResourcesChanged().Remove(OnVehicleResourceValueChanged);
471 }
472
473 Vehicle previousVehicle = m_Vehicle;
474 m_Vehicle = vehicle;
477
478 if (m_Vehicle)
479 {
484 m_AiVehicleUsage.GetOnDeleted().Insert(OnVehicleDeleted);
485
486 SCR_ResourceConsumer consumer = GetVehicleSuppliesConsumer(vehicle);
487 if (consumer)
488 {
489 m_fVehicleAggregatedResourceValue = consumer.GetAggregatedResourceValue();
490 consumer.GetOnResourcesChanged().Insert(OnVehicleResourceValueChanged);
491 }
492 }
493 else
494 {
496 m_FuelManager = null;
497 m_AiVehicleUsage = null;
498 }
499
500 Replication.BumpMe();
501
503 m_OnVehicleChanged.Invoke(vehicle, previousVehicle);
504 }
505
506 //------------------------------------------------------------------------------------------------
507 protected void UpdateGarbageBlacklist(notnull Vehicle vehicle, bool blacklisted)
508 {
509 SCR_GameModeCampaign gameMode = SCR_GameModeCampaign.GetInstance();
510 if (gameMode && gameMode.IsProxy())
511 return;
512
513 if (m_SuppliesTransportSystem.IsVehicleSelected(vehicle, this))
514 return;
515
517 if (!garbageSystem)
518 return;
519
520 garbageSystem.UpdateBlacklist(vehicle, blacklisted);
521 }
522
523 //------------------------------------------------------------------------------------------------
524 protected void SetState(SCR_ETransportUnitState state)
525 {
526 if (m_eState == state)
527 return;
528
529 m_eState = state;
530 Replication.BumpMe();
531
534 }
535
536 //------------------------------------------------------------------------------------------------
537 SCR_ResupplyCampaignMilitaryBaseTaskEntity GetPreferableResupplyTask()
538 {
540 }
541
542 //------------------------------------------------------------------------------------------------
544 protected void OnSourceBaseCallsignSet()
545 {
546 SCR_CampaignMilitaryBaseManager baseManager = SCR_GameModeCampaign.GetInstance().GetBaseManager();
548 if (base == m_SourceBase)
549 return;
550
552 }
553
554 //------------------------------------------------------------------------------------------------
556 {
557 SCR_CampaignMilitaryBaseManager baseManager = SCR_GameModeCampaign.GetInstance().GetBaseManager();
559 if (suppliedBase == m_SuppliedBase)
560 return;
561
562 m_SuppliedBase = suppliedBase;
563 }
564
565 //------------------------------------------------------------------------------------------------
566 protected void UpdateState()
567 {
568 if (!m_AiGroupConditionManager.IsAIGroupAvailable(m_AIGroup))
569 {
571 return;
572 }
573
575 {
577 return;
578 }
579 }
580
581 //------------------------------------------------------------------------------------------------
582 protected void OnResupplyTaskSolverStateChanged(int solverId, SCR_EResupplyTaskSolverState resupplyTaskSolverState)
583 {
585 m_OnResupplyTaskSolverStateChanged.Invoke(resupplyTaskSolverState);
586 }
587
588 //------------------------------------------------------------------------------------------------
589 protected void OnTaskSolverStateChanged(SCR_TaskSolverBase taskSolver, SCR_ETaskSolverState taskSolverState)
590 {
591 if (taskSolverState == SCR_ETaskSolverState.FAILED || taskSolverState == SCR_ETaskSolverState.COMPLETED)
592 {
594 UpdateState();
595
596 if (taskSolverState == SCR_ETaskSolverState.FAILED)
597 {
599 }
600 }
601 }
602
603 //------------------------------------------------------------------------------------------------
605 {
606 if (m_eState != SCR_ETransportUnitState.INACTIVE)
607 return;
608
609 m_MoveToSourceBaseWaypoint = m_TaskSolver.CreateMoveWaypointToSourceBase();
611 return;
612
613 m_AIGroup.GetOnWaypointCompleted().Insert(OnMoveToSourceBaseWaypointCompleted);
614 }
615
616 //------------------------------------------------------------------------------------------------
618 {
619 if (m_eState != SCR_ETransportUnitState.INACTIVE)
620 return null;
621
622 return m_TaskSolver.CreateBoardingVehicleWaypoint();
623 }
624
625 //------------------------------------------------------------------------------------------------
626 protected SCR_TransportUnitHelpTaskEntity CreateTransportUnitHelpTask()
627 {
628 if (!m_TaskSystem)
629 return null;
630
631 SCR_Faction faction = SCR_Faction.Cast(GetFaction());
632 if (!faction || !faction.IsPlayable())
633 return null;
634
635 SCR_GroupTaskManagerComponent groupTaskManager = SCR_GroupTaskManagerComponent.GetInstance();
636 if (!groupTaskManager || !groupTaskManager.CanCreateNewTaskWithResourceName(m_sTransportUnitHelpTask, faction))
637 return null;
638
639 if (HasTransportUnitHelpTask(faction))
640 return null;
641
642 string taskId = string.Format(TRANSPORT_UNIT_HELP_TASK_ID, faction.GetFactionKey(), GenerateTaskID());
643 SCR_Task task = m_TaskSystem.CreateTask(m_sTransportUnitHelpTask, taskId, "", "", m_AIGroup.GetOrigin());
644 if (!task)
645 {
646 Print("Task was not created", LogLevel.ERROR);
647 return null;
648 }
649
650 m_TaskSystem.SetTaskOwnership(task, SCR_ETaskOwnership.EXECUTOR);
651 m_TaskSystem.SetTaskVisibility(task, SCR_ETaskVisibility.GROUP);
652 m_TaskSystem.AddTaskFaction(task, faction.GetFactionKey());
653
654 groupTaskManager.SetGroupTask(task, 0);
655
656 SCR_TransportUnitHelpTaskEntity transportUnitHelpTask = SCR_TransportUnitHelpTaskEntity.Cast(task);
657 if (!transportUnitHelpTask)
658 return null;
659
660 transportUnitHelpTask.SetTransportUnit(this);
661
662 return transportUnitHelpTask;
663 }
664
665 //------------------------------------------------------------------------------------------------
666 protected bool HasTransportUnitHelpTask(notnull SCR_Faction faction)
667 {
668 array<SCR_Task> tasks = {};
669 SCR_TaskSystem.GetInstance().GetTasksByStateFiltered(
670 tasks,
671 SCR_ETaskState.CREATED | SCR_ETaskState.ASSIGNED,
672 faction.GetFactionKey(),
673 -1,
674 SCR_TransportUnitHelpTaskEntity
675 );
676
677 foreach (SCR_Task theTask : tasks)
678 {
679 SCR_TransportUnitHelpTaskEntity transportUnitHelpTask = SCR_TransportUnitHelpTaskEntity.Cast(theTask);
680 if (!transportUnitHelpTask)
681 continue;
682
683 if (transportUnitHelpTask.GetTransportUnit() == this)
684 return true;
685 }
686
687 return false;
688 }
689
690 //------------------------------------------------------------------------------------------------
692 {
693 m_NearbySupplyTrucks.Clear();
694 GetGame().GetWorld().QueryEntitiesBySphere(GetOwner().GetOrigin(), m_fSearchTruckRadius, QuerySupplyTrucks, FilterVehicles, EQueryEntitiesFlags.DYNAMIC);
695
696 return GetClosestVehicle();
697 }
698
699 //------------------------------------------------------------------------------------------------
701 {
702 float minSqDistanceAny = float.MAX;
703 float minSqDistanceOperable = float.MAX;
704
705 Vehicle closestAny, closestOperable;
706 foreach (Vehicle vehicle : m_NearbySupplyTrucks)
707 {
708 float sqDistance = vector.DistanceSq(vehicle.GetOrigin(), m_AIGroup.GetOrigin());
709
710 // Track closest overall
711 if (sqDistance < minSqDistanceAny)
712 {
713 minSqDistanceAny = sqDistance;
714 closestAny = vehicle;
715 }
716
717 // Track closest operable
718 if (m_VehicleConditionManager.IsVehicleUsable(vehicle) && sqDistance < minSqDistanceOperable)
719 {
720 minSqDistanceOperable = sqDistance;
721 closestOperable = vehicle;
722 }
723 }
724
725 if (closestOperable)
726 return closestOperable;
727
728 return closestAny;
729 }
730
731 //------------------------------------------------------------------------------------------------
732 protected bool FilterVehicles(IEntity entity)
733 {
734 return entity.IsInherited(Vehicle);
735 }
736
737 //------------------------------------------------------------------------------------------------
738 protected bool QuerySupplyTrucks(IEntity entity)
739 {
740 Vehicle vehicle = Vehicle.Cast(entity);
741 if (!vehicle)
742 return true;
743
744 if (vehicle.m_eVehicleType != EVehicleType.SUPPLY_TRUCK)
745 return true;
746
747 if (m_SuppliesTransportSystem && m_SuppliesTransportSystem.IsVehicleUsed(vehicle, this))
748 return true;
749
750 m_NearbySupplyTrucks.Insert(vehicle);
751
752 return true;
753 }
754
755 //------------------------------------------------------------------------------------------------
756 protected SCR_ResupplyCampaignMilitaryBaseTaskEntity SelectPreferableResupplyTask()
757 {
758 array<SCR_Task> resupplyTasks = {};
759 SCR_TaskSystem.GetInstance().GetTasksByStateFiltered(resupplyTasks, SCR_ETaskState.CREATED | SCR_ETaskState.ASSIGNED, GetFaction().GetFactionKey(), -1, SCR_ResupplyCampaignMilitaryBaseTaskEntity);
760
761 float maxScarcityLevel = -float.MAX;
762 int maxPriorityLevel = int.MAX;
763 SCR_ResupplyCampaignMilitaryBaseTaskEntity resupplyTask;
764 SCR_ResupplyCampaignMilitaryBaseTaskEntity preferableResupplyTask;
766 foreach (SCR_Task task : resupplyTasks)
767 {
768 if (task.GetTaskState() != SCR_ETaskState.CREATED)
769 continue;
770
772 continue;
773
774 resupplyTask = SCR_ResupplyCampaignMilitaryBaseTaskEntity.Cast(task);
775 if (!resupplyTask)
776 continue;
777
778 if (m_SourceBase == resupplyTask.GetMilitaryBase())
779 continue;
780
781 // Tasks with the highest priority are preferred
782 // If more tasks have the highest priority, tasks with the highest scarcity are preferred
783 militaryBase = resupplyTask.GetMilitaryBase();
784 if (!militaryBase)
785 continue;
786
787 int baseResupplyPriority = resupplyTask.GetMilitaryBase().GetSupplyRequestExecutionPriority();
788 if (baseResupplyPriority < maxPriorityLevel)
789 {
790 maxPriorityLevel = baseResupplyPriority;
791 preferableResupplyTask = resupplyTask;
792 maxScarcityLevel = resupplyTask.GetMilitaryBase().GetScarcityLevel();
793 }
794 else if (baseResupplyPriority == maxPriorityLevel)
795 {
796 float baseScarcityLevel = resupplyTask.GetMilitaryBase().GetScarcityLevel();
797 if (baseScarcityLevel > maxScarcityLevel)
798 {
799 maxScarcityLevel = baseScarcityLevel;
800 preferableResupplyTask = resupplyTask;
801 }
802 }
803 }
804
805 return preferableResupplyTask;
806 }
807
808 //------------------------------------------------------------------------------------------------
810 {
811 if (m_sSourceBaseEntityName.IsEmpty())
812 return;
813
814 IEntity sourceBaseEntity = GetGame().GetWorld().FindEntityByName(m_sSourceBaseEntityName);
815 if (!sourceBaseEntity)
816 return;
817
819 if (!m_SourceBase)
820 return;
821
822 m_iSourceBaseCallsign = m_SourceBase.GetCallsign();
823 }
824
825 //------------------------------------------------------------------------------------------------
827 {
828 if (!m_AIGroup)
829 return;
830
831 SCR_Faction faction = SCR_Faction.Cast(m_AIGroup.GetFaction());
832 if (!faction)
833 return;
834
836 SCR_NotificationsComponent.SendLocal(ENotification.CAMPAIGN_TRANSPORT_GROUP_LOST, Replication.FindItemId(GetOwner()));
837 }
838
839 //------------------------------------------------------------------------------------------------
840 override void EOnInit(IEntity owner)
841 {
843
846 return;
847
848 m_TaskSolverManager = SCR_TaskSolverManagerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_TaskSolverManagerComponent));
850 return;
851
853 if (!m_TaskSolver)
854 return;
855
856 m_TaskSolver.SetAiGroup(m_AIGroup);
857
858 m_TaskSolver.GetOnStateChanged().Insert(OnTaskSolverStateChanged);
859 m_TaskSolver.GetOnResupplyTaskSolverStateChanged().Insert(OnResupplyTaskSolverStateChanged);
860
861 m_VehicleConditionManager = m_TaskSolver.GetVehicleConditionManager();
862 m_VehicleConditionManager.GetOnVehicleUsabilityChanged().Insert(OnVehicleUsabilityChanged);
863 m_AiGroupConditionManager = m_TaskSolver.GetAiGroupConditionManager();
864
865 m_TaskSystem = SCR_TaskSystem.GetInstance();
866
867 m_SuppliesTransportSystem.Register(this);
868 }
869
870 //------------------------------------------------------------------------------------------------
871 protected void OnIsVehicleUsableSet()
872 {
874 m_OnVehicleChanged.Invoke(m_Vehicle, null);
875 }
876
877 //------------------------------------------------------------------------------------------------
878 protected void OnVehicleUsabilityChanged(bool isUsable)
879 {
880 if (m_bIsVehicleUsable == isUsable)
881 return;
882
883 m_bIsVehicleUsable = isUsable;
885
887 {
888 SCR_VehicleConditionCheck failedCondition = m_VehicleConditionManager.GetFirstFailedCheck(m_Vehicle);
889 if (failedCondition)
890 m_eVehicleFailedConditionType = failedCondition.GetConditionType();
891 }
892
893 Replication.BumpMe();
894 }
895
896 //------------------------------------------------------------------------------------------------
897 override void OnPostInit(IEntity owner)
898 {
899 if (!GetGame().InPlayMode())
900 return;
901
902 super.OnPostInit(owner);
903
904 SetEventMask(owner, EntityEvent.INIT);
905
907
908 m_AIGroup = SCR_AIGroup.Cast(owner);
909 }
910
911 //------------------------------------------------------------------------------------------------
912 override void OnDelete(IEntity owner)
913 {
914 if (m_TaskSolver)
915 {
916 m_TaskSolver.GetOnStateChanged().Remove(OnTaskSolverStateChanged);
917 m_TaskSolver.GetOnResupplyTaskSolverStateChanged().Remove(OnResupplyTaskSolverStateChanged);
918 }
919
921 m_TaskSolverManager.RemoveSolver(m_TaskSolver);
922
923 SCR_ResourceConsumer consumer = GetVehicleSuppliesConsumer(m_Vehicle);
924 if (consumer)
925 consumer.GetOnResourcesChanged().Remove(OnVehicleResourceValueChanged);
926
928 m_VehicleConditionManager.GetOnVehicleUsabilityChanged().Remove(OnVehicleUsabilityChanged);
929
931 m_AiVehicleUsage.GetOnDeleted().Remove(OnVehicleDeleted);
932
934 m_SuppliesTransportSystem.Unregister(this);
935
936 SCR_GameModeCampaign gameMode = SCR_GameModeCampaign.GetInstance();
937 if (gameMode && !gameMode.IsProxy())
938 {
941
942 if (m_Vehicle)
944 }
945
947
948 super.OnDelete(owner);
949 }
950}
ENotification
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
vector GetOrigin()
SCR_BaseGameMode GetGameMode()
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
SCR_ETaskSolverState
SCR_ETransportUnitState
void SCR_FuelManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
void SCR_GroupTaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
EResourceGeneratorID
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
FactionKey GetFactionKey()
ScriptInvokerBase< ScriptInvokerFloatMethod > ScriptInvokerFloat
ScriptInvokerBase< ScriptInvokerIntMethod > ScriptInvokerInt
SCR_ETaskVisibility
Definition SCR_Task.c:24
void SCR_Task(IEntitySource src, IEntity parent)
Definition SCR_Task.c:1938
SCR_ETaskState
Definition SCR_Task.c:3
ScriptInvokerBase< OnTransportUnitVehicleChangedDelegate > OnTransportUnitVehicleChangedInvoker
func OnTransportUnitVehicleChangedDelegate
SCR_EVehicleConditionCheckType
EVehicleType
Definition Vehicle.c:4
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external GenericComponent FindComponent(typename typeName)
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
SCR_ESupplyRequestExecutionPriority GetSupplyRequestExecutionPriority()
SCR_CampaignMilitaryBaseComponent FindBaseByCallsign(int callsign)
int GetCommanderId()
bool IsPlayable()
Script entry for garbage system modding.
static SCR_GarbageSystem GetByEntityWorld(IEntity entity)
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
static SCR_SuppliesTransportSystem GetInstance()
void SelectForTaskSolving(SCR_ResupplyCampaignMilitaryBaseTaskEntity task)
SCR_ResupplyCampaignMilitaryBaseTaskEntity m_PreferableResupplyTask
SCR_EResupplyTaskSolverState GetResupplyTaskSolverState()
SCR_CampaignMilitaryBaseComponent m_SourceBase
override void EOnInit(IEntity owner)
void UpdateGarbageBlacklist(notnull Vehicle vehicle, bool blacklisted)
SCR_TaskSolverManagerComponent m_TaskSolverManager
SCR_TransportUnitHelpTaskEntity CreateTransportUnitHelpTask()
void SetState(SCR_ETransportUnitState state)
void OnTaskSolverStateChanged(SCR_TaskSolverBase taskSolver, SCR_ETaskSolverState taskSolverState)
SCR_ResupplyCampaignMilitaryBaseTaskEntity GetPreferableResupplyTask()
void OnBoardingCompleted(AIWaypoint waypoint)
SCR_AIVehicleUsageComponent m_AiVehicleUsage
SCR_ResourceConsumer GetVehicleSuppliesConsumer(Vehicle vehicle)
ref ScriptInvokerInt m_OnResupplyTaskSolverStateChanged
void SetSuppliedBase(SCR_CampaignMilitaryBaseComponent suppliedBase)
ScriptInvokerFloat GetOnVehicleResourcesValueChanged()
ScriptInvokerInt GetOnResupplyTaskSolverStateChanged()
override void OnDelete(IEntity owner)
SCR_CampaignMilitaryBaseComponent m_SuppliedBase
void OnSourceBaseCallsignSet()
Called upon the m_iSourceBaseCallsign replication and set the correct base from the server.
SCR_TransportUnitHelpTaskEntity m_TransportUnitHelpTaskEntity
SCR_ResupplyCampaignMilitaryBaseTaskEntity SelectPreferableResupplyTask()
ref OnTransportUnitVehicleChangedInvoker m_OnVehicleChanged
void OnPreferableResupplyTaskSet()
Called upon the m_PreferableResupplyTaskRplId replication.
SCR_AIGroupConditionManager m_AiGroupConditionManager
SCR_EVehicleConditionCheckType GetVehicleFailedConditionType()
void OnResupplyTaskSolverStateChanged(int solverId, SCR_EResupplyTaskSolverState resupplyTaskSolverState)
void SetSourceBase(SCR_CampaignMilitaryBaseComponent sourceBase)
void OnMoveToSourceBaseWaypointCompleted(AIWaypoint waypoint)
SCR_SuppliesTransportSystem m_SuppliesTransportSystem
static const string TRANSPORT_UNIT_HELP_TASK_ID
void OnVehicleDeleted(SCR_AIVehicleUsageComponent vehicleUsageComponent)
void OnVehicleResourceValueChanged(SCR_ResourceInteractor interactor, float previousValue)
SCR_BoardingEntityWaypoint CreateBoardingVehicleWaypoint()
SCR_EVehicleConditionCheckType m_eVehicleFailedConditionType
bool HasTransportUnitHelpTask(notnull SCR_Faction faction)
void SetPreferableResupplyTask(SCR_ResupplyCampaignMilitaryBaseTaskEntity preferableTask)
override void OnPostInit(IEntity owner)
SCR_BoardingEntityWaypoint m_BoardingWaypoint
ref ScriptInvokerFloat m_OnVehicleResourcesValueChanged
SCR_VehicleConditionManager m_VehicleConditionManager
OnTransportUnitVehicleChangedInvoker GetOnVehicleChanged()
SCR_CampaignMilitaryBaseComponent GetSourceBase()
SCR_FuelManagerComponent m_FuelManager
proto external GenericEntity GetOwner()
Get owner entity.
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EQueryEntitiesFlags