2 Copyright © 2004 Parallel Realities
3 Copyright © 2007-2008 Kővágó Zoltán <DirtY.iCE.hu@gmail.com>
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.
23 #include "CObjective.h"
24 #include "CParticle.h"
25 #include "CSpawnPoint.h"
28 #include "console/console.hpp"
34 for (int i
= 0 ; i
< 10 ; i
++)
43 fightingGaldov
= false;
46 foundItems
= totalItems
= 0;
47 foundMIAs
= totalMIAs
= 0;
50 limitLeft
= limitUp
= 0;
51 limitRight
= ((MAPWIDTH
- 40) * BRICKSIZE
);
52 limitDown
= ((MAPHEIGHT
- 30) * BRICKSIZE
);
56 for (int x
= 0 ; x
< MAPWIDTH
; x
++)
57 for (int y
= 0 ; y
< MAPHEIGHT
; y
++)
60 for (int i
= 0 ; i
< 10 ; i
++)
61 allowableEnemy
[i
] = NULL
;
63 maxAllowableEnemies
= 0;
75 objectiveList
.clear();
83 waterLevel
= requiredWaterLevel
= -1;
84 isBossMission
= false;
86 isBlizzardLevel
= false;
87 isCavesTileset
= false;
88 isGrasslandsTileset
= false;
91 doBossLevelAction
= NULL
;
92 bossEnergyMeterBit
= 0;
94 for (int i
= 0 ; i
< 10 ; i
++)
103 windPower
= windChangeTime
= 0;
110 persistantList
.clear();
113 bool Map::isPracticeMission()
115 if (strstr(name
, "Practice"))
121 bool Map::isSolid(int x
, int y
)
123 if ((data
[x
][y
] >= MAP_BREAKABLE
) && (data
[x
][y
] < MAP_DECORATION
))
131 bool Map::isBreakable(int x
, int y
)
133 if ((data
[x
][y
] >= MAP_BREAKABLE
) && (data
[x
][y
] <= MAP_BREAKABLE2
))
141 bool Map::isNoReset(int x
, int y
)
143 if ((data
[x
][y
] >= MAP_NORESET
) && (data
[x
][y
] < MAP_DECORATION
))
151 bool Map::isLiquid(int x
, int y
)
157 else if ((data
[x
][y
] >= MAP_WATER
) && (data
[x
][y
] <= MAP_LAVA
))
161 else if ((data
[x
][y
] >= MAP_WATERANIM
) && (data
[x
][y
] <= MAP_LAVAANIM
))
169 bool Map::isTopLayer(int x
, int y
)
171 if (data
[x
][y
] >= MAP_TOPLAYER
)
179 Persistant
*Map::getPersistant(char *name
)
181 Persistant
*p
= (Persistant
*)persistantList
.getHead();
183 while (p
->next
!= NULL
)
185 p
= (Persistant
*)p
->next
;
187 if (strcmp(p
->stageName
, name
) == 0)
196 Persistant
*Map::createPersistant(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)
210 debug("pers", 1) << "Creating '" << name
<< "' in persistance list..." << std::endl
;
212 p
= new Persistant();
215 persistantList
.add(p
);
220 void Map::destroyPersistant(char *name
)
222 Persistant
*p
= (Persistant
*)persistantList
.getHead();
224 while (p
->next
!= NULL
)
226 p
= (Persistant
*)p
->next
;
228 if (strcmp(p
->stageName
, name
) == 0)
230 strcpy(p
->stageName
, "@none@");
237 void Map::setName(char *name
)
239 strcpy(this->name
, name
);
241 if (strstr(name
, "BioMech"))
243 isBossMission
= true;
246 if (strcmp(name
, "Galdov") == 0)
248 isBossMission
= true;
251 if (strcmp(name
, "Final Battle") == 0)
253 isBossMission
= true;
256 if (strstr(name
, "Ice"))
261 if (strstr(name
, "Arctic"))
264 isBlizzardLevel
= true;
268 void Map::setClipping(int limitLeft
, int limitRight
, int limitUp
, int limitDown
)
270 if (limitLeft
!= -1) this->limitLeft
= limitLeft
;
271 if (limitRight
!= -1) this->limitRight
= limitRight
;
272 if (limitUp
!= -1) this->limitUp
= limitUp
;
273 if (limitDown
!= -1) this->limitDown
= limitDown
;
276 void Map::addTrain(char *name
, int startX
, int startY
, int endX
, int endY
, int pause
, bool atStart
, bool active
)
278 Train
*train
= new Train();
279 train
->setName(name
);
280 train
->type
= TR_TRAIN
;
281 train
->set(startX
, startY
, endX
, endY
, pause
, atStart
);
282 train
->active
= active
;
289 warning
<< "Train with 0 wait time added '" << name
<< "' (" << startX
<< ":" << startY
<< ")" << std::endl
;
292 trainList
.add(train
);
295 void Map::addDoor(char *name
, int type
, int startX
, int startY
, int endX
, int endY
, bool active
)
297 Train
*train
= new Train();
298 train
->setName(name
);
302 train
->set(startX
, startY
, endX
, endY
, 0, false);
303 train
->active
= active
;
305 if (type
< TR_SLIDEDOOR
)
316 trainList
.add(train
);
319 void Map::addSwitch(char *name
, char *linkName
, char *requiredObjectName
, char *activateMessage
, int type
, int x
, int y
, bool activated
)
321 Switch
*swt
= new Switch();
322 swt
->set(name
, linkName
, requiredObjectName
, activateMessage
, type
, x
, y
, activated
);
327 void Map::addItem(Entity
*item
)
332 void Map::addBullet(Entity
*bullet
)
334 bulletList
.add(bullet
);
337 void Map::addParticle(float x
, float y
, float dx
, float dy
, int health
, int color
, Sprite
*sprite
, int flags
)
339 Particle
*particle
= new Particle();
340 particle
->set(x
, y
, dx
, dy
, color
, health
, flags
);
341 particle
->setSprite(sprite
);
343 particleList
.add(particle
);
346 void Map::addEnemy(Entity
*enemy
)
348 enemyList
.add(enemy
);
351 void Map::addMIA(Entity
*mia
)
356 void Map::addObstacle(Entity
*obstacle
)
358 obstacleList
.add(obstacle
);
361 void Map::addSpawnPoint(char *name
, int x
, int y
, int type
, int subtype
, int min
, int max
, bool active
)
363 SpawnPoint
*spawnPoint
= new SpawnPoint();
364 spawnPoint
->create(name
, x
, y
, type
, subtype
, min
, max
, active
);
366 spawnList
.add(spawnPoint
);
369 void Map::addEffect(Effect
*effect
)
371 effectList
.add(effect
);
374 void Map::addObjective(char *description
, char *target
, int targetValue
, bool required
)
376 Objective
*objective
= new Objective(description
, target
, targetValue
, required
);
378 objectiveList
.add(objective
);
381 void Map::addTeleporter(Teleporter
*teleporter
)
383 teleportList
.add(teleporter
);
386 void Map::addLineDef(LineDef
*lineDef
)
388 lineList
.add(lineDef
);
391 void Map::addTrap(Trap
*trap
)
396 void Map::evalTileset(char *baseDir
)
398 if (strstr(baseDir
, "caves"))
400 isCavesTileset
= true;
402 else if (strstr(baseDir
, "grasslands"))
404 isGrasslandsTileset
= true;
408 void Map::killAllEnemies()
410 Entity
*enemy
= (Entity
*)enemyList
.getHead()->next
;
412 while (enemy
!= NULL
)
416 enemy
= (Entity
*)enemy
->next
;
420 void Map::setAllowableEnemy(Entity
*enemy
)
422 for (int i
= 0 ; i
< 10 ; i
++)
424 if (allowableEnemy
[i
] == NULL
)
426 allowableEnemy
[i
] = enemy
;
427 maxAllowableEnemies
= i
+ 1;
432 warning
<< "Can't add anymore spawnable enemies to list!" << std::endl
;
435 char *Map::getSpawnableEnemy(int i
)
437 if (allowableEnemy
[i
] == NULL
)
440 return allowableEnemy
[i
]->name
;
443 char *Map::getSpawnableEnemy()
445 if (maxAllowableEnemies
== 0)
447 printf("ERROR: No enemy spawn list defined for map '%s'!! Please report this Error!\n", name
);
451 return allowableEnemy
[rand() % maxAllowableEnemies
]->name
;
454 void Map::getRandomEntityPosition(int *x
, int *y
)
456 Entity
*ent
= (Entity
*)miaList
.getHead();
458 while (ent
->next
!= NULL
)
460 ent
= (Entity
*)ent
->next
;
462 if ((rand() % 5) == 0)
470 ent
= (Entity
*)enemyList
.getHead();
472 while (ent
->next
!= NULL
)
474 ent
= (Entity
*)ent
->next
;
476 if ((rand() % 5) == 0)
484 ent
= (Entity
*)itemList
.getHead();
486 while (ent
->next
!= NULL
)
488 ent
= (Entity
*)ent
->next
;
490 if ((rand() % 5) == 0)
499 void Map::setMainBossPart(Boss
*boss
)
503 if (mainBossPart
!= NULL
)
505 bossEnergyMeterBit
= 200;
506 bossEnergyMeterBit
/= boss
->maxHealth
;