1 [
EntityEditorProps(
category:
"GameScripted/Building", description:
"Component attached to a composition layout, holding information about the final composition to be built")]
8 [
RplProp(onRplName:
"SpawnPreviewIfBuildingModeOpened")]
12 protected int m_iToBuildValue;
16 protected float m_fCurrentBuildValue;
20 protected const static int EMPTY_BUILDING_VALUE = 0;
21 protected static const int INVALID_PREFAB_ID = -1;
48 if (editorManagerEntity)
55 return editorManagerEntity !=
null;
62 if (!m_OnAddBuildingValueInt)
65 return m_OnAddBuildingValueInt;
72 if (!m_OnAddBuildingValueVoid)
75 return m_OnAddBuildingValueVoid;
82 if (!m_OnCompositionIdSet)
85 return m_OnCompositionIdSet;
106 SCR_CampaignBuildingEditorComponent buildingEditorComponent = SCR_CampaignBuildingEditorComponent.Cast(editorModeEntity.FindComponent(SCR_CampaignBuildingEditorComponent));
107 if (!buildingEditorComponent)
110 SCR_CampaignBuildingProviderComponent providerComponent = SCR_CampaignBuildingProviderComponent.Cast(buildingEditorComponent.GetProviderComponent());
111 if (!providerComponent)
114 return vector.DistanceSq(
GetOwner().
GetOrigin(), providerComponent.GetOwner().GetOrigin()) <= providerComponent.GetBuildingRadius() * providerComponent.GetBuildingRadius();
130 if (DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_CAMPAIGN_INSTANT_BUILDING))
138 if (currentBuildValue < m_iToBuildValue)
152 if (resName.IsEmpty())
153 return EMPTY_BUILDING_VALUE;
156 if (!buildingManagerComponent)
157 return EMPTY_BUILDING_VALUE;
161 return EMPTY_BUILDING_VALUE;
163 return outlineManager.GetCompositionBuildingValue(resName);
173 if (!buildingManagerComponent)
176 return buildingManagerComponent.GetCompositionResourceName(prefabID);
182 BaseGameMode gameMode =
GetGame().GetGameMode();
186 return SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
197 if (m_OnCompositionIdSet)
198 m_OnCompositionIdSet.Invoke(prefabId);
202 Replication.BumpMe();
216 IEntity ent =
GetOwner().GetRootParent();
220 SCR_EditorLinkComponent linkComponent = SCR_EditorLinkComponent.Cast(ent.FindComponent(SCR_EditorLinkComponent));
224 linkComponent.SpawnComposition();
229 EntitySpawnParams spawnParams =
new EntitySpawnParams;
230 ent.GetWorldTransform(spawnParams.Transform);
249 IEntity ent =
GetOwner().GetRootParent();
254 if (resName.IsEmpty())
257 Resource res = Resource.Load(resName);
261 BaseGameMode gameMode =
GetGame().GetGameMode();
265 SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
266 if (!buildingManagerComponent)
269 EntitySpawnParams spawnParams =
new EntitySpawnParams();
270 spawnParams.TransformMode = ETransformMode.WORLD;
271 ent.GetWorldTransform(spawnParams.Transform);
273 m_PreviewEntity =
SCR_PrefabPreviewEntity.SpawnPreviewFromPrefab(res,
"SCR_PrefabPreviewEntity", ent.GetWorld(), spawnParams,
"{58F07022C12D0CF5}Assets/Editor/PlacingPreview/Preview.emat");
278 ent.AddChild(
m_PreviewEntity, -1, EAddChildFlags.RECALC_LOCAL_TRANSFORM);
287 if (!characterController)
290 characterController.GetOnPlayerDeath().Insert(
DeletePreview);
301 if (modeEntity.IsOpened())
314 if (!characterController)
317 characterController.GetOnPlayerDeath().Remove(
DeletePreview);
332 m_fCurrentBuildValue += value;
333 m_fCurrentBuildValue = Math.Clamp(m_fCurrentBuildValue, 0, m_iToBuildValue);
335 if (m_OnAddBuildingValueInt)
336 m_OnAddBuildingValueInt.Invoke(m_fCurrentBuildValue);
338 if (m_OnAddBuildingValueVoid)
339 m_OnAddBuildingValueVoid.Invoke();
341 Replication.BumpMe();
349 newValue = Math.Clamp(newValue, 0, m_iToBuildValue);
350 m_fCurrentBuildValue = newValue;
352 if (m_OnAddBuildingValueInt)
353 m_OnAddBuildingValueInt.Invoke(m_fCurrentBuildValue);
355 if (m_OnAddBuildingValueVoid)
356 m_OnAddBuildingValueVoid.Invoke();
358 Replication.BumpMe();
365 return m_iToBuildValue;
372 return m_fCurrentBuildValue;
388 return editorManager.FindModeEntity(
EEditorMode.BUILDING);
396 IEntity rootEnt =
GetOwner().GetRootParent();
400 SCR_CampaignBuildingCompositionComponent compositionComponent = SCR_CampaignBuildingCompositionComponent.Cast(rootEnt.FindComponent(SCR_CampaignBuildingCompositionComponent));
401 if (!compositionComponent)
404 compositionComponent.SetInteractionLockServer(
true);
415 Math3D.MatrixIdentity4(transform);
417 transform[3] = entity.GetOrigin();
419 BaseWorld world =
GetGame().GetWorld();
423 transform[3][1] = world.GetSurfaceY(transform[3][0], transform[3][2]);
424 entity.SetTransform(transform);
430 super.OnChildAdded(parent, child);
433 RplComponent rplComp = RplComponent.Cast(
GetOwner().FindComponent(RplComponent));
434 if (!rplComp || rplComp.IsProxy())