1[
EntityEditorProps(
category:
"GameScripted/Building", description:
"Component attached to a provider, responsible for basic provider behaviour.")]
6class SCR_CampaignBuildingProviderComponent : SCR_MilitaryBaseLogicComponent
9 protected string m_sProviderDisplayName;
11 [
Attribute(
"0",
UIWidgets.CheckBox,
"Can the building mode at this provider executed only via user action?")]
17 [
Attribute(
"0",
UIWidgets.CheckBox,
"Master provider is for example HQ with other service (providers) in vicinity.")]
20 [
Attribute(
"0",
UIWidgets.CheckBox,
"When opening a Free Roam Building mode, try to use master provider. Master provider is HQ where the service is registered in.")]
23 [
Attribute(
"0",
UIWidgets.CheckBox,
"Reads data(EEditableEntityLabel) from available providers as and extends the building option.")]
29 [
Attribute(
"0",
UIWidgets.CheckBox,
"If set, player can command friendly AI in building radius.")]
32 [
Attribute(
"1",
UIWidgets.CheckBox,
"Obstruct view when an enemy is present within the radius of the building.")]
38 [
Attribute(defvalue:
"1", uiwidget:
UIWidgets.ComboBox,
desc:
"Minimal rank that allows player to use the provider to build structures.", enums: ParamEnumArray.FromEnum(SCR_ECharacterRank))]
41 [
Attribute(
desc:
"Fill in the budgets to be used with this provider")]
44 [
Attribute(
desc:
"Traits this provider will provide. Each trait represents a tab in building interface. The tabs have to be defined in building mode's SCR_ContentBrowserEditorComponent.",
UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(
EEditableEntityLabel))]
59 protected ref array<SCR_CampaignBuildingBudgetToEvaluateData>
m_aShownBudget = {};
74 bool m_changesAccumulated =
false;
79 m_accumulatedBudgetChanges[budgetType] = m_accumulatedBudgetChanges[budgetType] + amount;
81 if(!m_changesAccumulated)
83 GetGame().GetCallqueue().CallLater(ClearAccumulatedBudgetChanges);
84 m_changesAccumulated =
true;
92 bool found = m_accumulatedBudgetChanges.Find(
type, value);
101 void ClearAccumulatedBudgetChanges()
103 m_accumulatedBudgetChanges.Clear();
104 m_changesAccumulated =
false;
108 bool IsThereEnoughSupplies(
int availableSupplies,
int supplyCost,
int accumulatedSupplyCost)
110 int totalSupplyCost = supplyCost;
112 if(accumulatedSupplyCost != -1)
113 totalSupplyCost += accumulatedSupplyCost;
115 return totalSupplyCost <= availableSupplies;
119 bool IsThereEnoughBudgetToSpawn(notnull array<ref SCR_EntityBudgetValue> budgetCosts)
121 if(budgetCosts.IsEmpty())
126 foreach(SCR_EntityBudgetValue budget : budgetCosts)
136 SCR_CampaignBuildingProviderComponent realProvider =
this;
137 const int currentBudgetValue = GetBudgetValue(budgetType, realProvider);
139 const int budgetIncrease = budget.GetBudgetValue();
140 const int accumulatedBudgetChanges = realProvider.GetAccumulatedBudgetChanges(budgetType);
148 bool enoughSupplies = realProvider.IsThereEnoughSupplies(currentBudgetValue, budgetIncrease, accumulatedBudgetChanges);
160 if(maxBudgetValue == -1)
163 if(budgetIncrease + accumulatedBudgetChanges + currentBudgetValue > maxBudgetValue)
167 foreach(SCR_EntityBudgetValue budget : budgetCosts)
170 SCR_CampaignBuildingProviderComponent realProvider =
this;
173 const int currentBudgetValue = GetBudgetValue(budgetType, realProvider);
175 realProvider.AccumulateBudgetChange(budgetType, budget.GetBudgetValue());
198 SCR_ResourceComponent resource = componentToUse.GetResourceComponent();
206 float currentSupplies = consumer.GetAggregatedResourceValue();
207 return currentSupplies;
212 string GetProviderDisplayName()
214 return m_sProviderDisplayName;
219 bool UseMasterProvider()
226 bool IsMasterProvider()
232 bool UseAllAvailableProviders()
238 void SetUseAllAvailableProvidersByPlayer(
bool useByPlayer)
252 bool ObstrucViewWhenEnemyInRange()
262 array<SCR_MilitaryBaseComponent> bases = {};
263 array<SCR_CampaignBuildingProviderComponent> providers = {};
267 foreach (SCR_MilitaryBaseComponent
base : bases)
269 base.GetBuildingProviders(providers);
271 foreach (SCR_CampaignBuildingProviderComponent provider : providers)
273 if (provider.IsMasterProvider())
274 return provider.GetOwner();
283 bool UseMasterProviderBudget(
EEditableEntityBudget budget, out SCR_CampaignBuildingProviderComponent masterProviderComponent)
292 if (budgetData.GetBudget() == budget && budgetData.UseMasterProviderBudget())
298 masterProviderComponent = SCR_CampaignBuildingProviderComponent.Cast(masterProvider.
FindComponent(SCR_CampaignBuildingProviderComponent));
309 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
310 if (!playerController)
313 SCR_CampaignBuildingNetworkComponent buildingNetworkComponent = SCR_CampaignBuildingNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignBuildingNetworkComponent));
314 if (!buildingNetworkComponent)
317 buildingNetworkComponent.SetClientLock(lock, provider);
321 void SetCooldownClientLock(
bool val)
331 void SetPlayerCooldown(
int playerId,
int cooldownTime)
337 WorldTimestamp timestamp = world.GetServerTimestamp();
338 int existingEntryId = -1;
341 if (cooldownEntry.param1 != playerId)
344 if (cooldownEntry.param2.DiffMilliseconds(timestamp) * 0.001 > cooldownTime)
351 if (existingEntryId >= 0)
358 ScriptCallQueue callqueue =
GetGame().GetCallqueue();
365 void RemovePlayerCooldowns(
int playerId)
395 cooldownChange =
true;
424 if (cooldownEntry.param1 != playerId)
427 return cooldownEntry.param2.DiffMilliseconds(timestamp) * 0.001;
448 super.RegisterBase(
base);
462 array<SCR_MilitaryBaseComponent> bases = {};
475 array<SCR_MilitaryBaseComponent> bases = {};
479 foreach (SCR_MilitaryBaseComponent
base : bases)
512 if (maxValueBudgetData)
526 SCR_CampaignBuildingProviderComponent masterProviderComponent;
529 if (UseMasterProviderBudget(budgetData.
GetBudget(), masterProviderComponent))
530 return masterProviderComponent.GetMaxBudgetValue(budget);
534 if (maxValueBudgetData)
553 SCR_CampaignBuildingProviderComponent masterProviderComponent;
556 masterProviderComponent.SetPropValue(value);
568 SCR_CampaignBuildingProviderComponent masterProviderComponent;
571 masterProviderComponent.AddPropValue(value);
579 SCR_CampaignBuildingProviderComponent masterProviderComponent;
582 return masterProviderComponent.GetCurrentAIValue();
592 SCR_CampaignBuildingProviderComponent masterProviderComponent;
595 masterProviderComponent.SetAIValue(value);
605 SCR_CampaignBuildingProviderComponent masterProviderComponent;
608 masterProviderComponent.AddAIValue(value);
625 SCR_EditableCharacterComponent editableCharacter = SCR_EditableCharacterComponent.Cast(ent.
FindComponent(SCR_EditableCharacterComponent));
626 if (!editableCharacter)
629 editableCharacter.GetOnDestroyed().Insert(
OnAIRemoved);
630 editableCharacter.GetOnDeleted().Insert(
OnAIRemoved);
637 SCR_EditableCharacterComponent editableCharacter = SCR_EditableCharacterComponent.Cast(ent.
FindComponent(SCR_EditableCharacterComponent));
638 if (!editableCharacter)
641 editableCharacter.GetOnDestroyed().Remove(
OnAIRemoved);
642 editableCharacter.GetOnDeleted().Remove(
OnAIRemoved);
648 array<EEditableEntityLabel> availableTraits = {};
653 if (campaign && !campaign.GetEstablishingBasesEnabled())
657 if (!UseAllAvailableProviders())
658 return availableTraits;
660 array<SCR_MilitaryBaseComponent> bases = {};
663 return availableTraits;
665 array<SCR_CampaignBuildingProviderComponent> campaignBuildingProvides = {};
666 int providerCount = bases[0].GetBuildingProviders(campaignBuildingProvides);
668 array<EEditableEntityLabel> otherProviderAvailableTraits;
669 int providerAvailableTraitCount;
671 for (
int i = 0; i < providerCount; i++)
673 if (campaignBuildingProvides[i].UseAllAvailableProviders())
681 otherProviderAvailableTraits = campaignBuildingProvides[i].GetAvailableTraits();
682 providerAvailableTraitCount = otherProviderAvailableTraits.Count();
684 for (
int j = 0; j < providerAvailableTraitCount; j++)
686 if (!availableTraits.Contains(otherProviderAvailableTraits[j]))
688 availableTraits.Insert(otherProviderAvailableTraits[j]);
693 return availableTraits;
697 static bool CanBeUsedToEstablishBase(
IEntity provider,
int userPlayerId)
703 if (!gameMode.GetEstablishingBasesEnabled())
706 FactionAffiliationComponent affiliationComp;
707 while (provider && affiliationComp == null)
709 affiliationComp = FactionAffiliationComponent.Cast(provider.
FindComponent(FactionAffiliationComponent));
710 if (!affiliationComp)
714 if (!affiliationComp)
719 providerFaction = affiliationComp.GetDefaultAffiliatedFaction();
721 providerFaction = affiliationComp.GetAffiliatedFaction();
723 if (!providerFaction)
726 SCR_CampaignFaction campaignFaction = SCR_CampaignFaction.Cast(providerFaction);
731 return playerFaction && playerFaction == providerFaction;
739 super.OnPostInit(owner);
745 super.EOnInit(owner);
827 if (!networkComponent)
845 PlayerController playerController =
GetGame().GetPlayerController();
846 if (!playerController)
849 SCR_PlayerTeleportedFeedbackComponent playerTeleportComponent = SCR_PlayerTeleportedFeedbackComponent.Cast(playerController.FindComponent(SCR_PlayerTeleportedFeedbackComponent));
850 if (!playerTeleportComponent)
877 if (!networkComponent)
891 if (!networkComponent)
916 if (!factionComponent)
977 if (!placingComponent)
995 campaign.OnEntityRequested(editableEntity.GetOwner(), player,
SCR_Faction.Cast(GetEntityFaction(
GetOwner())),
this);
1009 if (!networkComponent)
1019 return s_OnProviderCreated;
1037 PlayerController playerController =
GetGame().GetPlayerController();
1038 if (!playerController)
1041 SCR_PlayerTeleportedFeedbackComponent playerTeleportComponent = SCR_PlayerTeleportedFeedbackComponent.Cast(playerController.FindComponent(SCR_PlayerTeleportedFeedbackComponent));
1042 if (!playerTeleportComponent)
1066 PlayerController playerController =
GetGame().GetPlayerController();
1067 if (!playerController)
1070 return SCR_CampaignBuildingNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignBuildingNetworkComponent));
1098 IEntity player =
GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID);
1108 if (!characterControllerComponent)
1111 IEntity ent = characterControllerComponent.GetOwner();
1115 return GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(ent);
1124 Faction ent1Faction = GetEntityFaction(ent1);
1128 Faction ent2Faction = GetEntityFaction(ent2);
1132 return ent1Faction == ent2Faction;
1138 FactionAffiliationComponent factionComp = FactionAffiliationComponent.Cast(ent.FindComponent(FactionAffiliationComponent));
1141 while (!factionComp && ent)
1143 ent = ent.GetParent();
1145 factionComp = FactionAffiliationComponent.Cast(ent.FindComponent(FactionAffiliationComponent));
1151 Faction faction = factionComp.GetAffiliatedFaction();
1153 faction = factionComp.GetDefaultAffiliatedFaction();
1181 [
Obsolete(
"SCR_CampaignBuildingProviderComponent.GetResourceComponent() should be used instead.")]
1193 if (budgetData.GetBudget() == budget)
1206 budgets.Insert(budgetData.GetBudget());
1209 return budgets.Count();
1222 if (budgetData.GetBudget() == blockingBudget && budgetData.CanBeUsed())
1235 if (budgetData.CanShowBudgetInUI() && !
m_aShownBudget.Contains(budgetData))
1238 return budgetData.GetBudget();
1256 if (!cooldownBudgetData)
1263 return cooldownTime;
1270 BaseGameMode gameMode =
GetGame().GetGameMode();
1274 SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
1275 if (!buildingManagerComponent)
1281 isActiveUser =
false;
1294 isActiveUser =
true;
1297 buildingManagerComponent.RemoveProvider(playerId,
this, isActiveUser);
1308 if (IsProviderDynamic())
1309 GetGame().GetCallqueue().Remove(CheckProviderMove);
1316 if (IsProviderDynamic())
1322 private void CheckProviderMove()
1324 IEntity mainParent = SCR_EntityHelper.GetMainParent(
GetOwner(),
true);
1328 Physics providerPhysics = mainParent.
GetPhysics();
1329 if (!providerPhysics)
1332 vector velocity = providerPhysics.GetVelocity();
1340 private bool IsProviderDynamic()
1342 IEntity mainParent = SCR_EntityHelper.GetMainParent(
GetOwner(),
true);
1346 Physics providerPhysics = mainParent.
GetPhysics();
1347 if (!providerPhysics)
1350 return providerPhysics.IsDynamic();
1356 bool IsEnemyFaction(notnull SCR_ChimeraCharacter
char)
1358 Faction faction =
char.GetFaction();
1362 SCR_CampaignFactionManager factionManager = SCR_CampaignFactionManager.Cast(
GetGame().GetFactionManager());
1363 if (!factionManager)
1366 Faction playerFaction = factionManager.GetLocalPlayerFaction();
1370 return playerFaction.IsFactionEnemy(faction);
1374 override bool RplLoad(ScriptBitReader reader)
1376 s_OnProviderCreated.Invoke();
1382 void ~SCR_CampaignBuildingProviderComponent()
ArmaReforgerScripted GetGame()
override bool RplLoad(ScriptBitReader reader)
SCR_BaseGameMode GetGameMode()
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
IEntity GetMasterProviderEntity()
void RequestEnterBuildingMode(IEntity provider, int playerID, bool UserActionActivationOnly, bool UserActionUsed, bool useAllAvailableProviders=false)
void SetClientLock(bool lock, IEntity provider)
SCR_ECharacterRank m_iRank
bool CanRegisterAtMilitaryBase()
SCR_CampaignSuppliesComponent GetSuppliesComponent()
override void RegisterBase(notnull SCR_MilitaryBaseComponent base)
void SetOnPlayerTeleported(int playerID)
void RemoveOnModeClosed()
void SetOnEntityKilled(IEntity ent)
Set an event called when entity spawned by this provider get killed.
EEditableEntityBudget GetShownBudget()
Evaluate all set budgets with this provider and return first one that is marked as to be shown in UI.
SCR_EditorManagerEntity GetEditorManagerByID(int playerId)
void SetCheckProviderMove()
bool m_bObstructViewWhenEnemyInRange
bool HasCooldownSet(int playerId)
Is placing allowed for this player?
void SetPropValue(int value)
SCR_CampaignMilitaryBaseComponent GetCampaignMilitaryBaseComponent()
void BuildingModeCreated()
int GetAvailableUsers(out array< int > users)
float GetBuildingRadius()
void SetOnPlayerDeathAvailableUserEvent(int userID)
bool IsBudgetToEvaluate(EEditableEntityBudget blockingBudget)
ScriptInvokerVoid GetOnCooldownLockUpdated()
bool CanBeUsedByAnyFaction()
SCR_CampaignBuildingProviderComponent m_MasterProviderComponent
void RemoveCheckProviderMove()
void RemoveActiveUser(int userID)
void RemoveActiveUsers()
Method called when the provider was destroyed or deleted to remove a provider.
void OnAvailableUserDeath(SCR_CharacterControllerComponent characterControllerComponent, IEntity instigatorEntity, notnull Instigator instigator)
void UpdateCooldownTimer()
Periodically called method to evaluate a current status of the cooldown.
SCR_MilitaryBaseComponent GetMilitaryBaseComponent()
void RemoveOnPlayerTeleported()
void SetOnPlayerDeathActiveUserEvent(int userID)
void SetOnProviderFactionChangedEvent()
Insert a method called when the provider faction is changed, e.g a base is taken by an enemy.
void AddAIValue(int value)
bool IsEntityFactionSame(notnull IEntity ent1, notnull IEntity ent2)
bool m_bUserActionActivationOnly
ref array< ref SCR_CampaignBuildingBudgetToEvaluateData > m_aBudgetsToEvaluate
void OnAIRemoved(IEntity ent)
An event called when AI spawned by this provider is killed or deleted.
ref array< int > m_aAvailableUsersIDs
void SetOnPlayerConsciousnessChanged()
Set even when player consciousness changed.
bool m_bUseAllAvailableProviders
bool ContainActiveUsers(int playerId)
int GetBudgetTypesToEvaluate(notnull out array< ref EEditableEntityBudget > budgets)
Returns all budget types to evaluate with this provider.
void PlayerTeleported(SCR_EditableCharacterComponent character, bool isLongFade, SCR_EPlayerTeleportedReason teleportReason)
SCR_ResourceComponent GetResourceComponent()
Caches and returns the resource component.
ref array< EEditableEntityLabel > m_aAvailableTraits
int GetCurrentPropValue()
const int MOVING_CHECK_PERIOD
ref ScriptInvokerVoid m_OnCooldownLockUpdated
bool GetUserActionInitOnly()
float GetCooldownValue(int playerId)
Return current value of the cooldown time for a given player.
void EntitySpawnedByProvider(int prefabID, SCR_EditableEntityComponent editableEntity)
Event rised when the entity is spawned by this provider.
ref array< SCR_CampaignBuildingBudgetToEvaluateData > m_aShownBudget
SCR_CampaignBuildingNetworkComponent GetNetworkManager()
ref array< int > m_aActiveUsersIDs
void RemoveEvents(IEntity ent)
remove all methods invoked to entity and related to it's dead or delete.
bool m_bCooldownClientLock
void SetAIValue(int value)
void RemoveAvailableUser(int userID)
array< EEditableEntityLabel > GetAvailableTraits()
int m_iCurrentAIValue
Current AI Value represents, how many AI is currently spawned with this provider. The max number is l...
bool m_bUseMasterProvider
void OnActiveUserDeath(SCR_CharacterControllerComponent characterControllerComponent, IEntity instigatorEntity, notnull Instigator instigator)
int CalculateCooldownTime(int playerId, int cooldownTime)
Checks the budget setting and calculate final cooldown time based on it.
bool ContainAvailableUsers(int playerId)
const int PROVIDER_SPEED_TO_REMOVE_BUILDING_SQ
int GetPlayerIdFromCharacterController(SCR_CharacterControllerComponent characterControllerComponent)
void AddPropValue(int value)
void OnBaseOwnerChanged(FactionAffiliationComponent owner, Faction previousFaction, Faction newFaction)
ref array< ref Tuple2< int, WorldTimestamp > > m_aPlacingCooldown
SCR_EditorManagerEntity GetEditorManager()
int GetActiveUsers(out notnull array< int > users)
SCR_ECharacterRank GetAccessRank()
int GetMaxBudgetValueFromMasterIfNeeded(EEditableEntityBudget budget)
Return max value of the given budget if this budget is added to be evaluated with this provider and h...
void AddNewActiveUser(int userID)
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 AddNewAvailableUser(int userID)
int m_iCurrentPropValue
Current props Value represents, how many entities with set prop budget can be spawned with this provi...
void RemoveOnLifeStateChanged()
SCR_CampaignBuildingBudgetToEvaluateData GetBudgetData(EEditableEntityBudget budget)
Get data of given budget.
bool m_bUseAllAvailableProvidersByPlayer
void SCR_CampaignSuppliesComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
Get all prefabs that have the spawner data
Get all prefabs that have the spawner the given labels and are valid in the editor mode param catalogType Type to catalog to get prefabs from param editorMode Editor mode to get valid entries from param faction Faction(Optional)
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
int GetBases(out array< SCR_MilitaryBaseComponent > bases)
SCR_EPlayerTeleportedReason
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
SCR_ResourceComponent m_ResourceComponent
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
proto external Physics GetPhysics()
proto external BaseWorld GetWorld()
proto external IEntity GetParent()
bool IsResourceTypeEnabled(EResourceType resourceType=EResourceType.SUPPLIES)
EEditableEntityBudget GetBudget()
override int CooldownTimeModifier(int playerId, int originalCooldown)
Modify the cooldown time based on the player rank.
OnPlayerDeathWithParamInvoker GetOnPlayerDeathWithParam()
ref OnLifeStateChangedInvoker m_OnLifeStateChanged
Core component to manage SCR_EditorManagerEntity.
SCR_EditorManagerEntity GetEditorManager()
OnFactionChangedInvoker GetOnFactionChanged()
ScriptInvoker GetOnPlaceEntityServer()
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
static IEntity GetLocalControlledEntity()
enum EPhysicsLayerPresets Vehicle
IEntity GetOwner()
Owner entity of the fuel tank.
override void EOnInit(IEntity owner)
SCR_FieldOfViewSettings Attribute
EEditorMode
Editor mode that defines overall functionality.
EntityEvent
Various entity events.
proto external PlayerController GetPlayerController()