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.
22 #include "spawnPoints.h"
24 bool okayToSpawnEnemy(const char *name, int x, int y)
26 // Don't summon other monsters!!
27 if (map.fightingGaldov)
32 if (engine.devNoMonsters)
37 // stop enemies from appearing in the middile of doors
38 Train *train = (Train*)map.trainList.getHead();
40 while (train->next != NULL)
42 train = (Train*)train->next;
44 // assume enemy is 20 x 20 pixels (most are at least) and trains are 64 x 64
45 if (Collision::collision(x * BRICKSHIFT, y * BRICKSHIFT, 20, 20, train->x, train->y, 64, 64))
47 debug(("Couldn't add enemy '%s' - Collided with train\n", name));
52 Entity *enemy = getDefinedEnemy(name);
54 if (map.isLiquid(x, y))
56 if (enemy->flags & ENT_SWIMS)
61 debug(("Couldn't add enemy '%s' - Would drown\n", name));
67 if (enemy->flags & ENT_SWIMS)
69 debug(("Couldn't add enemy '%s' - Not in water\n", name));
75 if (enemy->flags & ENT_FLIES)
80 for (int i = 0 ; i < 30 ; i++)
84 if (y > map.limitDown)
86 debug(("Couldn't add enemy '%s' - Outside map limits\n", name));
91 if (map.isLiquid(x, y))
93 debug(("Couldn't add enemy '%s' - Would drown after free fall\n", name));
98 if (map.isSolid(x, y))
104 debug(("Couldn't add enemy '%s' - Just couldn't!\n", name));
111 SpawnPoint *sp = (SpawnPoint*)map.spawnList.getHead();
117 while (sp->next != NULL)
119 sp = (SpawnPoint*)sp->next;
128 if (sp->spawnType == SPW_HAZARD)
130 if (sp->spawnSubType == HAZARD_ROCKFALL)
132 x = (int)fabs(sp->x - player.x);
133 y = (int)fabs(sp->y - player.y);
135 if ((x <= 640) && (y <= 480))
137 engine.setPlayerPosition((int)player.x + Math::rrand(-MAP_SHAKEAMOUNT, MAP_SHAKEAMOUNT), (int)player.y + Math::rrand(-MAP_SHAKEAMOUNT, MAP_SHAKEAMOUNT), map.limitLeft, map.limitRight, map.limitUp, map.limitDown);
140 else if (sp->spawnSubType == HAZARD_STALAGTITES)
142 x = (int)fabs(sp->x - player.x);
143 y = (int)fabs(sp->y - player.y);
145 if ((x <= 320) && (y <= 480))
147 engine.setPlayerPosition((int)player.x + Math::rrand(-MAP_SHAKEAMOUNT, MAP_SHAKEAMOUNT), (int)player.y + Math::rrand(-MAP_SHAKEAMOUNT, MAP_SHAKEAMOUNT), map.limitLeft, map.limitRight, map.limitUp, map.limitDown);
152 if (sp->readyToSpawn())
154 if ((sp->spawnType != SPW_ENEMY) && (sp->spawnType != SPW_ITEM))
156 // If the player is too far away, don't spawn (unless it's random enemy / item spawning)
157 x = (int)fabs(sp->x - player.x);
158 y = (int)fabs(sp->y - player.y);
160 if ((x > 700) || (y > 500))
167 switch (sp->spawnType)
170 switch (sp->spawnSubType)
172 case HAZARD_LAVABALL:
173 engine.world.place(sp->x, sp->y);
174 engine.world.currentWeapon = &weapon[WP_LAVABALL1];
175 addBullet(&engine.world, Math::rrand(-5, 5), Math::rrand(-(5 + game.skill), -(2 + game.skill)));
177 case HAZARD_ROCKFALL:
178 engine.world.place(sp->x, sp->y);
179 engine.world.currentWeapon = &weapon[WP_ROCK1];
180 addBullet(&engine.world, Math::rrand(-2, 2), Math::rrand(0, 2));
183 engine.world.place(sp->x, sp->y);
184 engine.world.currentWeapon = &weapon[WP_BOMB];
185 addBullet(&engine.world, Math::rrand(-2, 2), Math::rrand(0, 2));
187 case HAZARD_EXPLOSION:
188 x = sp->x + Math::rrand(-128, 128);
189 y = sp->y + Math::rrand(-128, 128);
190 addExplosion(x, y, 50, &engine.world);
193 if (map.isSolid(x, y))
195 int waterLevel = (int)map.waterLevel;
196 if (waterLevel == -1 || y < waterLevel)
198 map.data[x][y] = MAP_AIR;
200 else if (y == waterLevel)
202 map.data[x][y] = MAP_WATERANIM;
206 map.data[x][y] = MAP_WATER;
210 case HAZARD_POWERBULLETS:
211 engine.world.place(sp->x, sp->y);
212 engine.world.currentWeapon = &weapon[WP_SHELLS];
213 x = engine.world.currentWeapon->dx;
214 if (player.x < sp->x) x = -x;
215 addBullet(&engine.world, x, 0);
217 case HAZARD_STALAGTITES:
218 engine.world.place(sp->x, sp->y);
219 engine.world.currentWeapon = &weapon[WP_STALAGTITE];
220 addBullet(&engine.world, 0, 2);
223 printf("Spawn Subtype is unknown!\n");
229 if (game.missionOverReason != MIS_INPROGRESS)
232 enemy = map.getSpawnableEnemy();
234 x = (int)(player.x) >> BRICKSHIFT;
235 y = (int)(player.y) >> BRICKSHIFT;
237 x += Math::rrand(-10, 10);
238 y += Math::rrand(-10, 10);
240 if ((x >= 0) && (y >= 0) && (x < MAPWIDTH) && (y < MAPHEIGHT))
242 if ((map.data[x][y] == MAP_AIR) || (map.data[x][y] == MAP_WATER))
244 if (okayToSpawnEnemy(enemy, x, y))
248 addEnemy(enemy, x, y, ENT_SPAWNED);
249 addTeleportParticles(x, y, 25, SND_TELEPORT2);
257 if (game.missionOverReason != MIS_INPROGRESS)
260 x = (int)(player.x) >> BRICKSHIFT;
261 y = (int)(player.y) >> BRICKSHIFT;
263 x += Math::rrand(-10, 10);
264 y += Math::rrand(-10, 10);
266 if ((x >= 0) && (y >= 0))
268 if (map.data[x][y] == MAP_AIR)
272 dropHelperItems(x, y);
273 addTeleportParticles(x, y, 5, SND_TELEPORT2);
281 if (game.missionOverReason != MIS_INPROGRESS)
284 if (map.boss[sp->spawnSubType]->health > 0)
286 map.boss[sp->spawnSubType]->active = true;
292 debug(("Spawn Type is unknown!\n"));
298 if (sp->spawnType == SPW_ENEMY)
300 if ((Math::prand() % (game.skill + 2)) > 0)
302 sp->requiredInterval = Math::rrand(1, 30);