Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
contaminatedarealoader.c
Go to the documentation of this file.
1 // This will be used to parse and load contaminated area related data
3 {
4  private static string m_Path = "$mission:cfgeffectarea.json";
5 
6  static void CreateZones()
7  {
8  JsonDataContaminatedAreas effectAreaData;
9 
10  // We confirm the contaminated area configuration file exists in mission folder
11  if ( !FileExist( m_Path ) )
12  {
13  // We fallback to check in data and notify user file was not found in mission
14  PrintToRPT("[WARNING] :: [EffectAreaLoader CreateZones] :: No contaminated area file found in MISSION folder, your path is " + m_Path + " Attempting DATA folder"); // If the path is invalid, we warn the user
15 
16  m_Path = "";
17  GetGame().GetWorldName( m_Path );
18  m_Path = string.Format("dz/worlds/%1/ce/cfgeffectarea.json", m_Path );
19 
20  if ( !FileExist( m_Path ) )
21  {
22  PrintToRPT("[WARNING] :: [EffectAreaLoader CreateZones] :: No contaminated area file found in DATA folder, your path is " + m_Path); // If the path is invalid, we warn the user
23  return; // Nothing could be read, just end here
24  }
25  }
26 
27  // We load the data from file, in case of failure we notify user
28  effectAreaData = EffectAreaLoader.GetData();
29  if ( effectAreaData )
30  {
31  // Now that we have extracted the data we go through every declared area
32  //Debug.Log("Contaminated area JSON contains : " + effectAreaData.Areas.Count());
33 
34  for ( int i = 0; i < effectAreaData.Areas.Count(); i++ )
35  {
36  EffectAreaParams params = new EffectAreaParams();
37 
38  // We feed in all relevant data
39  params.m_ParamName = effectAreaData.Areas.Get( i ).AreaName;
40  string areaType = effectAreaData.Areas.Get( i ).Type;
41  params.m_ParamTriggerType = effectAreaData.Areas.Get( i ).TriggerType;
42  JsonDataAreaData data = effectAreaData.Areas.Get( i ).Data;
43 
44  // World level area data ( Trigger info, world particles, etc... )
45  vector pos = Vector( data.Pos[0], data.Pos[1], data.Pos[2] );
46  params.m_ParamRadius = data.Radius;
47  params.m_ParamPosHeight = data.PosHeight;
48  params.m_ParamNegHeight = data.NegHeight;
49  params.m_ParamInnerRings = data.InnerRingCount;
50  params.m_ParamInnerSpace = data.InnerPartDist;
51  params.m_ParamOuterToggle = data.OuterRingToggle;
52  params.m_ParamOuterSpace = data.OuterPartDist;
53  params.m_ParamOuterOffset = data.OuterOffset;
54  params.m_ParamVertLayers = data.VerticalLayers;
55  params.m_ParamVerticalOffset = data.VerticalOffset;
56  string particleName = data.ParticleName;
57 
58  // Local level area data ( Player particles and PPE )
59  JsonDataPlayerData playerData = effectAreaData.Areas.Get( i ).PlayerData;
60  string aroundPartName = playerData.AroundPartName;
61  string tinyPartName = playerData.TinyPartName;
62  string ppeRequesterType = playerData.PPERequesterType;
63 
64  // Conversion of particle name to ID for synchronization and loading
65  if (particleName != "")
66  params.m_ParamPartId = ParticleList.GetParticleID( particleName );
67 
68  if (aroundPartName != "")
69  params.m_ParamAroundPartId = ParticleList.GetParticleID( aroundPartName );
70 
71  if (tinyPartName != "")
72  params.m_ParamTinyPartId = ParticleList.GetParticleID( tinyPartName );
73 
74  params.m_ParamPpeRequesterType = ppeRequesterType;
75 
76  EffectArea newZone; // Zones MUST inherit from EffectArea
77 
78  // We snap item position to ground before creating if specified Y is 0
79  if ( pos[1] == 0 )
80  {
81  pos[1] = GetGame().SurfaceRoadY( pos[0], pos[2] );
82  Class.CastTo( newZone, GetGame().CreateObjectEx( areaType, pos, ECE_PLACE_ON_SURFACE ) );
83  }
84  else
85  Class.CastTo( newZone, GetGame().CreateObjectEx( areaType, pos, ECE_NONE ) );
86 
87  // We created a new zone, we feed in the data to finalize setup
88  if ( newZone )
89  newZone.SetupZoneData( params );
90  else
91  Error("[WARNING] :: [EffectAreaLoader CreateZones] :: Cast failed, are you sure your class ( 'Type:' ) inherits from EffectArea and that there are no Typos?");
92  }
93  }
94  else
95  Error("[WARNING] :: [EffectAreaLoader CreateZones] :: Data could not be read, please check data and syntax"); // Most JSON related errors should be handled, but we have an extra check in case data could not be read
96  }
97 
98  static JsonDataContaminatedAreas GetData()
99  {
100  string errorMessage;
102  if (!JsonFileLoader<JsonDataContaminatedAreas>.LoadFile(m_Path, data, errorMessage))
103  ErrorEx(errorMessage);
104 
105  return data;
106  }
107 }
GetGame
proto native CGame GetGame()
JsonDataContaminatedAreas
Definition: jsondatacontaminatedarea.c:2
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
FileExist
proto bool FileExist(string name)
Check existence of file.
ECE_PLACE_ON_SURFACE
const int ECE_PLACE_ON_SURFACE
Definition: centraleconomy.c:37
ErrorEx
enum ShapeType ErrorEx
EffectArea
Definition: effectarea.c:36
EffectAreaLoader
Definition: contaminatedarealoader.c:2
ParticleList
Definition: particlelist.c:11
vector
Definition: enconvert.c:105
ECE_NONE
const int ECE_NONE
Definition: centraleconomy.c:7
PrintToRPT
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
JsonDataAreaData
Definition: jsondatacontaminatedarea.c:17
JsonDataPlayerData
Definition: jsondatacontaminatedarea.c:33
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.