Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignBuildingBudgetEditorComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Editor", description: "", icon: "WBData/ComponentEditorProps/componentEditor.png")]
5
6class SCR_CampaignBuildingBudgetEditorComponent : SCR_BudgetEditorComponent
7{
8 protected SCR_ResourceComponent m_ResourceComponent;
9 protected SCR_CampaignBuildingEditorComponent m_CampaignBuildingComponent;
11 protected SCR_ECharacterRank m_eHighestRank;
12
13 protected static const int UNLIMITED_PROP_BUDGET = -1;
14
15 //------------------------------------------------------------------------------------------------
16 protected override void EOnEditorActivateServer()
17 {
19 m_CampaignBuildingComponent = SCR_CampaignBuildingEditorComponent.Cast(FindEditorComponent(SCR_CampaignBuildingEditorComponent, true, true));
20
21 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
22 if (!factionManager)
23 return;
24
25 array<ref SCR_RankInfo> ranks = factionManager.GetFactionRanks(m_Manager.GetPlayerID()).GetAllRanks();
26 if (!ranks)
27 return;
28
29 ranks.Sort();
30
31 SCR_RankInfo highestRankID = ranks[ranks.Count() - 1];
32 if (!highestRankID)
33 return;
34
35 m_eHighestRank = highestRankID.GetRankID();
36
38 }
39
40 //------------------------------------------------------------------------------------------------
41 protected override void EOnEditorActivate()
42 {
43 m_CampaignBuildingComponent = SCR_CampaignBuildingEditorComponent.Cast(FindEditorComponent(SCR_CampaignBuildingEditorComponent, true, true));
45 {
46 Debug.Error("SCR_CampaignBuildingBudgetEditorComponent was unable to find SCR_CampaignBuildingEditorComponent on " + m_Owner);
47 return;
48 }
49
51 m_CampaignBuildingComponent.GetOnProviderChanged().Insert(OnTargetBaseChanged);
52
54 if (baseGameMode)
56 }
57
58 //------------------------------------------------------------------------------------------------
59 protected override void EOnEditorDeactivate()
60 {
62 m_CampaignBuildingComponent.GetOnProviderChanged().Remove(OnTargetBaseChanged);
63
65 if (baseGameMode)
67 }
68
69 //------------------------------------------------------------------------------------------------
70 protected void OnResourceTypeEnabledChanged(array<EResourceType> disabledResourceTypes)
71 {
73 }
74
75 //------------------------------------------------------------------------------------------------
79 {
81 return true;
82
83 m_CampaignBuildingComponent = SCR_CampaignBuildingEditorComponent.Cast(FindEditorComponent(SCR_CampaignBuildingEditorComponent, true, true));
85 {
86 Debug.Error("Recovering of SCR_CampaignBuildingBudgetEditorComponent was unable to find SCR_CampaignBuildingEditorComponent on " + m_Owner + " and because of that editor will be closed now!");
87 m_Manager.Close();
88 return false;
89 }
90
92 ScriptInvoker providerChangedInvoker = m_CampaignBuildingComponent.GetOnProviderChanged();
93 providerChangedInvoker.Remove(OnTargetBaseChanged); // it is possible that it was added there previously, so first we have to do a cleanup just to be safe
94 providerChangedInvoker.Insert(OnTargetBaseChanged);
95
97 if (!baseGameMode)
98 return false; // if game mode doesnt exist then there is no hope for things working right
99
100 ScriptInvokerBase<SCR_BaseGameMode_OnResourceEnabledChanged> resourceTypeInvoker = baseGameMode.GetOnResourceTypeEnabledChanged();
101 resourceTypeInvoker.Remove(OnResourceTypeEnabledChanged); // it is possible that it was added there previously, so first we have to do a cleanup just to be safe
102 resourceTypeInvoker.Insert(OnResourceTypeEnabledChanged);
103 return true;
104 }
105
106 //------------------------------------------------------------------------------------------------
107 [Obsolete("SCR_CampaignBuildingBudgetEditorComponent.RefreshResourcesComponent() should be used instead.")]
109 {
111 return false;
112
113 SCR_CampaignSuppliesComponent providerSuppliesComponent;
114 if (m_CampaignBuildingComponent.GetProviderSuppliesComponent(providerSuppliesComponent))
115 {
117 {
118 if (m_SuppliesComponent != providerSuppliesComponent)
119 {
120 m_SuppliesComponent.m_OnSuppliesChanged.Remove(OnBaseSuppliesChanged);
121 }
122 }
123 else
124 {
125 providerSuppliesComponent.m_OnSuppliesChanged.Insert(OnBaseSuppliesChanged);
126 }
127 }
128
129 m_SuppliesComponent = providerSuppliesComponent;
130
131 return m_SuppliesComponent != null;
132 }
133
134 //------------------------------------------------------------------------------------------------
135 protected void OnBaseResourcesChanged(SCR_ResourceConsumer consumer, int previousValue)
136 {
138 }
139
140 //------------------------------------------------------------------------------------------------
141 [Obsolete("SCR_CampaignBuildingBudgetEditorComponent.OnBaseResourcesChanged() should be used instead.")]
142 protected void OnBaseSuppliesChanged(int supplies)
143 {
145 }
146
147 //------------------------------------------------------------------------------------------------
148 protected void OnTargetBaseChanged(IEntity targetEntity)
149 {
151 }
152
153 //------------------------------------------------------------------------------------------------
154 override bool GetMaxBudgetValue(EEditableEntityBudget type, out int maxBudget)
155 {
156 switch (type)
157 {
158 case EEditableEntityBudget.CAMPAIGN:
160 return true;
161
162 SCR_ResourceConsumer consumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
163 if (consumer)
164 maxBudget = consumer.GetAggregatedMaxResourceValue();
165
166 return true;
167
168 case EEditableEntityBudget.RANK_PRIVATE:
169 maxBudget = m_eHighestRank;
170 return true;
171
172 case EEditableEntityBudget.RANK_CORPORAL:
173 maxBudget = m_eHighestRank;
174 return true;
175
176 case EEditableEntityBudget.RANK_SERGEANT:
177 maxBudget = m_eHighestRank;
178 return true;
179
180 case EEditableEntityBudget.RANK_LIEUTENANT:
181 maxBudget = m_eHighestRank;
182 return true;
183
184 case EEditableEntityBudget.RANK_CAPTAIN:
185 maxBudget = m_eHighestRank;
186 return true;
187
188 case EEditableEntityBudget.RANK_MAJOR:
189 maxBudget = m_eHighestRank;
190 return true;
191
192 case EEditableEntityBudget.RANK_COLONEL:
193 maxBudget = m_eHighestRank;
194 return true;
195
196 case EEditableEntityBudget.RANK_GENERAL:
197 maxBudget = m_eHighestRank;
198 return true;
199
200 case EEditableEntityBudget.ESTABLISH_BASE:
201 maxBudget = CanEstablishBase();
202 return true;
203
204 case EEditableEntityBudget.PROPS:
205 maxBudget = GetProviderMaxValue(type);
206 return true;
207
208 case EEditableEntityBudget.COOLDOWN:
209 if (HasCooldownTime())
210 maxBudget = 0;
211 else
212 maxBudget = 1;
213
214 return true;
215
216 case EEditableEntityBudget.AI:
217 maxBudget = GetProviderMaxValue(type);
218 return true;
219
220 case EEditableEntityBudget.AI_SERVER:
221 AIWorld aiWorld = GetGame().GetAIWorld();
222 if (!aiWorld)
223 return true;
224
225 maxBudget = aiWorld.GetLimitOfActiveAIs();
226 return true;
227 }
228
229 return true;
230 }
231
232 //------------------------------------------------------------------------------------------------
234 {
236 return 0;
237
238 SCR_CampaignBuildingProviderComponent providerComponent = m_CampaignBuildingComponent.GetProviderComponent();
239 if (!providerComponent)
240 return 0; // build mode must have a provider, if it doesnt, then there is no budget
241
242 switch (type)
243 {
244 case EEditableEntityBudget.CAMPAIGN:
245 if (!m_ResourceComponent || !m_ResourceComponent.IsResourceTypeEnabled())
246 return -1;
247
248 SCR_ResourceConsumer consumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
249 if (!consumer)
250 return -1;
251
252 return consumer.GetAggregatedMaxResourceValue() - consumer.GetAggregatedResourceValue();
253
254 case EEditableEntityBudget.RANK_PRIVATE:
255 return m_eHighestRank - GetUserRank();
256
257 case EEditableEntityBudget.RANK_CORPORAL:
258 return m_eHighestRank - GetUserRank();
259
260 case EEditableEntityBudget.RANK_SERGEANT:
261 return m_eHighestRank - GetUserRank();
262
263 case EEditableEntityBudget.RANK_LIEUTENANT:
264 return m_eHighestRank - GetUserRank();
265
266 case EEditableEntityBudget.RANK_CAPTAIN:
267 return m_eHighestRank - GetUserRank();
268
269 case EEditableEntityBudget.RANK_MAJOR:
270 return m_eHighestRank - GetUserRank();
271
272 case EEditableEntityBudget.RANK_COLONEL:
273 return m_eHighestRank - GetUserRank();
274
275 case EEditableEntityBudget.RANK_GENERAL:
276 return m_eHighestRank - GetUserRank();
277
278 case EEditableEntityBudget.ESTABLISH_BASE:
279 return !CanEstablishBase();
280
281 case EEditableEntityBudget.PROPS:
282 return providerComponent.GetCurrentPropValue();
283
284 case EEditableEntityBudget.COOLDOWN:
285 return HasCooldownTime();
286
287 case EEditableEntityBudget.AI:
288 return providerComponent.GetCurrentAIValue();
289
290 case EEditableEntityBudget.AI_SERVER:
291 AIWorld aiWorld = GetGame().GetAIWorld();
292 if (!aiWorld)
293 return -1;
294
295 return aiWorld.GetCurrentNumOfActiveAIs();
296 }
297
298 return -1;
299 }
300
301 //------------------------------------------------------------------------------------------------
304 {
306 return 0;
307
308 SCR_CampaignBuildingProviderComponent providerComponent = m_CampaignBuildingComponent.GetProviderComponent();
309 if (!providerComponent)
310 return 0; // build mode must have a provider who determines the budget
311
312 return providerComponent.GetMaxBudgetValue(budget);
313 }
314
315 //------------------------------------------------------------------------------------------------
318 {
320 return false;
321
322 SCR_CampaignBuildingProviderComponent providerComponent = m_CampaignBuildingComponent.GetProviderComponent();
323 if (!providerComponent)
324 return false;
325
326 if (!m_Manager)
327 return false;
328
329 return providerComponent.HasCooldownSet(m_Manager.GetPlayerID());
330 }
331
332 //------------------------------------------------------------------------------------------------
334 {
336 return int.MAX;
337
338 SCR_CampaignBuildingProviderComponent providerComponent = m_CampaignBuildingComponent.GetProviderComponent();
339 if (!providerComponent)
340 return int.MAX; // build mode must have a provider, if it doesnt, then its safer to block at all cost
341
342 return providerComponent.GetCooldownValue(m_Manager.GetPlayerID());
343 }
344
345 //------------------------------------------------------------------------------------------------
346 protected bool CanEstablishBase()
347 {
348 // Establish base is allowed in others game modes like Gamemaster
349 SCR_GameModeCampaign campaignGameMode = SCR_GameModeCampaign.GetInstance();
350 if (!campaignGameMode)
351 return true;
352
354 return false;
355
356 SCR_CampaignBuildingProviderComponent providerComponent = m_CampaignBuildingComponent.GetProviderComponent();
357 if (!providerComponent)
358 return false;
359
360 SCR_ChimeraCharacter player = SCR_ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
361 if (!player)
362 return false;
363
364 Faction faction = player.GetFaction();
365 if (!faction)
366 return false;
367
368 IEntity providerEnt = providerComponent.GetOwner();
369 FactionAffiliationComponent factionComp = FactionAffiliationComponent.Cast(providerEnt.FindComponent(FactionAffiliationComponent));
370 if (!factionComp)
371 {
372 // in case of construction trucks, the provider is the back of the truck,
373 // while faction affiliation component is only on the truck itself,
374 // which is a parent, thus we need to check that as well
375 IEntity parent = providerEnt.GetParent();
376 while (parent && factionComp == null)
377 {
378 factionComp = FactionAffiliationComponent.Cast(parent.FindComponent(FactionAffiliationComponent));
379 if (!factionComp)
380 parent = parent.GetParent();
381 }
382
383 if (!factionComp)
384 return false;
385
386 providerEnt = parent;
387 }
388
389 if (Vehicle.Cast(providerEnt))
390 {
391 if (faction != factionComp.GetDefaultAffiliatedFaction())
392 return false;
393 }
394 else
395 {
396 if (faction != factionComp.GetAffiliatedFaction())
397 return false;
398 }
399
400 if (!campaignGameMode.GetBaseManager().CanFactionBuildNewBase(faction))
401 return false;
402
403 SCR_TaskSystem taskSystem = SCR_TaskSystem.GetInstance();
404 if (!taskSystem)
405 return false;
406
407 array<SCR_Task> tasks = {};
408 taskSystem.GetTasksByState(tasks, SCR_ETaskState.CREATED | SCR_ETaskState.ASSIGNED, faction.GetFactionKey());
409
410 SCR_EstablishBaseTaskEntity establishTask;
411 SCR_EstablishBaseTaskEntity nearestRelevantTask;
412
413 float distance;
414 float distanceToNearestRelevantTask;
415
416 foreach (SCR_Task task : tasks)
417 {
418 establishTask = SCR_EstablishBaseTaskEntity.Cast(task);
419
420 if (!establishTask)
421 continue;
422
423 distance = vector.DistanceSqXZ(providerComponent.GetOwner().GetOrigin(), establishTask.GetOrigin());
424
425 if (!nearestRelevantTask || distance < distanceToNearestRelevantTask)
426 {
427 nearestRelevantTask = establishTask;
428 distanceToNearestRelevantTask = distance;
429 }
430 }
431
432 int threshold = SCR_CampaignFactionCommanderHandlerComponent.Cast(SCR_FactionCommanderHandlerComponent.GetInstance()).GetBaseEstablishingRadius();
433
434 if (!nearestRelevantTask || distanceToNearestRelevantTask > (threshold * threshold))
435 return false;
436
437 return true;
438 }
439
440 //------------------------------------------------------------------------------------------------
442 SCR_ECharacterRank GetUserRank()
443 {
444 int playerId = SCR_PlayerController.GetLocalPlayerId();
445
446 PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
447 if (!playerController)
448 return SCR_ECharacterRank.INVALID;
449
450 return SCR_CharacterRankComponent.GetCharacterRank(playerController.GetControlledEntity());
451 }
452
453 //------------------------------------------------------------------------------------------------
454 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
455 protected override void OnEntityCoreBudgetUpdatedOwner(EEditableEntityBudget entityBudget, int budgetValue, int budgetChange, bool sendBudgetMaxEvent, bool budgetMaxReached)
456 {
457 int maxBudget;
459 Event_OnBudgetUpdated.Invoke(EEditableEntityBudget.PROPS, GetCurrentBudgetValue(EEditableEntityBudget.PROPS), budgetValue, maxBudget);
460
461 if (entityBudget != EEditableEntityBudget.CAMPAIGN)
462 return;
463
465 return;
466
467 SCR_ResourceConsumer consumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
468
469 if (!consumer)
470 return;
471
472 if (consumer.GetAggregatedResourceValue() - budgetChange <= 0)
473 Event_OnBudgetMaxReached.Invoke(entityBudget, true);
474 }
475
476 //------------------------------------------------------------------------------------------------
478 {
480 }
481
482 //------------------------------------------------------------------------------------------------
483 protected override void RefreshBudgetSettings()
484 {
486 return;
487
488 SCR_CampaignBuildingProviderComponent providerComponent = m_CampaignBuildingComponent.GetProviderComponent();
489 if (!providerComponent)
490 {
491 m_Manager.Close(); // build mode must have a provider
492 return;
493 }
494
495 array<ref EEditableEntityBudget> budgetsType = {};
496 providerComponent.GetBudgetTypesToEvaluate(budgetsType);
497
498 SCR_EditableEntityCoreBudgetSetting budget;
499
500 for (int i = budgetsType.Count() - 1; i >= 0; i--)
501 {
502 EEditableEntityBudget budgetType = budgetsType[i];
503
504 int maxBudgetValue;
505
506 if (m_EntityCore.GetBudget(budgetType, budget) && GetMaxBudgetValue(budgetType, maxBudgetValue))
507 m_BudgetSettingsMap.Insert(budgetType, budget);
508 }
509
511 }
512
513 //------------------------------------------------------------------------------------------------
514 override bool CanPlaceEntitySource(IEntityComponentSource editableEntitySource, out EEditableEntityBudget blockingBudget, bool isPlacingPlayer = false, bool updatePreview = true, bool showNotification = true)
515 {
516 bool canPlace = true;
517 if (IsBudgetCapEnabled() && editableEntitySource)
518 {
519 array<ref SCR_EntityBudgetValue> budgetCosts = {};
520 if (!GetEntitySourcePreviewBudgetCosts(editableEntitySource, budgetCosts))
521 canPlace = false;
522
523 // Clear budget cost when placing as player
524 if (isPlacingPlayer)
525 budgetCosts.Clear();
526
527 if (updatePreview)
528 UpdatePreviewCost(budgetCosts);
529
530 canPlace = canPlace && CanPlace(budgetCosts, blockingBudget);
531 }
532 return CanPlaceResultCampaignBuilding(canPlace, showNotification, blockingBudget);
533 }
534
535 //------------------------------------------------------------------------------------------------
536 protected bool CanPlaceResultCampaignBuilding(bool canPlace, bool showNotification, EEditableEntityBudget blockingBudget)
537 {
538 if (showNotification)
539 {
540 Rpc(CanPlaceOwnerCampaignBuilding, canPlace, blockingBudget);
541 }
542 return canPlace;
543 }
544
545 //------------------------------------------------------------------------------------------------
549 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
550 void CanPlaceOwnerCampaignBuilding(bool canPlace, EEditableEntityBudget blockingBudget)
551 {
552 if (!canPlace)
553 {
554 switch (blockingBudget)
555 {
556 case EEditableEntityBudget.CAMPAIGN:
557 {
558 GetManager().SendNotification(ENotification.EDITOR_PLACING_NO_ENOUGH_SUPPLIES);
559 break;
560 }
561
562 case EEditableEntityBudget.RANK_PRIVATE:
563 case EEditableEntityBudget.RANK_CORPORAL:
564 case EEditableEntityBudget.RANK_SERGEANT:
565 case EEditableEntityBudget.RANK_LIEUTENANT:
566 case EEditableEntityBudget.RANK_CAPTAIN:
567 case EEditableEntityBudget.RANK_MAJOR:
568 case EEditableEntityBudget.RANK_COLONEL:
569 case EEditableEntityBudget.RANK_GENERAL:
570 string rankName = typename.EnumToString(EEditableEntityBudget, blockingBudget);
571 rankName.Replace("RANK_", string.Empty);
572 SCR_ECharacterRank requiredRank = typename.StringToEnum(SCR_ECharacterRank, rankName);
573 SCR_Faction localFaction = SCR_Faction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
574 if (!localFaction)
575 return;
576
577 SCR_RankInfo rank = localFaction.GetRanks().GetRankByID(requiredRank, true);
578 if (!rank)
579 return;
580
581 SCR_NotificationsComponent.SendLocal(ENotification.EDITOR_PLACING_RANK_TOO_LOW, SCR_PlayerController.GetLocalPlayerId(), rank.GetRankID());
582 break;
583
584
585 case EEditableEntityBudget.ESTABLISH_BASE:
586 {
587 SCR_GameModeCampaign campaignGameMode = SCR_GameModeCampaign.GetInstance();
588 Faction faction = SCR_FactionManager.SGetLocalPlayerFaction();
589 if (campaignGameMode && faction && !campaignGameMode.GetBaseManager().CanFactionBuildNewBase(faction))
590 GetManager().SendNotification(ENotification.EDITOR_PLACING_ESTABLISH_BASE_LIMIT_REACHED);
591 else
592 GetManager().SendNotification(ENotification.EDITOR_PLACING_BUDGET_ESTABLISH_BASE);
593 break;
594 }
595
596 case EEditableEntityBudget.PROPS:
597 {
598 GetManager().SendNotification(ENotification.EDITOR_PLACING_NO_MORE_COMPOSITIONS_AT_BASE);
599 break;
600 }
601
602 case EEditableEntityBudget.COOLDOWN:
603 {
604 SCR_NotificationsComponent.SendLocal(ENotification.EDITOR_COOLDOWN, GetCooldownTime());
605 break;
606 }
607
608 case EEditableEntityBudget.AI:
609 {
610 SCR_NotificationsComponent.SendLocal(ENotification.EDITOR_AILIMIT);
611 break;
612 }
613
614 case EEditableEntityBudget.AI_SERVER:
615 {
616 SCR_NotificationsComponent.SendLocal(ENotification.EDITOR_PLACING_BUDGET_MAX);
617 break;
618 }
619 }
620 }
621 }
622
623 //------------------------------------------------------------------------------------------------
625 {
626 const bool valid = super.GetMaxBudget(type, budget);
627
628 if(!valid)
629 return false;
630
631 //if some checks fail, the budget will not change
632 int newMaxBudget = budget.GetBudgetValue();
633
634 switch (type)
635 {
636 case EEditableEntityBudget.CAMPAIGN:
637 {
639 break;
640
641 SCR_ResourceConsumer consumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
642 if (!consumer)
643 break;
644
645 newMaxBudget = consumer.GetAggregatedResourceValue();
646 break;
647 }
648
649 case EEditableEntityBudget.RANK_PRIVATE:
650 {
651 newMaxBudget = GetUserRank();
652 break;
653 }
654
655 case EEditableEntityBudget.RANK_CORPORAL:
656 {
657 newMaxBudget = GetUserRank();
658 break;
659 }
660
661 case EEditableEntityBudget.RANK_SERGEANT:
662 {
663 newMaxBudget = GetUserRank();
664 break;
665 }
666
667 case EEditableEntityBudget.RANK_LIEUTENANT:
668 {
669 newMaxBudget = GetUserRank();
670 break;
671 }
672
673 case EEditableEntityBudget.RANK_CAPTAIN:
674 {
675 newMaxBudget = GetUserRank();
676 break;
677 }
678
679 case EEditableEntityBudget.RANK_MAJOR:
680 {
681 newMaxBudget = GetUserRank();
682 break;
683 }
684
685 case EEditableEntityBudget.RANK_COLONEL:
686 {
687 newMaxBudget = GetUserRank();
688 break;
689 }
690
691 case EEditableEntityBudget.RANK_GENERAL:
692 {
693 newMaxBudget = GetUserRank();
694 break;
695 }
696
697 case EEditableEntityBudget.ESTABLISH_BASE:
698 {
699 newMaxBudget = !CanEstablishBase();
700 break;
701 }
702
703 case EEditableEntityBudget.PROPS:
704 {
705 newMaxBudget = GetProviderMaxValue(EEditableEntityBudget.PROPS);
706 break;
707 }
708
709 case EEditableEntityBudget.COOLDOWN:
710 {
711 newMaxBudget = HasCooldownTime();
712 break;
713 }
714
715 case EEditableEntityBudget.AI:
716 {
718 break;
719 }
720
721 case EEditableEntityBudget.AI_SERVER:
722 {
723 AIWorld aiWorld = GetGame().GetAIWorld();
724 if (!aiWorld)
725 break;
726
727 newMaxBudget = aiWorld.GetLimitOfActiveAIs();
728 break;
729 }
730 }
731
732 budget.SetBudgetValue(newMaxBudget);
733
734 return true;
735 }
736
737 //------------------------------------------------------------------------------------------------
738 override bool CanPlace(notnull array<ref SCR_EntityBudgetValue> budgetCosts, out EEditableEntityBudget blockingBudget)
739 {
740 if (!IsBudgetCapEnabled() || budgetCosts.IsEmpty())
741 return true;
742
743 array<EEditableEntityBudget> blockingBudgets = {};
744 int initialPriorityOrder = -1;
745 EEditableEntityBudget blockingBudgetCandidate = -1;
746
747 foreach (SCR_EntityBudgetValue budgetCost : budgetCosts)
748 {
749 if (!CanPlace(budgetCost, blockingBudget))
750 {
751 if (IsBudgetCapEnabled(blockingBudget))
752 {
753 SCR_EditableEntityCoreBudgetSetting budgetSettings = GetBudgetSetting(blockingBudget);
754 if (!budgetSettings)
755 continue;
756
757 // promote budget to candidate if it's non priority budget, only when there wasn't set any priority budget yet.
758 SCR_BudgetUIInfo budgetUIInfo = SCR_BudgetUIInfo.Cast(budgetSettings.GetInfo());
759 if (!budgetUIInfo && initialPriorityOrder == -1)
760 {
761 blockingBudgetCandidate = blockingBudget;
762 continue;
763 }
764
765 if (!budgetUIInfo)
766 continue;
767
768 // this budget has higher priority then any other before, promote it as a priority budget.
769 if (initialPriorityOrder < budgetUIInfo.GetPriorityOrder())
770 {
771 blockingBudgetCandidate = blockingBudget;
772 initialPriorityOrder = budgetUIInfo.GetPriorityOrder();
773 }
774 }
775 };
776 }
777
778 if (blockingBudgetCandidate == -1)
779 return true;
780
781 blockingBudget = blockingBudgetCandidate;
782
783 return false;
784 }
785
786 //------------------------------------------------------------------------------------------------
791 {
793 return true;
794
795 SCR_CampaignBuildingProviderComponent providerComponent = m_CampaignBuildingComponent.GetProviderComponent();
796 if (!providerComponent)
797 return true;
798
799 return providerComponent.IsBudgetToEvaluate(blockingBudget);
800 }
801
802 //------------------------------------------------------------------------------------------------
803 override bool GetEntityPreviewBudgetCosts(SCR_EditableEntityUIInfo entityUIInfo, out notnull array<ref SCR_EntityBudgetValue> budgetCosts)
804 {
805 if (!entityUIInfo)
806 return false;
807
808 SCR_EditableGroupUIInfo groupUIInfo = SCR_EditableGroupUIInfo.Cast(entityUIInfo);
809 if (groupUIInfo)
810 {
811 entityUIInfo.GetEntityAndChildrenBudgetCost(budgetCosts);
812
813 if (!entityUIInfo.GetEntityBudgetCost(budgetCosts))
814 GetEntityTypeBudgetCost(entityUIInfo.GetEntityType(), budgetCosts);
815 }
816 else
817 {
818 array<ref SCR_EntityBudgetValue> entityChildrenBudgetCosts = {};
819
820 if (!entityUIInfo.GetEntityBudgetCost(budgetCosts))
821 GetEntityTypeBudgetCost(entityUIInfo.GetEntityType(), budgetCosts);
822
823 entityUIInfo.GetEntityChildrenBudgetCost(entityChildrenBudgetCosts);
824
825 SCR_EntityBudgetValue.MergeBudgetCosts(budgetCosts, entityChildrenBudgetCosts);
826 }
827
828 FilterAvailableBudgets(budgetCosts);
829
830 return true;
831 }
832}
EEditableEntityBudget
ENotification
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_BaseGameMode GetGameMode()
bool CheckAndRecoverCampaignBuildingComponent()
void OnBaseSuppliesChanged(int supplies)
void OnResourceTypeEnabledChanged(array< EResourceType > disabledResourceTypes)
SCR_ECharacterRank m_eHighestRank
bool HasCooldownTime()
Return current cooldown timer state.
SCR_CampaignBuildingEditorComponent m_CampaignBuildingComponent
void OnBaseResourcesChanged(SCR_ResourceConsumer consumer, int previousValue)
void OnTargetBaseChanged(IEntity targetEntity)
SCR_CampaignSuppliesComponent m_SuppliesComponent
void CanPlaceOwnerCampaignBuilding(bool canPlace, EEditableEntityBudget blockingBudget)
SCR_ECharacterRank GetUserRank()
int GetProviderMaxValue(EEditableEntityBudget budget)
override int GetCurrentBudgetValue(EEditableEntityBudget type)
bool CanPlaceResultCampaignBuilding(bool canPlace, bool showNotification, EEditableEntityBudget blockingBudget)
SCR_EditableEntityCore m_EntityCore
int GetMaxBudgetValue(EEditableEntityBudget budget)
Return max value of the given budget if this budget is added to be evaluated with this provider and h...
void SCR_CampaignSuppliesComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
float distance
EDamageType type
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
void OnResourceTypeEnabledChanged()
EResourceGeneratorID
SCR_ResourceComponent m_ResourceComponent
void SCR_Task(IEntitySource src, IEntity parent)
Definition SCR_Task.c:1938
SCR_ETaskState
Definition SCR_Task.c:3
Definition Debug.c:13
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
proto external Managed FindComponent(typename typeName)
proto external IEntity GetParent()
SCR_BaseEditorComponent FindEditorComponent(typename type, bool showError=false, bool modeFirst=false)
SCR_EditorManagerEntity GetManager()
ScriptInvokerBase< SCR_BaseGameMode_OnResourceEnabledChanged > GetOnResourceTypeEnabledChanged()
void UpdatePreviewCost(notnull array< ref SCR_EntityBudgetValue > budgetCosts)
bool GetEntitySourcePreviewBudgetCosts(IEntityComponentSource editableEntitySource, out notnull array< ref SCR_EntityBudgetValue > budgetCosts)
SCR_EditableEntityCoreBudgetSetting GetBudgetSetting(EEditableEntityBudget budgetType)
bool CanPlace(notnull array< ref SCR_EntityBudgetValue > budgetCosts, out EEditableEntityBudget blockingBudget)
bool GetMaxBudget(EEditableEntityBudget type, out SCR_EntityBudgetValue budget)
void RefreshBudgetSettings()
Get default budget definitions from core, budget values not synced on client, use GetCurrentBudget fo...
void GetEntityTypeBudgetCost(EEditableEntityType entityType, out array< ref SCR_EntityBudgetValue > budgetCosts)
bool CanPlaceEntitySource(IEntityComponentSource editableEntitySource, out EEditableEntityBudget blockingBudget, bool isPlacingPlayer=false, bool updatePreview=true, bool showNotification=true)
bool GetEntityPreviewBudgetCosts(SCR_EditableEntityUIInfo entityUIInfo, out notnull array< ref SCR_EntityBudgetValue > budgetCosts)
void FilterAvailableBudgets(inout notnull array< ref SCR_EntityBudgetValue > budgetCosts)
void OnEntityCoreBudgetUpdatedOwner(EEditableEntityBudget entityBudget, int budgetValue, int budgetChange, bool sendBudgetMaxEvent, bool budgetMaxReached)
int GetCurrentBudgetValue(EEditableEntityBudget type)
bool GetMaxBudgetValue(EEditableEntityBudget type, out int maxBudget)
void GetEntityAndChildrenBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets)
Get Entity and its children budgets.
EEditableEntityType GetEntityType()
bool GetEntityBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets)
void GetEntityChildrenBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets)
Get only Entity's children budget costs, i.e. cost of entities inside a composition entitiy.
SCR_RankContainer GetRanks()
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
static IEntity GetLocalControlledEntity()
SCR_RankInfo GetRankByID(SCR_ECharacterRank rankIdentifier)
SCR_ECharacterRank GetRankID()
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134