Advertisement
Thatguy5532

Initial Town Manager

Jun 26th, 2024
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.83 KB | Source Code | 0 0
  1. class LIB_TownManagerComponentClass : ScriptComponentClass
  2. {
  3. };
  4.  
  5. class LIB_TownData : Managed
  6. {
  7.     EntityID markerID;
  8.     string name;
  9.     int population;
  10.     int stability;
  11.     int support;
  12.     string faction;
  13.     int size;
  14. }
  15.  
  16. class LIB_TownManagerComponent : ScriptComponent
  17. {
  18.     protected static ref array<IEntity> m_ObjArr = {};
  19.     protected static ref array<IEntity> m_objMarkerArr = {};
  20.  
  21.     //------------------------------------------------------------------------------------------------
  22.     override void EOnInit(IEntity owner)
  23.     {
  24.         //Print(owner.GetName());
  25.         if (GetGame().InPlayMode()) {
  26.             SCR_MapDescriptorComponent MapD = SCR_MapDescriptorComponent.Cast(owner.FindComponent(SCR_MapDescriptorComponent));
  27.            
  28.             if (IsObj(owner, MapD))
  29.             {
  30.                 m_ObjArr.Insert(owner);
  31.                 IEntity MarkerEnt = CreateObjMarker(owner);
  32.                 CreateObjArea(owner);
  33.                 m_objMarkerArr.Insert(MarkerEnt);
  34.             }
  35.         }
  36.        
  37.        
  38.     }
  39.    
  40.     bool IsObj(IEntity owner, SCR_MapDescriptorComponent MapD)
  41.     {
  42.         switch(MapD.GetBaseType())
  43.         {
  44.             case EMapDescriptorType.MDT_PORT:
  45.                 return true;
  46.                 break;
  47.            
  48.             case EMapDescriptorType.MDT_BASE:
  49.                 return true;
  50.                 break;
  51.            
  52.             case EMapDescriptorType.MDT_FORTRESS:
  53.                 return true;
  54.                 break;
  55.            
  56.             case EMapDescriptorType.MDT_FUELSTATION:
  57.                 return true;
  58.                 break;
  59.            
  60.             case EMapDescriptorType.MDT_NAME_GENERIC:
  61.                 return true;
  62.                 break;
  63.            
  64.             case EMapDescriptorType.MDT_NAME_CITY:
  65.                 return true;
  66.                 break;
  67.            
  68.             case EMapDescriptorType.MDT_NAME_VILLAGE:
  69.                 return true;
  70.                 break;
  71.            
  72.             case EMapDescriptorType.MDT_NAME_TOWN:
  73.                 return true;
  74.                 break;
  75.            
  76.             case EMapDescriptorType.MDT_NAME_SETTLEMENT:
  77.                 return true;
  78.                 break;
  79.         }
  80.         return false;
  81.     }
  82.  
  83.     //------------------------------------------------------------------------------------------------
  84.     override void OnPostInit(IEntity owner)
  85.     {
  86.         // remove if unused
  87.         SetEventMask(owner, EntityEvent.INIT);
  88.     }
  89.  
  90.     //------------------------------------------------------------------------------------------------
  91.     override void OnDelete(IEntity owner)
  92.     {
  93.         // remove if unused
  94.         SCR_MapDescriptorComponent MapD = SCR_MapDescriptorComponent.Cast(owner.FindComponent(SCR_MapDescriptorComponent));
  95.         if (m_ObjArr) {
  96.             m_ObjArr.RemoveItem(owner)
  97.         }
  98.     }
  99.     //------------------------------------------------------------------------------------------------
  100.     static IEntity GetRandObj()
  101.     {
  102.         if (m_ObjArr.IsEmpty()) {
  103.             return null;
  104.         };
  105.        
  106.         return m_ObjArr.GetRandomElement();
  107.     }
  108.    
  109.     static array<IEntity> GetObjArr()
  110.     {
  111.         if (m_ObjArr.IsEmpty()) {
  112.             return null;
  113.         };
  114.        
  115.         return m_ObjArr;
  116.     }
  117.    
  118.     IEntity CreateObjMarker(IEntity owner)
  119.     {
  120.         Print("Create Obj Marker");
  121.        
  122.         IEntity slotMarker = GetGame().SpawnEntityPrefab("{E537867C6E760514}Prefabs/ScenarioFramework/Components/Marker Entities/SlotMarker.et", false);
  123.         LIB_ScenarioFrameworkSlotMarker markerComp = LIB_ScenarioFrameworkSlotMarker.Cast(slotMarker.FindComponent(LIB_ScenarioFrameworkSlotMarker));
  124.         SCR_MapDescriptorComponent MapD = SCR_MapDescriptorComponent.Cast(owner.FindComponent(SCR_MapDescriptorComponent));
  125.        
  126.        
  127.         slotMarker.SetOrigin(owner.GetOrigin());
  128.         //Print(slotMarker);
  129.         //Print(markerComp);
  130.         markerComp.SetScriptSpawned(true);
  131.         Print(MapD.GetBaseType());
  132.         switch(MapD.GetBaseType())
  133.         {
  134.             case EMapDescriptorType.MDT_PORT:
  135.                 markerComp.SetMapMarkerIcon(LIB_EScenarioFrameworkMarkerCustom.FUELSTATION);
  136.                 PrintFormat("MDT_PORT: %1", LIB_EScenarioFrameworkMarkerCustom.FUELSTATION);
  137.                 break;
  138.            
  139.             case EMapDescriptorType.MDT_BASE:
  140.                 markerComp.SetMapMarkerIcon(LIB_EScenarioFrameworkMarkerCustom.MILITARY);
  141.                 PrintFormat("MDT_BASE: %1", LIB_EScenarioFrameworkMarkerCustom.MILITARY);
  142.                 break;
  143.            
  144.             case EMapDescriptorType.MDT_FORTRESS:
  145.                 markerComp.SetMapMarkerIcon(LIB_EScenarioFrameworkMarkerCustom.MILITARY);
  146.                 PrintFormat("MDT_FORTRESS: %1", LIB_EScenarioFrameworkMarkerCustom.MILITARY);
  147.                 break;
  148.            
  149.             case EMapDescriptorType.MDT_FUELSTATION:
  150.                 markerComp.SetMapMarkerIcon(LIB_EScenarioFrameworkMarkerCustom.FUELSTATION);
  151.                 PrintFormat("MDT_FUELSTATION: %1", LIB_EScenarioFrameworkMarkerCustom.FUELSTATION);
  152.                 break;
  153.            
  154.             case EMapDescriptorType.MDT_NAME_GENERIC:
  155.                 markerComp.SetMapMarkerIcon(LIB_EScenarioFrameworkMarkerCustom.TOWN);
  156.                 PrintFormat("MDT_NAME_GENERIC: %1", LIB_EScenarioFrameworkMarkerCustom.TOWN);
  157.                 break;
  158.            
  159.             case EMapDescriptorType.MDT_NAME_CITY:
  160.                 markerComp.SetMapMarkerIcon(LIB_EScenarioFrameworkMarkerCustom.CAPITAL);
  161.                 PrintFormat("MDT_NAME_CITY: %1", LIB_EScenarioFrameworkMarkerCustom.CAPITAL);
  162.                 break;
  163.            
  164.             case EMapDescriptorType.MDT_NAME_VILLAGE:
  165.                 markerComp.SetMapMarkerIcon(LIB_EScenarioFrameworkMarkerCustom.TOWN);
  166.                 PrintFormat("MDT_NAME_VILLAGE: %1", LIB_EScenarioFrameworkMarkerCustom.TOWN);
  167.                 break;
  168.            
  169.             case EMapDescriptorType.MDT_NAME_TOWN:
  170.                 markerComp.SetMapMarkerIcon(LIB_EScenarioFrameworkMarkerCustom.TOWN);
  171.                 PrintFormat("MDT_NAME_TOWN: %1", LIB_EScenarioFrameworkMarkerCustom.TOWN);
  172.                 break;
  173.            
  174.             case EMapDescriptorType.MDT_NAME_SETTLEMENT:
  175.                 markerComp.SetMapMarkerIcon(LIB_EScenarioFrameworkMarkerCustom.TOWN);
  176.                 PrintFormat("MDT_NAME_SETTLEMENT: %1", LIB_EScenarioFrameworkMarkerCustom.TOWN);
  177.                 break;
  178.         }
  179.        
  180.         markerComp.SetMapMarkerColor(LIB_EScenarioFrameworkMarkerCustomColor.BLUFOR);
  181.         markerComp.SetMapMarkerText(owner.GetName());
  182.         markerComp.CreateMapMarker();
  183.        
  184.         return slotMarker;
  185.     }
  186.    
  187.     // {C72F956E4AC6A6E7}Prefabs/ScenarioFramework/Components/Area.et
  188.     void CreateObjArea(IEntity owner)
  189.     {
  190.         //IEntity Area = GetGame().SpawnEntityPrefab("{C72F956E4AC6A6E7}Prefabs/ScenarioFramework/Components/Area.et", false);
  191.         //SCR_ScenarioFrameworkArea AreaComp = SCR_ScenarioFrameworkArea.Cast(Area.FindComponent(SCR_ScenarioFrameworkArea));
  192.         //Area.SetOrigin(owner.GetOrigin());
  193.        
  194.        
  195.     }
  196. };
  197.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement