DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
RebuildingSpawner.c
См. документацию.
1#ifdef DIAG_DEVELOPER
2class RebuildingSpawner
3{
4 static PlayerBase m_Player;
5 static EntityAI m_Rebuidable;
6 static ref array<string> m_AllRebuildableTypes;
7 static ref array<string> m_RebuildableTypesUsed = {};
8 static float m_Delay = 3000.0; //ms
9 static float m_Dist = 10.0; //m
10 static int m_LastIdx = -1;
11 static bool m_IsSpawned;
12 static bool m_Loop;
13 static vector m_SpawnPos;
14
15 static int m_DbgLockCounter;
16
17 static void StartRebuildablesSpawning(bool loop = false, array<string> overrides = null)
18 {
19 //in case you also doubleclick by accident
20 StopRebuildablesSpawning();
21
22 if (!overrides)
23 {
24 if (!m_AllRebuildableTypes)
25 InitAllRebuildableTypes();
26
27 m_RebuildableTypesUsed.Copy(m_AllRebuildableTypes);
28 }
29 else
30 {
31 m_RebuildableTypesUsed.Copy(overrides);
32 }
33
34 if (g_Game.IsDedicatedServer())
35 m_Player = PlayerBase.Cast(g_Game.GetPlayerByIndex());
36 else
37 m_Player = PlayerBase.Cast(g_Game.GetPlayer());
38 m_SpawnPos = m_Player.GetPosition() + m_Player.GetDirection() * m_Dist;
39
40 m_LastIdx = -1;
41 m_Loop = loop;
42 if (m_Rebuidable)
43 m_Rebuidable.DeleteSafe();
44 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(ProcessRebuildablesSpawning, m_Delay);
45 }
46
47 static void StopRebuildablesSpawning()
48 {
49 if (m_Rebuidable)
50 m_Rebuidable.DeleteSafe();
51 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(ProcessRebuildablesSpawning);
52 }
53
55
56 protected static void InitAllRebuildableTypes()
57 {
58 string basePath = "cfgVehicles";
59 string typeName;
60 m_AllRebuildableTypes = new array<string>();
61 int count = g_Game.ConfigGetChildrenCount(basePath);
62 for (int q = 0; q < count; ++q)
63 {
64 g_Game.ConfigGetChildName(basePath, q, typeName);
65 string cfgPath = "cfgVehicles " + typeName + " Construction";
66 if (g_Game.ConfigIsExisting(cfgPath) && !g_Game.IsKindOf(typeName, "BaseBuildingBase"))
67 m_AllRebuildableTypes.Insert(typeName);
68 }
69 }
70
71 protected static void ProcessRebuildablesSpawning()
72 {
73 if (m_Rebuidable)
74 {
75 m_Rebuidable.DeleteSafe();
76
77 if (m_LastIdx >= m_RebuildableTypesUsed.Count() - 1)
78 {
79 if (m_Loop)
80 m_LastIdx = -1;
81 else
82 return;
83 }
84 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(ProcessRebuildablesSpawning, m_Delay);
85 }
86 else
87 {
88 ++m_LastIdx;
89 if (m_LastIdx >= m_RebuildableTypesUsed.Count())
90 return;
91
92 SpawnAndRebuildAllParts(m_RebuildableTypesUsed[m_LastIdx]);
93 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(ProcessRebuildablesSpawning, m_Delay);
94 }
95 }
96
97 protected static void SpawnAndRebuildAllParts(string type)
98 {
99 m_Rebuidable = EntityAI.Cast(g_Game.CreateObjectEx(type, m_SpawnPos, ECE_PLACE_ON_SURFACE));
100 ConstructionBase con = ConstructionBase.Cast(m_Rebuidable.GetConstructionBasic());
101 map<string, ref ConstructionPart> partsMap = con.GetConstructionParts(); //simple array under define, too lazy to solve now
102 foreach (string name, ref ConstructionPart part : partsMap)
103 {
104 con.BuildPartServerEx(null, name, -1);
105 }
106 }
107
108 static void RebuildAllWoodenPartsFiltered(ConstructionBase con, EntityAI ent)
109 {
110 TStringArray wallsDoored = new TStringArray();
111 TStringArray wallsWindowed = new TStringArray();
112 TStringArray wallsSimple = new TStringArray();
113 TStringArray doors = new TStringArray();
114 TStringArray windows = new TStringArray();
115
116 string tmp;
117 GetCLIParam("RBLDRebuildEverythingWithLocks", tmp);
118 int maxTotalLockCount = tmp.ToInt();
119 GameInventory inv = ent.GetInventory();
120
121 //Print("DbgLocks | Entity: " + ent + " | lock count: " + (RebuildingSpawner.m_DbgLockCounter - 1));
122 //go through all parts first, directly build the simple ones
123 array<ConstructionPart> constructionPartArray = con.GetConstructionPartArray();
124 foreach (ConstructionPart part : constructionPartArray)
125 {
126 if (part.IsUtilityPart())
127 continue;
128
129 string partName = part.GetPartName();
130 if (partName.Contains("rubble") || partName.Contains("roof"))
131 {
132 con.BuildPartServerEx(null, partName, -1);
133 continue;
134 }
135
136 if (!partName.Contains("_wood"))
137 continue;
138
139 if (partName.Contains("wall"))
140 {
141 if (partName.Contains("_window_"))
142 wallsWindowed.Insert(partName);
143 if (partName.Contains("_door_"))
144 wallsDoored.Insert(partName);
145 else
146 wallsSimple.Insert(partName);
147 }
148 else if (partName.Contains("door"))
149 {
150 doors.Insert(partName);
151 }
152 else if (partName.Contains("window"))
153 {
154 windows.Insert(partName);
155 }
156 }
157
158 //1. walls with doors
159 foreach (string wallWithDoors : wallsDoored)
160 {
161 if (!con.HasConflictPart(wallWithDoors))
162 con.BuildPartServerEx(null, wallWithDoors, -1);
163 }
164
165 //2. walls with windows
166 foreach (string wallWithWindows : wallsWindowed)
167 {
168 if (!con.HasConflictPart(wallWithWindows))
169 con.BuildPartServerEx(null, wallWithWindows, -1);
170 }
171
172 //3. simple walls
173 foreach (string wallSimple : wallsSimple)
174 {
175 if (!con.HasConflictPart(wallSimple))
176 con.BuildPartServerEx(null, wallSimple, -1);
177 }
178
179 //4. doors
180 foreach (string door : doors)
181 {
182 if (!con.HasConflictPart(door) && con.HasRequiredPart(door)) //later parts need to check requirements too
183 {
184 con.BuildPartServerEx(null, door, -1);
185
186 if (m_DbgLockCounter > maxTotalLockCount)
187 continue;
188
189 int idx1 = door.IndexOf("door") + 4;
190 int idx2 = door.IndexOf("_wood");
191 string attSlotName = door.Substring(idx1, idx2 - idx1); //slot number
192 attSlotName = string.Format("Att_CodeLock%1_Wood", attSlotName);
193 int slotID = InventorySlots.GetSlotIdFromString(attSlotName);
194 DigitalCodeLock lock;
195
196 if (Class.CastTo(lock, inv.FindAttachment(slotID))) //found old
197 {
198 ++m_DbgLockCounter;
199 }
200 else if (!lock && Class.CastTo(lock, inv.CreateAttachmentEx("DigitalCodeLock", slotID))) //or spawned new
201 {
202 ++m_DbgLockCounter;
203 lock.OnDebugSpawn();
204 }
205 }
206 }
207
208 //5. windows
209 foreach (string window : windows)
210 {
211 if (!con.HasConflictPart(door) && con.HasRequiredPart(window)) //later parts need to check requirements too
212 con.BuildPartServerEx(null, window, -1);
213 }
214 }
215}
216#endif
class LogManager EntityAI
const int ECE_PLACE_ON_SURFACE
Определения CentralEconomy.c:38
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
void DigitalCodeLock()
Определения CodeLock.c:590
void ConstructionBase(EntityAI parent)
Определения ConstructionBase.c:58
void ConstructionPart(string name, string part_name, string main_part_name, int id, bool is_built, bool is_base, bool is_gate, array< string > required_parts)
Определения ConstructionPart.c:531
map
Определения ControlsXboxNew.c:4
DayZGame g_Game
Определения DayZGame.c:4074
class Explosion m_Delay
DayZPlayer m_Player
Определения Hand_Events.c:42
override void OnDebugSpawn()
Определения CodeLock.c:561
proto native EntityAI CreateAttachmentEx(string typeName, int slotId)
Create Entity of specified type as attachment of entity.
proto native EntityAI FindAttachment(int slot)
Returns attached entity in slot (you can use InventorySlots.GetSlotIdFromString(name) to get slot id)
class array< Class T > TStringArray
proto native int ToInt()
Converts string to integer.
proto void Insert(int index, string input)
Inserts a string into the n-th index, increasing the string length by the size of the input.
bool Contains(string sample)
Returns true if sample is substring of string.
Определения EnString.c:286
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.
proto bool GetCLIParam(string param, out string val)
Returns command line argument.
const int CALL_CATEGORY_SYSTEM
Определения 3_Game/DayZ/tools/tools.c:8