Devilution
Diablo devolved - magic behind the 1996 computer game
town.cpp
Go to the documentation of this file.
1 #include "all.h"
2 
4 
14 void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h)
15 {
16  int i, j, xx, yy, nMap;
17  long v1, v2, v3, v4, ii;
18  WORD *Sector;
19 
20  ii = 4;
21  yy = yi;
22  for (j = 0; j < h; j++) {
23  xx = xi;
24  for (i = 0; i < w; i++) {
25  WORD *Map;
26 
27  Map = (WORD *)&pSector[ii];
28  nMap = SDL_SwapLE16(*Map);
29  if (nMap) {
30  Sector = (((WORD *)&P3Tiles[(nMap - 1) * 8]));
31  v1 = SDL_SwapLE16(*(Sector + 0)) + 1;
32  v2 = SDL_SwapLE16(*(Sector + 1)) + 1;
33  v3 = SDL_SwapLE16(*(Sector + 2)) + 1;
34  v4 = SDL_SwapLE16(*(Sector + 3)) + 1;
35 
36  } else {
37  v1 = 0;
38  v2 = 0;
39  v3 = 0;
40  v4 = 0;
41  }
42  dPiece[xx][yy] = v1;
43  dPiece[xx + 1][yy] = v2;
44  dPiece[xx][yy + 1] = v3;
45  dPiece[xx + 1][yy + 1] = v4;
46  xx += 2;
47  ii += 2;
48  }
49  yy += 2;
50  }
51 }
52 
60 void T_FillTile(BYTE *P3Tiles, int xx, int yy, int t)
61 {
62  long v1, v2, v3, v4;
63  WORD *Tiles;
64 
65  Tiles = ((WORD *)&P3Tiles[(t - 1) * 8]);
66  v1 = SDL_SwapLE16(*(Tiles + 0)) + 1;
67  v2 = SDL_SwapLE16(*(Tiles + 1)) + 1;
68  v3 = SDL_SwapLE16(*(Tiles + 2)) + 1;
69  v4 = SDL_SwapLE16(*(Tiles + 3)) + 1;
70 
71  dPiece[xx][yy] = v1;
72  dPiece[xx + 1][yy] = v2;
73  dPiece[xx][yy + 1] = v3;
74  dPiece[xx + 1][yy + 1] = v4;
75 }
76 
80 void T_Pass3()
81 {
82  int xx, yy, x;
83  BYTE *P3Tiles, *pSector;
84 
85  for (yy = 0; yy < MAXDUNY; yy += 2) {
86  for (xx = 0; xx < MAXDUNX; xx += 2) {
87  dPiece[xx][yy] = 0;
88  dPiece[xx + 1][yy] = 0;
89  dPiece[xx][yy + 1] = 0;
90  dPiece[xx + 1][yy + 1] = 0;
91  }
92  }
93 
94  P3Tiles = LoadFileInMem("Levels\\TownData\\Town.TIL", NULL);
95  pSector = LoadFileInMem("Levels\\TownData\\Sector1s.DUN", NULL);
96  T_FillSector(P3Tiles, pSector, 46, 46, 25, 25);
97  mem_free_dbg(pSector);
98  pSector = LoadFileInMem("Levels\\TownData\\Sector2s.DUN", NULL);
99  T_FillSector(P3Tiles, pSector, 46, 0, 25, 23);
100  mem_free_dbg(pSector);
101  pSector = LoadFileInMem("Levels\\TownData\\Sector3s.DUN", NULL);
102  T_FillSector(P3Tiles, pSector, 0, 46, 23, 25);
103  mem_free_dbg(pSector);
104  pSector = LoadFileInMem("Levels\\TownData\\Sector4s.DUN", NULL);
105  T_FillSector(P3Tiles, pSector, 0, 0, 23, 23);
106  mem_free_dbg(pSector);
107 
108 #ifndef SPAWN
109  if (gbMaxPlayers == 1) {
110  if (!(plr[myplr].pTownWarps & 1)) {
111 #endif
112  T_FillTile(P3Tiles, 48, 20, 320);
113 #ifndef SPAWN
114  }
115  if (!(plr[myplr].pTownWarps & 2)) {
116 #endif
117  T_FillTile(P3Tiles, 16, 68, 332);
118  T_FillTile(P3Tiles, 16, 70, 331);
119 #ifndef SPAWN
120  }
121  if (!(plr[myplr].pTownWarps & 4)) {
122 #endif
123  for (x = 36; x < 46; x++) {
124  T_FillTile(P3Tiles, x, 78, random_(0, 4) + 1);
125  }
126 #ifndef SPAWN
127  }
128  }
129 #endif
130 
131  if (quests[Q_PWATER]._qactive != QUEST_DONE && quests[Q_PWATER]._qactive) {
132  T_FillTile(P3Tiles, 60, 70, 342);
133  } else {
134  T_FillTile(P3Tiles, 60, 70, 71);
135  }
136 
137  mem_free_dbg(P3Tiles);
138 }
139 
144 void CreateTown(int entry)
145 {
146  int x, y;
147 
148  dminx = 10;
149  dminy = 10;
150  dmaxx = 84;
151  dmaxy = 84;
152  DRLG_InitTrans();
154 
155  if (entry == 0) {
156  ViewX = 75;
157  ViewY = 68;
158  } else if (entry == 1) {
159  ViewX = 25;
160  ViewY = 31;
161  } else if (entry == 7) {
162  if (TWarpFrom == 5) {
163  ViewX = 49;
164  ViewY = 22;
165  }
166  if (TWarpFrom == 9) {
167  ViewX = 18;
168  ViewY = 69;
169  }
170  if (TWarpFrom == 13) {
171  ViewX = 41;
172  ViewY = 81;
173  }
174  }
175 
176  T_Pass3();
177  memset(dLight, 0, sizeof(dLight));
178  memset(dFlags, 0, sizeof(dFlags));
179  memset(dPlayer, 0, sizeof(dPlayer));
180  memset(dMonster, 0, sizeof(dMonster));
181  memset(dObject, 0, sizeof(dObject));
182  memset(dItem, 0, sizeof(dItem));
183  memset(dSpecial, 0, sizeof(dSpecial));
184 
185  for (y = 0; y < MAXDUNY; y++) {
186  for (x = 0; x < MAXDUNX; x++) {
187  if (dPiece[x][y] == 360) {
188  dSpecial[x][y] = 1;
189  } else if (dPiece[x][y] == 358) {
190  dSpecial[x][y] = 2;
191  } else if (dPiece[x][y] == 129) {
192  dSpecial[x][y] = 6;
193  } else if (dPiece[x][y] == 130) {
194  dSpecial[x][y] = 7;
195  } else if (dPiece[x][y] == 128) {
196  dSpecial[x][y] = 8;
197  } else if (dPiece[x][y] == 117) {
198  dSpecial[x][y] = 9;
199  } else if (dPiece[x][y] == 157) {
200  dSpecial[x][y] = 10;
201  } else if (dPiece[x][y] == 158) {
202  dSpecial[x][y] = 11;
203  } else if (dPiece[x][y] == 156) {
204  dSpecial[x][y] = 12;
205  } else if (dPiece[x][y] == 162) {
206  dSpecial[x][y] = 13;
207  } else if (dPiece[x][y] == 160) {
208  dSpecial[x][y] = 14;
209  } else if (dPiece[x][y] == 214) {
210  dSpecial[x][y] = 15;
211  } else if (dPiece[x][y] == 212) {
212  dSpecial[x][y] = 16;
213  } else if (dPiece[x][y] == 217) {
214  dSpecial[x][y] = 17;
215  } else if (dPiece[x][y] == 216) {
216  dSpecial[x][y] = 18;
217  }
218  }
219  }
220 }
221 
DRLG_InitTrans
void DRLG_InitTrans()
Definition: gendung.cpp:171
quests
QuestStruct quests[MAXQUESTS]
Definition: quests.cpp:8
dminx
int dminx
Definition: gendung.cpp:77
T_FillTile
void T_FillTile(BYTE *P3Tiles, int xx, int yy, int t)
Load a tile in to dPiece.
Definition: town.cpp:60
dmaxx
int dmaxx
Definition: gendung.cpp:68
MAXDUNX
#define MAXDUNX
Definition: defs.h:25
ViewX
int ViewX
Definition: gendung.cpp:73
all.h
ViewY
int ViewY
Definition: gendung.cpp:74
dObject
char dObject[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:19
gbMaxPlayers
BYTE gbMaxPlayers
Specifies the maximum number of players in a game, where 1 represents a single player game and 4 repr...
Definition: multi.cpp:34
Q_PWATER
@ Q_PWATER
Definition: enums.h:2561
MAXDUNY
#define MAXDUNY
Definition: defs.h:26
dLight
char dLight[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:27
dPiece
int dPiece[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:26
T_FillSector
DEVILUTION_BEGIN_NAMESPACE void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h)
Load level data into dPiece.
Definition: town.cpp:14
TWarpFrom
int TWarpFrom
Definition: trigs.cpp:9
DEVILUTION_END_NAMESPACE
#define DEVILUTION_END_NAMESPACE
Definition: types.h:10
T_Pass3
void T_Pass3()
Initialize all of the levels data.
Definition: town.cpp:80
LoadFileInMem
BYTE * LoadFileInMem(char *pszName, DWORD *pdwFileLen)
Load a file in to a buffer.
Definition: engine.cpp:801
dItem
char dItem[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:57
QUEST_DONE
@ QUEST_DONE
Definition: enums.h:2570
dmaxy
int dmaxy
Definition: gendung.cpp:69
CreateTown
void CreateTown(int entry)
Initialize town level.
Definition: town.cpp:144
dSpecial
char dSpecial[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:50
myplr
int myplr
Definition: player.cpp:9
random_
int random_(BYTE idx, int v)
Main RNG function.
Definition: engine.cpp:752
mem_free_dbg
void mem_free_dbg(void *p)
Multithreaded safe memfree.
Definition: engine.cpp:786
dMonster
int dMonster[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:17
DEVILUTION_BEGIN_NAMESPACE
Definition: sha.cpp:10
dPlayer
char dPlayer[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:49
dFlags
char dFlags[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:56
DRLG_Init_Globals
void DRLG_Init_Globals()
Definition: drlg_l1.cpp:470
dminy
int dminy
Definition: gendung.cpp:78
plr
PlayerStruct plr[MAX_PLRS]
Definition: player.cpp:10