2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 for (int i = 0 ; i < 10 ; i++)
37 fightingGaldov = false;
40 foundItems = totalItems = 0;
41 foundMIAs = totalMIAs = 0;
44 limitLeft = limitUp = 0;
45 limitRight = ((MAPWIDTH - 40) * BRICKSIZE);
46 limitDown = ((MAPHEIGHT - 30) * BRICKSIZE);
50 for (int x = 0 ; x < MAPWIDTH ; x++)
51 for (int y = 0 ; y < MAPHEIGHT ; y++)
54 for (int i = 0 ; i < 10 ; i++)
55 allowableEnemy[i] = NULL;
57 maxAllowableEnemies = 0;
69 objectiveList.clear();
77 waterLevel = requiredWaterLevel = -1;
78 isBossMission = false;
80 isBlizzardLevel = false;
81 isCavesTileset = false;
82 isGrasslandsTileset = false;
85 doBossLevelAction = NULL;
86 bossEnergyMeterBit = 0;
88 for (int i = 0 ; i < 10 ; i++)
97 windPower = windChangeTime = 0;
104 persistantList.clear();
107 bool Map::isPracticeMission()
109 if (strstr(name, "Practice"))
115 bool Map::isValid(int x, int y)
117 if (x >= 0 && y >= 0 && x < MAPWIDTH && y < MAPHEIGHT)
123 bool Map::isSolid(int x, int y)
128 if ((data[x][y] >= MAP_BREAKABLE) && (data[x][y] < MAP_DECORATION))
136 bool Map::isBreakable(int x, int y)
141 if ((data[x][y] >= MAP_BREAKABLE) && (data[x][y] <= MAP_BREAKABLE2))
149 bool Map::isNoReset(int x, int y)
154 if ((data[x][y] >= MAP_NORESET) && (data[x][y] < MAP_DECORATION))
162 bool Map::isLiquid(int x, int y)
171 else if ((data[x][y] >= MAP_WATER) && (data[x][y] <= MAP_LAVA))
175 else if ((data[x][y] >= MAP_WATERANIM) && (data[x][y] <= MAP_LAVAANIM))
183 bool Map::isTopLayer(int x, int y)
188 if (data[x][y] >= MAP_TOPLAYER)
196 Persistant *Map::getPersistant(const char *name)
198 Persistant *p = (Persistant*)persistantList.getHead();
200 while (p->next != NULL)
202 p = (Persistant*)p->next;
204 if (strcmp(p->stageName, name) == 0)
213 Persistant *Map::createPersistant(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)
227 debug(("Creating %s in persistance list...\n", name));
229 p = new Persistant();
232 persistantList.add(p);
237 void Map::destroyPersistant(const char *name)
239 Persistant *p = (Persistant*)persistantList.getHead();
241 while (p->next != NULL)
243 p = (Persistant*)p->next;
245 if (strcmp(p->stageName, name) == 0)
247 strlcpy(p->stageName, "@none@", sizeof p->stageName);
254 void Map::setName(const char *name)
256 strlcpy(this->name, name, sizeof this->name);
258 if (strstr(name, "BioMech"))
260 isBossMission = true;
263 if (strcmp(name, "Galdov") == 0)
265 isBossMission = true;
268 if (strcmp(name, "Final Battle") == 0)
270 isBossMission = true;
273 if (strstr(name, "Ice"))
278 if (strstr(name, "Arctic"))
281 isBlizzardLevel = true;
285 void Map::setClipping(int limitLeft, int limitRight, int limitUp, int limitDown)
287 if (limitLeft != -1) this->limitLeft = limitLeft;
288 if (limitRight != -1) this->limitRight = limitRight;
289 if (limitUp != -1) this->limitUp = limitUp;
290 if (limitDown != -1) this->limitDown = limitDown;
293 void Map::addTrain(const char *name, int startX, int startY, int endX, int endY, int pause, bool atStart, bool active)
295 Train *train = new Train();
296 train->setName(name);
297 train->type = TR_TRAIN;
298 train->set(startX, startY, endX, endY, pause, atStart);
299 train->active = active;
306 debug(("WARNING: TRAIN WITH 0 WAIT TIME ADDED '%s' (%d:%d)\n", name, startX, startY));
309 trainList.add(train);
312 void Map::addDoor(const char *name, int type, int startX, int startY, int endX, int endY, bool active)
314 Train *train = new Train();
315 train->setName(name);
319 train->set(startX, startY, endX, endY, 0, false);
320 train->active = active;
322 if (type < TR_SLIDEDOOR)
333 trainList.add(train);
336 void Map::addSwitch(const char *name, const char *linkName, const char *requiredObjectName, const char *activateMessage, int type, int x, int y, bool activated)
338 Switch *swt = new Switch();
339 swt->set(name, linkName, requiredObjectName, activateMessage, type, x, y, activated);
344 void Map::addItem(Entity *item)
349 void Map::addBullet(Entity *bullet)
351 bulletList.add(bullet);
354 void Map::addParticle(float x, float y, float dx, float dy, int health, int color, Sprite *sprite, int flags)
356 Particle *particle = new Particle();
357 particle->set(x, y, dx, dy, color, health, flags);
358 particle->setSprite(sprite);
360 particleList.add(particle);
363 void Map::addEnemy(Entity *enemy)
365 enemyList.add(enemy);
368 void Map::addMIA(Entity *mia)
373 void Map::addObstacle(Entity *obstacle)
375 obstacleList.add(obstacle);
378 void Map::addSpawnPoint(const char *name, int x, int y, int type, int subtype, int min, int max, bool active)
380 SpawnPoint *spawnPoint = new SpawnPoint();
381 spawnPoint->create(name, x, y, type, subtype, min, max, active);
383 spawnList.add(spawnPoint);
386 void Map::addEffect(Effect *effect)
388 effectList.add(effect);
391 void Map::addObjective(const char *description, const char *target, int targetValue, bool required)
393 Objective *objective = new Objective(description, target, targetValue, required);
395 objectiveList.add(objective);
398 void Map::addTeleporter(Teleporter *teleporter)
400 teleportList.add(teleporter);
403 void Map::addLineDef(LineDef *lineDef)
405 lineList.add(lineDef);
408 void Map::addTrap(Trap *trap)
413 void Map::evalTileset(const char *baseDir)
415 if (strstr(baseDir, "caves"))
417 isCavesTileset = true;
419 else if (strstr(baseDir, "grasslands"))
421 isGrasslandsTileset = true;
425 void Map::killAllEnemies()
427 Entity *enemy = (Entity*)enemyList.getHead()->next;
429 while (enemy != NULL)
433 enemy = (Entity*)enemy->next;
437 void Map::setAllowableEnemy(Entity *enemy)
439 for (int i = 0 ; i < 10 ; i++)
441 if (allowableEnemy[i] == NULL)
443 allowableEnemy[i] = enemy;
444 maxAllowableEnemies = i + 1;
449 debug(("WARNING: Can't add anymore spawnable enemies to list!!!\n"));
452 char *Map::getSpawnableEnemy(int i)
454 if (allowableEnemy[i] == NULL)
457 return allowableEnemy[i]->name;
460 char *Map::getSpawnableEnemy()
462 if (maxAllowableEnemies == 0)
464 printf("ERROR: No enemy spawn list defined for map '%s'!! Please report this Error!\n", name);
468 return allowableEnemy[Math::prand() % maxAllowableEnemies]->name;
471 void Map::getRandomEntityPosition(int *x, int *y)
473 Entity *ent = (Entity*)miaList.getHead();
475 while (ent->next != NULL)
477 ent = (Entity*)ent->next;
479 if ((Math::prand() % 5) == 0)
487 ent = (Entity*)enemyList.getHead();
489 while (ent->next != NULL)
491 ent = (Entity*)ent->next;
493 if ((Math::prand() % 5) == 0)
501 ent = (Entity*)itemList.getHead();
503 while (ent->next != NULL)
505 ent = (Entity*)ent->next;
507 if ((Math::prand() % 5) == 0)
516 void Map::setMainBossPart(Boss *boss)
520 if (mainBossPart != NULL)
522 bossEnergyMeterBit = 200;
523 bossEnergyMeterBit /= boss->maxHealth;