Rise
The Vieneo Province
waypoints.cpp
Go to the documentation of this file.
1 #include "waypoints.h"
2 #include "Viewscreen.h"
3 
5 {
6  gameclass = prmGameClass;
7 }
8 
9 void waypoints::Update(Swaypoint waypoint) const
10 {
11  Upload(waypoint);
12 }
13 
15 {
16  SClientPacket outpacket;
17  outpacket.type = 37; // waypoint management
18  outpacket.f_x = 2.0f; // request all data
19  outpacket.f_y = 0.0f; // no specific waypoint ID
20  outpacket.f_z = 0.0f; // NULL
21  outpacket.f_w = 0.0f; // NULL
22  gameclass->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
23 }
24 
25 void waypoints::Sort(short sortfield, char sortdirection, int* linecursel, int* lineact) const
26 {
27  gameclass->logger->AddToCallStack("waypoints::Sort");
28 
29  if (gameclass->bus->waypoint.size() < 2) return;
30 
31  bool swapflag;
32  do
33  {
34  swapflag = false;
35  for (unsigned s = 1; s < (gameclass->bus->waypoint.size() - 1); s++)
36  {
37  bool flip = false;
38  if (sortfield == 1) // description
39  {
40  if (sortdirection == 1)
41  {
42  if (_stricmp(gameclass->bus->waypoint.at(s).text, gameclass->bus->waypoint.at(s + 1).text) > 0)
43  flip = true;
44  }
45  else
46  {
47  if (_stricmp(gameclass->bus->waypoint.at(s).text, gameclass->bus->waypoint.at(s + 1).text) < 0)
48  flip = true;
49  }
50  }
51  else if (sortfield == 3) // distance
52  {
53  D3DXVECTOR3 result = playerships[0].position - gameclass->bus->waypoint.at(s).location;
54  float thisdist = D3DXVec3Length(&result);
55  result = playerships[0].position - gameclass->bus->waypoint.at(s + 1).location;
56  float nextdist = D3DXVec3Length(&result);
57 
58  if (sortdirection == 1)
59  {
60  if (thisdist > nextdist)
61  flip = true;
62  }
63  else
64  {
65  if (thisdist < nextdist)
66  flip = true;
67  }
68  }
69  if (flip)
70  {
71  const Swaypoint tempwaypoint = gameclass->bus->waypoint.at(s);
72  gameclass->bus->waypoint.at(s) = gameclass->bus->waypoint.at(s + 1);
73  gameclass->bus->waypoint.at(s + 1) = tempwaypoint;
74  if (gameclass->bus->WPtargetC == s)
75  gameclass->bus->WPtargetC = s + 1;
76  else if (gameclass->bus->WPtargetC == (s + 1))
77  gameclass->bus->WPtargetC = s;
78  if (*linecursel == s)
79  *linecursel = s + 1;
80  else if (*linecursel == (s + 1))
81  *linecursel = s;
82  if (*lineact == s)
83  *lineact = s + 1;
84  else if (*lineact == (s + 1))
85  *lineact = s;
86  swapflag = true;
87  }
88  }
89  } while (swapflag);
90 
91  if (gameclass->bus->WPtargetC < 0 || gameclass->bus->WPtargetC >= static_cast<long>(gameclass->bus->waypoint.size()))
92  {
93  char msg[99];
94  sprintf_s(msg, 99, "Found the problem WPtargetC %i because of flip!", gameclass->bus->WPtargetC);
95  gameclass->logger->Log(msg, Logger::Level::Error);
96  gameclass->bus->WPtargetC = 0;
97  }
98 }
99 
100 void waypoints::Delete(int index) const
101 {
102  if (index == 0)
103  ZeroMemory(&gameclass->bus->waypoint.at(0), sizeof Swaypoint);
104  else // delete from list
105  {
106  SClientPacket outpacket;
107  outpacket.type = 37; // Waypoint management
108  outpacket.f_x = 1.0f; // delete
109  outpacket.f_y = static_cast<float>(gameclass->bus->waypoint.at(index).id);
110  outpacket.f_z = 0.0f;
111  outpacket.f_w = 0.0f;
112  gameclass->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
113 
114  gameclass->bus->waypoint.erase(gameclass->bus->waypoint.begin() + index);
115 
116  if (index == gameclass->bus->WPtargetC)
117  gameclass->bus->WPtargetC = 0;
118  else
119  gameclass->bus->WPtargetC--;
120  if (gameclass->bus->WPtargetC < 0)
121  gameclass->bus->WPtargetC = 0;
122 
123  outpacket.type = 37; // Waypoint management
124  outpacket.f_x = 0.0f; // set
125  outpacket.f_y = static_cast<float>(gameclass->bus->waypoint.at(gameclass->bus->WPtargetC).id);
126  outpacket.f_z = 0.0f;
127  outpacket.f_w = 0.0f;
128  gameclass->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
129  }
130 }
131 
132 void waypoints::AddOrUpdate(Swaypoint tempwaypoint) const
133 {
135  for (unsigned t = 1; t < gameclass->bus->waypoint.size(); t++)
136  {
137  if (gameclass->bus->waypoint.at(t).id == tempwaypoint.id)
138  {
139  char msg[99];
140  sprintf_s(msg, 99, "Found received waypoint at %i, updating (%i)!", t, tempwaypoint.id);
141  gameclass->logger->Log(msg);
142  gameclass->bus->waypoint.at(t) = tempwaypoint;
143  return;
144  }
145  }
146  char msg[99];
147  sprintf_s(msg, 99, "Could not find received waypoint, adding (%i)!", tempwaypoint.id);
148  gameclass->logger->Log(msg);
149  gameclass->bus->waypoint.emplace_back(tempwaypoint);
150 }
151 
152 short waypoints::Find(int id) const
153 {
155  for (unsigned t = 1; t < gameclass->bus->waypoint.size(); t++)
156  {
157  if (gameclass->bus->waypoint.at(t).id == id)
158  return t;
159  }
160  return 0;
161 }
162 
163 short waypoints::FindByUniqueId(int uniqueId) const
164 {
166  for (unsigned t = 1; t < gameclass->bus->waypoint.size(); t++)
167  {
168  if (gameclass->bus->waypoint.at(t).uniqueid == uniqueId)
169  return t;
170  }
171  return 0;
172 }
173 
174 std::vector<Swaypoint> waypoints::GetGroup(short group) const
175 {
176  std::vector<Swaypoint> newwaypoints;
177  for (unsigned t = 0; t < gameclass->bus->waypoint.size(); t++)
178  {
179  // waypoint.at(t).id = t;
180  if (gameclass->bus->waypoint.at(t).group == group)
181  newwaypoints.emplace_back(gameclass->bus->waypoint.at(t));
182  }
183  return newwaypoints;
184 }
185 
186 void waypoints::Upload(Swaypoint swaypoint) const
187 {
188  SPacketHuge hugePacket;
189  hugePacket.type = 18; // waypoint data upstream
190  hugePacket.waypoint = swaypoint;
191  gameclass->networking->SendToServer(&hugePacket, sizeof SPacketHuge, true);
192 }
void Update(Swaypoint waypoint) const
Definition: waypoints.cpp:9
D3DXVECTOR3 position
Definition: globals.h:549
void RequestWaypointData() const
Definition: waypoints.cpp:14
void SendToServer(void *pData, DWORD dwSize, bool bGuaranteed, PacketOrdering order=ORDERING_NONE) const
Definition: Networking.cpp:59
s_network_objects playerships[MAX_SCAN]
Definition: globals.cpp:174
void Upload(Swaypoint swaypoint) const
Definition: waypoints.cpp:186
void AddOrUpdate(Swaypoint tempwaypoint) const
Definition: waypoints.cpp:132
Logger * logger
Definition: GameClass.h:113
Networking * networking
Definition: GameClass.h:107
void Sort(short sortfield, char sortdirection, int *linecursel, int *lineact) const
Definition: waypoints.cpp:25
waypoints(GameClass *prmGameClass)
Definition: waypoints.cpp:4
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition: Logger.cpp:11
std::vector< Swaypoint > GetGroup(short group) const
Definition: waypoints.cpp:174
GameClass * gameclass
Definition: waypoints.h:22
std::vector< Swaypoint > waypoint
Definition: Bus.h:391
short FindByUniqueId(int id) const
Definition: waypoints.cpp:163
int WPtargetC
Definition: Bus.h:390
void AddToCallStack(const char *msg)
Definition: Logger.cpp:86
Bus * bus
Definition: GameClass.h:112
void Delete(int index) const
Definition: waypoints.cpp:100
short Find(int uniqueid) const
Definition: waypoints.cpp:152