2 Copyright (C) 2004 Parallel Realities
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 for (int i = 0 ; i < 10 ; i++)
36 fightingGaldov = false;
39 foundItems = totalItems = 0;
40 foundMIAs = totalMIAs = 0;
43 limitLeft = limitUp = 0;
44 limitRight = ((MAPWIDTH - 40) * BRICKSIZE);
45 limitDown = ((MAPHEIGHT - 30) * BRICKSIZE);
49 for (int x = 0 ; x < MAPWIDTH ; x++)
50 for (int y = 0 ; y < MAPHEIGHT ; y++)
53 for (int i = 0 ; i < 10 ; i++)
54 allowableEnemy[i] = NULL;
56 maxAllowableEnemies = 0;
68 objectiveList.clear();
76 waterLevel = requiredWaterLevel = -1;
77 isBossMission = false;
79 isBlizzardLevel = false;
80 isCavesTileset = false;
81 isGrasslandsTileset = false;
84 doBossLevelAction = NULL;
85 bossEnergyMeterBit = 0;
87 for (int i = 0 ; i < 10 ; i++)
96 windPower = windChangeTime = 0;
103 persistantList.clear();
106 bool Map::isPracticeMission()
108 if (strstr(name, "Practice"))
114 bool Map::isSolid(int x, int y)
116 if ((data[x][y] >= MAP_BREAKABLE) && (data[x][y] < MAP_DECORATION))
124 bool Map::isBreakable(int x, int y)
126 if ((data[x][y] >= MAP_BREAKABLE) && (data[x][y] <= MAP_BREAKABLE2))
134 bool Map::isNoReset(int x, int y)
136 if ((data[x][y] >= MAP_NORESET) && (data[x][y] < MAP_DECORATION))
144 bool Map::isLiquid(int x, int y)
150 else if ((data[x][y] >= MAP_WATER) && (data[x][y] <= MAP_LAVA))
154 else if ((data[x][y] >= MAP_WATERANIM) && (data[x][y] <= MAP_LAVAANIM))
162 bool Map::isTopLayer(int x, int y)
164 if (data[x][y] >= MAP_TOPLAYER)
172 Persistant *Map::getPersistant(const char *name)
174 Persistant *p = (Persistant*)persistantList.getHead();
176 while (p->next != NULL)
178 p = (Persistant*)p->next;
180 if (strcmp(p->stageName, name) == 0)
189 Persistant *Map::createPersistant(const char *name)
191 Persistant *p = (Persistant*)persistantList.getHead();
193 while (p->next != NULL)
195 p = (Persistant*)p->next;
197 if (strcmp(p->stageName, name) == 0)
203 debug(("Creating %s in persistance list...\n", name));
205 p = new Persistant();
208 persistantList.add(p);
213 void Map::destroyPersistant(const char *name)
215 Persistant *p = (Persistant*)persistantList.getHead();
217 while (p->next != NULL)
219 p = (Persistant*)p->next;
221 if (strcmp(p->stageName, name) == 0)
223 strncpy(p->stageName, "@none@", sizeof p->stageName);
230 void Map::setName(const char *name)
232 strncpy(this->name, name, sizeof this->name);
234 if (strstr(name, "BioMech"))
236 isBossMission = true;
239 if (strcmp(name, "Galdov") == 0)
241 isBossMission = true;
244 if (strcmp(name, "Final Battle") == 0)
246 isBossMission = true;
249 if (strstr(name, "Ice"))
254 if (strstr(name, "Arctic"))
257 isBlizzardLevel = true;
261 void Map::setClipping(int limitLeft, int limitRight, int limitUp, int limitDown)
263 if (limitLeft != -1) this->limitLeft = limitLeft;
264 if (limitRight != -1) this->limitRight = limitRight;
265 if (limitUp != -1) this->limitUp = limitUp;
266 if (limitDown != -1) this->limitDown = limitDown;
269 void Map::addTrain(const char *name, int startX, int startY, int endX, int endY, int pause, bool atStart, bool active)
271 Train *train = new Train();
272 train->setName(name);
273 train->type = TR_TRAIN;
274 train->set(startX, startY, endX, endY, pause, atStart);
275 train->active = active;
282 debug(("WARNING: TRAIN WITH 0 WAIT TIME ADDED '%s' (%d:%d)\n", name, startX, startY));
285 trainList.add(train);
288 void Map::addDoor(const char *name, int type, int startX, int startY, int endX, int endY, bool active)
290 Train *train = new Train();
291 train->setName(name);
295 train->set(startX, startY, endX, endY, 0, false);
296 train->active = active;
298 if (type < TR_SLIDEDOOR)
309 trainList.add(train);
312 void Map::addSwitch(const char *name, const char *linkName, const char *requiredObjectName, const char *activateMessage, int type, int x, int y, bool activated)
314 Switch *swt = new Switch();
315 swt->set(name, linkName, requiredObjectName, activateMessage, type, x, y, activated);
320 void Map::addItem(Entity *item)
325 void Map::addBullet(Entity *bullet)
327 bulletList.add(bullet);
330 void Map::addParticle(float x, float y, float dx, float dy, int health, int color, Sprite *sprite, int flags)
332 Particle *particle = new Particle();
333 particle->set(x, y, dx, dy, color, health, flags);
334 particle->setSprite(sprite);
336 particleList.add(particle);
339 void Map::addEnemy(Entity *enemy)
341 enemyList.add(enemy);
344 void Map::addMIA(Entity *mia)
349 void Map::addObstacle(Entity *obstacle)
351 obstacleList.add(obstacle);
354 void Map::addSpawnPoint(const char *name, int x, int y, int type, int subtype, int min, int max, bool active)
356 SpawnPoint *spawnPoint = new SpawnPoint();
357 spawnPoint->create(name, x, y, type, subtype, min, max, active);
359 spawnList.add(spawnPoint);
362 void Map::addEffect(Effect *effect)
364 effectList.add(effect);
367 void Map::addObjective(const char *description, const char *target, int targetValue, bool required)
369 Objective *objective = new Objective(description, target, targetValue, required);
371 objectiveList.add(objective);
374 void Map::addTeleporter(Teleporter *teleporter)
376 teleportList.add(teleporter);
379 void Map::addLineDef(LineDef *lineDef)
381 lineList.add(lineDef);
384 void Map::addTrap(Trap *trap)
389 void Map::evalTileset(const char *baseDir)
391 if (strstr(baseDir, "caves"))
393 isCavesTileset = true;
395 else if (strstr(baseDir, "grasslands"))
397 isGrasslandsTileset = true;
401 void Map::killAllEnemies()
403 Entity *enemy = (Entity*)enemyList.getHead()->next;
405 while (enemy != NULL)
409 enemy = (Entity*)enemy->next;
413 void Map::setAllowableEnemy(Entity *enemy)
415 for (int i = 0 ; i < 10 ; i++)
417 if (allowableEnemy[i] == NULL)
419 allowableEnemy[i] = enemy;
420 maxAllowableEnemies = i + 1;
425 debug(("WARNING: Can't add anymore spawnable enemies to list!!!\n"));
428 char *Map::getSpawnableEnemy(int i)
430 if (allowableEnemy[i] == NULL)
433 return allowableEnemy[i]->name;
436 char *Map::getSpawnableEnemy()
438 if (maxAllowableEnemies == 0)
440 printf("ERROR: No enemy spawn list defined for map '%s'!! Please report this Error!\n", name);
444 return allowableEnemy[Math::prand() % maxAllowableEnemies]->name;
447 void Map::getRandomEntityPosition(int *x, int *y)
449 Entity *ent = (Entity*)miaList.getHead();
451 while (ent->next != NULL)
453 ent = (Entity*)ent->next;
455 if ((Math::prand() % 5) == 0)
463 ent = (Entity*)enemyList.getHead();
465 while (ent->next != NULL)
467 ent = (Entity*)ent->next;
469 if ((Math::prand() % 5) == 0)
477 ent = (Entity*)itemList.getHead();
479 while (ent->next != NULL)
481 ent = (Entity*)ent->next;
483 if ((Math::prand() % 5) == 0)
492 void Map::setMainBossPart(Boss *boss)
496 if (mainBossPart != NULL)
498 bossEnergyMeterBit = 200;
499 bossEnergyMeterBit /= boss->maxHealth;