Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignBaseTask.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4 };
5 
6 //------------------------------------------------------------------------------------------------
10 {
11 
12  const int MIN_OFFSET = 3;
13  const int MAX_OFFSET = 80;
14  //**************************//
15  //PROTECTED MEMBER VARIABLES//
16  //**************************//
17 
18  protected SCR_CampaignMilitaryBaseComponent m_TargetBase = null;
19  protected int m_iTargetBaseId = -1;
20 
21  //*********************//
22  //PUBLIC MEMBER METHODS//
23  //*********************//
24 
25  //------------------------------------------------------------------------------------------------
26  int GetTargetBaseId()
27  {
28  return m_iTargetBaseId;
29  }
30 
31  //------------------------------------------------------------------------------------------------
36  void SetTargetBase(notnull SCR_CampaignMilitaryBaseComponent targetBase)
37  {
38  if (SCR_MapEntity.GetMapInstance())
39  {
40  SCR_MapEntity.GetOnMapZoom().Insert(OnMapZoom);
41  SCR_MapEntity.GetOnMapOpen().Insert(OnMapOpenCallback);
42  }
43 
44  m_TargetBase = targetBase;
45  m_bIsPriority = (SCR_CampaignFaction.Cast(m_TargetFaction).GetPrimaryTarget() == targetBase);
46  SetOrigin(m_TargetBase.GetOwner().GetOrigin());
47  CreateMapUIIcon();
48  UpdateMapInfo();
49  SetHUDIcon();
50  }
51 
52  //------------------------------------------------------------------------------------------------
53  void OnMapOpenCallback(MapConfiguration config)
54  {
55  SetOffset();
56  }
57 
58  //------------------------------------------------------------------------------------------------
59  void OnMapZoom(float pixelPerUnit)
60  {
61  SetOffset();
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  // Temporary method to set offset of task marker from base marker. Once we have a proper solution for the map, this can be deleted.
66  void SetOffset()
67  {
68  vector newPos = m_TargetBase.GetOwner().GetOrigin();
69  newPos[0] = newPos[0] + CalculateOffset() / 2.5;
70  newPos[2] = newPos[2] - CalculateOffset() / 5;
71  SetOrigin(newPos);
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  // Temporary method to set offset of task marker from base marker. Once we have a proper solution for the map, this can be deleted.
76  float CalculateOffset()
77  {
78  float pixelPerUnit = SCR_MapEntity.GetMapInstance().GetCurrentZoom();
79  int max_offset = MAX_OFFSET;
80  int min_offset = MIN_OFFSET;
81  float min_zoom = SCR_MapConstants.MAX_PIX_PER_METER;
82  float max_zoom = SCR_MapEntity.GetMapInstance().GetMinZoom();
83 
84  float a = max_offset * min_offset * (max_zoom - min_zoom) / (min_offset - max_offset);
85  float b = min_zoom - a / min_offset;
86 
87  return b + a / pixelPerUnit;
88  }
89 
90  //------------------------------------------------------------------------------------------------
91  string GetBaseNameWithCallsign()
92  {
93  if (m_TargetBase.GetType() == SCR_ECampaignBaseType.RELAY)
94  return m_TargetBase.GetBaseNameUpperCase();
95  return string.Format("%1 (%2)", m_TargetBase.GetBaseNameUpperCase(), m_TargetBase.GetCallsignDisplayNameOnlyUC());
96  }
97 
98  //------------------------------------------------------------------------------------------------
103  SCR_CampaignMilitaryBaseComponent GetTargetBase()
104  {
105  return m_TargetBase;
106  }
107 
108  //******************************//
109  //PUBLIC OVERRIDE MEMBER METHODS//
110  //******************************//
111 
112  //------------------------------------------------------------------------------------------------
113  override void Deserialize(ScriptBitReader reader)
114  {
115  super.Deserialize(reader);
116 
117  int baseID;
118  reader.ReadInt(baseID);
119 
120  SCR_CampaignMilitaryBaseComponent base = SCR_GameModeCampaign.GetInstance().GetBaseManager().FindBaseByCallsign(baseID);
121 
122  if (!base)
123  {
124  m_iTargetBaseId = baseID;
125  return;
126  }
127 
128  if (base.GetFaction() == GetTargetFaction())
129  return;
130 
131  SetTargetBase(base);
132  }
133 
134  //------------------------------------------------------------------------------------------------
135  override void Serialize(ScriptBitWriter writer)
136  {
137  super.Serialize(writer);
138 
139  int baseID = -1;
140  SCR_CampaignMilitaryBaseComponent base = GetTargetBase();
141  if (base)
142  baseID = base.GetCallsign();
143 
144  writer.WriteInt(baseID);
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  protected override void UpdateMapInfo()
149  {
150  //Insert task icon into base's map UI
151  //m_TargetBase cannot be null here
152  }
153 };
SCR_BaseTaskClass
Definition: SCR_BaseTask.c:2
SCR_CampaignBaseTaskClass
Definition: SCR_CampaignBaseTask.c:2
SCR_CampaignBaseTask
Definition: SCR_CampaignBaseTask.c:9
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
SCR_ECampaignBaseType
SCR_ECampaignBaseType
Definition: SCR_CampaignMilitaryBaseComponent.c:2577
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
m_TargetFaction
protected Faction m_TargetFaction
Definition: SCR_EditableTaskComponent.c:22
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_CampaignFaction
Definition: SCR_CampaignFaction.c:2
SCR_MapConstants
Definition: SCR_MapConstants.c:2
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38