World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
MapInfo.cpp
См. документацию.
1 #include "Engine/MapInfo.h"
2 
3 #include <cstdlib>
4 #include <sstream>
5 
6 #include "Engine/Engine.h"
7 
11 #include "LOD.h"
12 
15 #include "OurMath.h"
16 #include "Party.h"
17 
18 const char *location_type[] = {
19  "GENERIC",
20  "PADDEDCELL",
21  "ROOM",
22  "BATHROOM",
23  "LIVINGROOM",
24  "STONEROOM",
25  "AUDITORIUM",
26  "CONCERTHALL",
27  "CAVE",
28  "ARENA",
29  "HANGAR",
30  "CARPETEDHALLWAY",
31  "HALLWAY",
32  "STONECORRIDOR",
33  "ALLEY",
34  "FOREST",
35  "CITY",
36  "MOUNTAIN",
37  "QUARRY",
38  "PLAINS",
39  "PARKINGLOT",
40  "SEWERPIPE",
41  "UNDERWATER",
42  "DRUGGED",
43  "DIZZY",
44  "PSYCHOTIC"
45 };
46 
48  String pMapStatsTXT = (char*)pEvents_LOD->LoadCompressedTexture("MapStats.txt");
49  std::stringstream stream(pMapStatsTXT);
50  String tmpString;
51  std::getline(stream, tmpString);
52  std::getline(stream, tmpString);
53  std::getline(stream, tmpString);
54 
55  char work_str[32];
56  int work_str_pos;
57  int work_str_len;
58 
59  size_t i = 1;
60  while (!stream.eof()) {
61  std::getline(stream, tmpString);
62  std::stringstream line(tmpString);
63  size_t decode_step = 0;
64  while (!line.eof()) {
65  std::getline(line, tmpString, '\t');
66  char test_string[1024];
67  strcpy(test_string, tmpString.c_str());
68  switch (decode_step) {
69  case 1:
70  pInfos[i].pName = RemoveQuotes(test_string); // randoms crashes here
71  break;
72  case 2:
73  pInfos[i].pFilename = MakeLower(RemoveQuotes(test_string));
74  break;
75  case 3:
76  pInfos[i].uNumResets = atoi(test_string);
77  break;
78  case 4:
79  pInfos[i].uFirstVisitedAt = atoi(test_string);
80  break;
81  case 5:
82  pInfos[i]._per = atoi(test_string);
83  break;
84  case 6:
85  pInfos[i].uRespawnIntervalDays = atoi(test_string);
86  break;
87  case 7:
88  pInfos[i]._alert_days = atoi(test_string);
89  break;
90  case 8:
91  pInfos[i]._steal_perm = atoi(test_string);
92  break;
93  case 9:
94  pInfos[i].LockX5 = atoi(test_string);
95  break;
96  case 10:
97  pInfos[i].Trap_D20 = atoi(test_string);
98  break;
99  case 11:
100  pInfos[i].Treasure_prob = atoi(test_string);
101  break;
102  case 12:
103  pInfos[i].Encounter_percent = atoi(test_string);
104  break;
105  case 13:
106  pInfos[i].EncM1percent = atoi(test_string);
107  break;
108  case 14:
109  pInfos[i].EncM2percent = atoi(test_string);
110  break;
111  case 15:
112  pInfos[i].EncM3percent = atoi(test_string);
113  break;
114  case 16:
116  break;
117  case 18:
118  pInfos[i].Dif_M1 = atoi(test_string);
119  break;
120  case 19:
123  strcpy(work_str, test_string);
124  work_str_pos = 0;
125  work_str_len = strlen(work_str);
126  if (work_str_len) {
127  while (work_str[work_str_pos] != '-') {
128  ++work_str_pos;
129  if (work_str_pos >= work_str_len) break;
130  }
131  work_str[work_str_pos] = 0;
132  pInfos[i].uEncounterMonster1AtLeast = atoi(work_str);
133  if (work_str_pos < work_str_len)
134  pInfos[i].uEncounterMonster1AtMost = atoi(&work_str[work_str_pos + 1]);
135  else
137  }
138  break;
139  case 20:
141  break;
142  case 22:
143  pInfos[i].Dif_M2 = atoi(test_string);
144  break;
145  case 23:
148  strcpy(work_str, test_string);
149  work_str_pos = 0;
150  work_str_len = strlen(work_str);
151  if (work_str_len) {
152  while (work_str[work_str_pos] != '-') {
153  ++work_str_pos;
154  if (work_str_pos >= work_str_len) break;
155  }
156  work_str[work_str_pos] = 0;
157  pInfos[i].uEncounterMonster2AtLeast = atoi(work_str);
158  if (work_str_pos < work_str_len)
159  pInfos[i].uEncounterMonster2AtMost = atoi(&work_str[work_str_pos + 1]);
160  else
162  }
163  break;
164  case 24:
166  break;
167  case 26:
168  pInfos[i].Dif_M3 = atoi(test_string);
169  break;
170  case 27:
173  strcpy(work_str, test_string);
174  work_str_pos = 0;
175  work_str_len = strlen(work_str);
176  if (work_str_len) {
177  while (work_str[work_str_pos] != '-') {
178  ++work_str_pos;
179  if (work_str_pos >= work_str_len) break;
180  }
181  work_str[work_str_pos] = 0;
182  pInfos[i].uEncounterMonster3AtLeast = atoi(work_str);
183  if (work_str_pos < work_str_len)
184  pInfos[i].uEncounterMonster3AtMost = atoi(&work_str[work_str_pos + 1]);
185  else
187  }
188  break;
189  case 28:
190  pInfos[i].uRedbookTrackID = atoi(test_string);
191  break;
192  case 29: {
193  pInfos[i].uEAXEnv = 0xff;
194  for (int j = 0; j < 25; j++) {
195  if (!strcmp(test_string, location_type[j])) {
196  pInfos[i].uEAXEnv = j;
197  break;
198  }
199  }
200  if (pInfos[i].uEAXEnv == 0xff) {
201  pInfos[i].uEAXEnv = 26;
202  }
203  } break;
204  }
205  decode_step++;
206  }
207  i++;
208  }
209 
210  uNumMaps = i - 1;
211 }
212 
215 
216  for (int i = 1; i <= pMapStats->uNumMaps; i++) {
217  if (pMapStats->pInfos[i].pFilename == name) {
218  return i;
219  }
220  }
221  Error("Map not found");
222  return -1;
223 }
224 
226  Assert(uNumMaps >= 2);
227 
228  String map_name = MakeLower(Str2);
229 
230  for (uint i = 1; i < uNumMaps; ++i) {
231  if (pInfos[i].pFilename == map_name) {
232  return (MAP_TYPE)i;
233  }
234  }
235 
236  Error("Map not found!");
237  return (MAP_TYPE)-1;
238 }
239 
241  SpriteObject a1a;
242  a1a.containing_item.Reset();
243 
244  int v34 = 0;
245  int v5 = rand() % 100;
246  int v7 = (uint8_t)byte_4E8168[a2->uIndex - 1][2 * Treasure_prob];
247  int v8 = (uint8_t)byte_4E8168[a2->uIndex - 1][2 * Treasure_prob + 1];
248  int v9 = rand();
249  int v10 = v8 - v7 + 1;
250  int64_t v12 = v9;
251  int result = v9 / v10;
252  int v13 = v7 + (uint64_t)(v12 % v10);
253  if (v13 < 7) {
254  if (v5 < 20) return result;
255  if (v5 >= 60) {
256  return sub_450521_ProllyDropItemAt(v13, rand() % 27 + 20,
257  a2->vPosition.x,
258  a2->vPosition.y,
259  a2->vPosition.z, 0);
260  }
261  if (a2->uIndex == 1) {
263  v34 = rand() % 51 + 50;
264  } else if (a2->uIndex == 2) {
266  v34 = rand() % 101 + 100;
267  } else if (a2->uIndex == 3) {
269  v34 = rand() % 301 + 200;
270  } else if (a2->uIndex == 4) {
272  v34 = rand() % 501 + 500;
273  } else if (a2->uIndex == 5) {
275  v34 = rand() % 1001 + 1000;
276  } else if (a2->uIndex == 6) {
278  v34 = rand() % 3001 + 2000;
279  }
284  } else {
286  if (!result) return result;
289  a1a.containing_item.Reset(); // ?? this needs checking
290  }
291  a1a.vPosition.y = a2->vPosition.y;
292  a1a.uAttributes = 0;
293  a1a.uSoundID = 0;
294  a1a.uFacing = 0;
295  a1a.vPosition.z = a2->vPosition.z;
296  a1a.vPosition.x = a2->vPosition.x;
297  a1a.spell_skill = 0;
298  a1a.spell_level = 0;
299  a1a.spell_id = 0;
300  a1a.spell_target_pid = 0;
301  a1a.spell_caster_pid = 0;
302  a1a.uSpriteFrameID = 0;
303  a1a.uSectorID = pIndoor->GetSector(a2->vPosition.x, a2->vPosition.y, a2->vPosition.z);
304 
305  return a1a.Create(0, 0, 0, 0);
306 }
307 
309  const char *model_name; // [sp-4h] [bp-84h]@6
310  char pName[128]; // [sp+8h] [bp-78h]@11
311 
312  switch (point) {
313  case MapStartPoint_Party:
314  model_name = "Party Start";
315  break;
316  case MapStartPoint_North:
317  model_name = "North Start";
318  break;
319  case MapStartPoint_South:
320  model_name = "South Start";
321  break;
322  case MapStartPoint_East:
323  model_name = "East Start";
324  break;
325  case MapStartPoint_West:
326  model_name = "West Start";
327  break;
328  default:
329  Error("Invalid enum value: %u", point);
330  }
331 
332  strcpy(pName, model_name);
333  if (pDecorationList->GetDecorIdByName(pName)) {
334  if (uNumLevelDecorations > 0) {
335  for (size_t i = 0; i < uNumLevelDecorations; ++i) {
336  if (pLevelDecorations[i].uDecorationDescID == pDecorationList->GetDecorIdByName(pName)) {
337  pParty->vPosition.x = pLevelDecorations[i].vPosition.x;
338  pParty->vPosition.y = pLevelDecorations[i].vPosition.y;
339  pParty->vPosition.z = pLevelDecorations[i].vPosition.z;
342  pLevelDecorations[i].field_1A) /
343  90;
344  if (pLevelDecorations[i].field_10_y_rot)
345  pParty->sRotationY =
346  pLevelDecorations[i].field_10_y_rot;
347  pParty->sRotationX = 0;
348  pParty->uFallSpeed = 0;
349  }
350  }
351  }
357  if (Party_Teleport_Z_Pos) {
360  }
361  if (Party_Teleport_Cam_Yaw != -1)
366  }
374  }
375 }
MapInfo::EncM2percent
char EncM2percent
Definition: MapInfo.h:55
SpriteObject
Definition: SpriteObject.h:189
Party::vPosition
Vec3_int_ vPosition
Definition: Party.h:250
pLevelDecorations
std::array< LevelDecoration, 3000 > pLevelDecorations
Definition: Decoration.cpp:8
MapInfo::_alert_days
int _alert_days
Definition: MapInfo.h:46
RemoveQuotes
char * RemoveQuotes(char *str)
Definition: Strings.h:17
Party::uFallSpeed
int uFallSpeed
Definition: Party.h:259
SpriteObject::uFacing
unsigned __int16 uFacing
Definition: SpriteObject.h:220
MapStats::pInfos
MapInfo pInfos[77]
Definition: MapInfo.h:79
LOD.h
MapStartPoint
MapStartPoint
Definition: MapInfo.h:27
MapInfo::pEncounterMonster1Texture
String pEncounterMonster1Texture
Definition: MapInfo.h:40
TeleportToStartingPoint
void TeleportToStartingPoint(MapStartPoint point)
Definition: MapInfo.cpp:308
DecorationList.h
Start_Party_Teleport_Flag
int Start_Party_Teleport_Flag
Definition: mm7_data.cpp:628
Party_Teleport_Y_Pos
int Party_Teleport_Y_Pos
Definition: mm7_data.cpp:623
Party::sRotationX
int sRotationX
Definition: Party.h:252
ItemGen::SetIdentified
void SetIdentified()
Definition: Items.h:307
LOD::File::LoadCompressedTexture
void * LoadCompressedTexture(const String &pContainer, size_t *data_size=nullptr)
Definition: LOD.cpp:921
MapStats::GetMapInfo
MAP_TYPE GetMapInfo(const String &Str2)
Definition: MapInfo.cpp:225
MapInfo::uEncounterMonster2AtMost
uint8_t uEncounterMonster2AtMost
Definition: MapInfo.h:62
MapInfo::_per
int _per
Definition: MapInfo.h:48
SpriteObject::uSectorID
__int16 uSectorID
Definition: SpriteObject.h:223
SpriteObject.h
stru193_math::uIntegerHalfPi
static const unsigned int uIntegerHalfPi
Definition: OurMath.h:89
MapInfo::uEncounterMonster3AtMost
uint8_t uEncounterMonster3AtMost
Definition: MapInfo.h:65
MapInfo::Trap_D20
char Trap_D20
Definition: MapInfo.h:51
ObjectList::ObjectIDByItemID
unsigned int ObjectIDByItemID(unsigned int uItemID)
Definition: ObjectList.cpp:7
int64_t
__int64 int64_t
Definition: alext.h:31
SpawnPointMM7
Definition: Indoor.h:304
MapInfo::EncM3percent
char EncM3percent
Definition: MapInfo.h:56
SpriteObject::uType
SPRITE_OBJECT_TYPE uType
Definition: SpriteObject.h:215
ItemGen::Reset
void Reset()
Definition: Items.cpp:133
uint64_t
unsigned __int64 uint64_t
Definition: alext.h:32
MapInfo::uEncounterMonster1AtMost
uint8_t uEncounterMonster1AtMost
Definition: MapInfo.h:59
DecorationList::GetDecorIdByName
uint16_t GetDecorIdByName(const char *pName)
Definition: DecorationList.cpp:60
SpriteObject::uSpriteFrameID
unsigned __int16 uSpriteFrameID
Definition: SpriteObject.h:224
pIndoor
IndoorLocation * pIndoor
Definition: Indoor.cpp:49
Engine.h
MapStartPoint_North
@ MapStartPoint_North
Definition: MapInfo.h:29
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9435
pMapStats
struct MapStats * pMapStats
Definition: mm7_data.cpp:20
SpriteObject::uObjectDescID
unsigned __int16 uObjectDescID
Definition: SpriteObject.h:217
MapInfo::LockX5
char LockX5
Definition: MapInfo.h:50
Party::uFallStartY
int uFallStartY
Definition: Party.h:265
pItemsTable
struct ItemsTable * pItemsTable
Definition: Items.cpp:37
MapInfo::SpawnRandomTreasure
int SpawnRandomTreasure(struct SpawnPointMM7 *a2)
Definition: MapInfo.cpp:240
ItemGen::special_enchantment
ITEM_ENCHANTMENT special_enchantment
Definition: Items.h:330
sub_450521_ProllyDropItemAt
int sub_450521_ProllyDropItemAt(int ecx0, int a2, int a3, int a4, int a5, uint16_t a6)
Definition: Indoor.cpp:5409
MapStartPoint_East
@ MapStartPoint_East
Definition: MapInfo.h:31
MapInfo::EncM1percent
char EncM1percent
Definition: MapInfo.h:54
SpriteObject::vPosition
struct Vec3_int_ vPosition
Definition: SpriteObject.h:218
MapInfo::Dif_M3
char Dif_M3
Definition: MapInfo.h:63
pParty
Party * pParty
Definition: Party.cpp:30
Party_Teleport_Cam_Pitch
int Party_Teleport_Cam_Pitch
Definition: mm7_data.cpp:626
MapInfo::uEncounterMonster3AtLeast
uint8_t uEncounterMonster3AtLeast
Definition: MapInfo.h:64
MapInfo::Dif_M1
char Dif_M1
Definition: MapInfo.h:57
ITEM_GOLD_LARGE
@ ITEM_GOLD_LARGE
Definition: Items.h:99
location_type
const char * location_type[]
Definition: MapInfo.cpp:18
Party_Teleport_X_Pos
int Party_Teleport_X_Pos
Definition: mm7_data.cpp:622
Indoor.h
ItemGen::uItemID
int uItemID
Definition: Items.h:326
SpriteObject::spell_id
int spell_id
Definition: SpriteObject.h:228
Party_Teleport_Cam_Yaw
int Party_Teleport_Cam_Yaw
Definition: mm7_data.cpp:625
Party.h
MapStartPoint_South
@ MapStartPoint_South
Definition: MapInfo.h:30
MapStats::uNumMaps
unsigned int uNumMaps
Definition: MapInfo.h:80
uNumLevelDecorations
size_t uNumLevelDecorations
Definition: Decoration.cpp:9
MapInfo::uFirstVisitedAt
unsigned int uFirstVisitedAt
Definition: MapInfo.h:44
MapInfo::uEncounterMonster1AtLeast
uint8_t uEncounterMonster1AtLeast
Definition: MapInfo.h:58
MapInfo::pName
String pName
Definition: MapInfo.h:38
ITEM_GOLD_SMALL
@ ITEM_GOLD_SMALL
Definition: Items.h:97
MapInfo::uEncounterMonster2AtLeast
uint8_t uEncounterMonster2AtLeast
Definition: MapInfo.h:61
pGames_LOD
LOD::File * pGames_LOD
Definition: LOD.cpp:25
ITEM_ENCHANTMENT
ITEM_ENCHANTMENT
Definition: Items.h:38
stream
EGLStreamKHR stream
Definition: SDL_egl.h:1082
pEvents_LOD
LODFile_IconsBitmaps * pEvents_LOD
Definition: LOD.cpp:10
SpriteObject::Create
int Create(int yaw, int pitch, int a4, int a5)
Definition: SpriteObject.cpp:56
SpriteObject::containing_item
struct ItemGen containing_item
Definition: SpriteObject.h:227
byte_4E8168
std::array< std::array< char, 14 >, 7 > byte_4E8168
Definition: Items.cpp:25
MapInfo::uEAXEnv
uint8_t uEAXEnv
Definition: MapInfo.h:70
SPRITE_OBJECT_TYPE
SPRITE_OBJECT_TYPE
Definition: SpriteObject.h:5
MapInfo::Dif_M2
char Dif_M2
Definition: MapInfo.h:60
SpriteObject::uSoundID
unsigned __int16 uSoundID
Definition: SpriteObject.h:221
MapInfo.h
MapInfo::pEncounterMonster3Texture
String pEncounterMonster3Texture
Definition: MapInfo.h:42
uint8_t
unsigned __int8 uint8_t
Definition: SDL_config.h:35
MapStats::Initialize
void Initialize()
Definition: MapInfo.cpp:47
MapStats::sub_410D99_get_map_index
int sub_410D99_get_map_index(int a1)
Definition: MapInfo.cpp:213
MapInfo::uRedbookTrackID
uint8_t uRedbookTrackID
Definition: MapInfo.h:69
MapStartPoint_West
@ MapStartPoint_West
Definition: MapInfo.h:32
Party_Teleport_Z_Speed
int Party_Teleport_Z_Speed
Definition: mm7_data.cpp:627
name
EGLImageKHR EGLint * name
Definition: SDL_egl.h:1497
SpriteObject::spell_level
int spell_level
Definition: SpriteObject.h:229
MAP_TYPE
MAP_TYPE
Definition: MapInfo.h:5
SpriteObject::spell_target_pid
int spell_target_pid
Definition: SpriteObject.h:233
MapInfo::Encounter_percent
char Encounter_percent
Definition: MapInfo.h:53
uint
unsigned int uint
Definition: MM7.h:4
MapInfo::_steal_perm
int _steal_perm
Definition: MapInfo.h:47
SpriteObject::spell_skill
int spell_skill
Definition: SpriteObject.h:230
SpawnPointMM7::vPosition
Vec3_int_ vPosition
Definition: Indoor.h:314
Decoration.h
stru_5C6E00
struct stru193_math * stru_5C6E00
Definition: mm7_data.cpp:19
ItemGen::GenerateArtifact
bool GenerateArtifact()
Definition: Items.cpp:978
LOD::File::GetSubNodeName
String GetSubNodeName(size_t index) const
Definition: LOD.h:71
OurMath.h
MakeLower
String MakeLower(const String &text)
Definition: Strings.cpp:43
MapInfo::pFilename
String pFilename
Definition: MapInfo.h:39
IndoorLocation::GetSector
int GetSector(int sX, int sY, int sZ)
Definition: Indoor.cpp:1279
ObjectList.h
MapInfo::uRespawnIntervalDays
unsigned int uRespawnIntervalDays
Definition: MapInfo.h:45
SpawnPointMM7::uIndex
uint16_t uIndex
Definition: Indoor.h:317
MapInfo::Treasure_prob
char Treasure_prob
Definition: MapInfo.h:52
SpriteObject::uAttributes
unsigned __int16 uAttributes
Definition: SpriteObject.h:222
MapInfo::uNumResets
unsigned int uNumResets
Definition: MapInfo.h:43
Party_Teleport_Z_Pos
int Party_Teleport_Z_Pos
Definition: mm7_data.cpp:624
Party::sRotationY
int sRotationY
Definition: Party.h:251
String
std::string String
Definition: Strings.h:10
MapStartPoint_Party
@ MapStartPoint_Party
Definition: MapInfo.h:28
ITEM_GOLD_MEDIUM
@ ITEM_GOLD_MEDIUM
Definition: Items.h:98
pObjectList
struct ObjectList * pObjectList
Definition: ObjectList.cpp:5
MapInfo::pEncounterMonster2Texture
String pEncounterMonster2Texture
Definition: MapInfo.h:41
ItemsTable::pItems
NZIArray< ItemDesc, 800 > pItems
Definition: Items.h:460
pDecorationList
struct DecorationList * pDecorationList
Definition: DecorationList.cpp:11
SpriteObject::spell_caster_pid
int spell_caster_pid
Definition: SpriteObject.h:232