2011-08-24 14:14:44 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Parallel Realities
|
2015-03-01 21:37:32 +01:00
|
|
|
Copyright (C) 2011, 2012 Guus Sliepen
|
2019-05-22 00:47:32 +02:00
|
|
|
Copyright (C) 2015-2019 Julie Marchant <onpon4@riseup.net>
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
2015-02-26 17:20:36 +01:00
|
|
|
as published by the Free Software Foundation; either version 3
|
2011-08-24 14:14:44 +02:00
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-02-26 17:20:36 +01:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2015-02-26 17:20:36 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-24 14:14:44 +02:00
|
|
|
*/
|
|
|
|
|
2017-01-25 16:48:29 +01:00
|
|
|
#include <stdlib.h>
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2016-11-26 00:21:31 +01:00
|
|
|
#include "defs.h"
|
|
|
|
#include "structs.h"
|
|
|
|
|
2017-01-21 05:26:49 +01:00
|
|
|
#include "audio.h"
|
|
|
|
#include "collectable.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "explosion.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "weapons.h"
|
|
|
|
|
2011-08-24 14:14:44 +02:00
|
|
|
/*
|
|
|
|
Create a new collectable item based on supplied arguments.
|
|
|
|
*/
|
2015-04-24 22:27:07 +02:00
|
|
|
void collectable_add(float x, float y, int type, int value, int life)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-03-09 01:59:33 +01:00
|
|
|
int r;
|
2019-05-23 17:25:54 +02:00
|
|
|
Collectable *collectable;
|
2019-05-26 07:08:58 +02:00
|
|
|
int plasma_useless, shield_useless, rockets_useless;
|
|
|
|
|
|
|
|
plasma_useless = (((weapons[W_PLAYER_WEAPON].reload[0] >= rate2reload[game.minPlasmaRate]) &&
|
|
|
|
(weapons[W_PLAYER_WEAPON].ammo[0] <= game.minPlasmaOutput) &&
|
|
|
|
(weapons[W_PLAYER_WEAPON].damage <= game.minPlasmaDamage)) ||
|
|
|
|
(player.ammo[0] >= game.maxPlasmaAmmo));
|
|
|
|
|
|
|
|
shield_useless = ((game.difficulty == DIFFICULTY_NIGHTMARE) ||
|
|
|
|
(player.shield >= player.maxShield));
|
|
|
|
|
|
|
|
rockets_useless = ((player.weaponType[1] == W_CHARGER) ||
|
|
|
|
(player.weaponType[1] == W_LASER) || (game.maxRocketAmmo <= 0) ||
|
|
|
|
(player.ammo[1] >= game.maxRocketAmmo));
|
2015-03-09 01:59:33 +01:00
|
|
|
|
2011-08-24 14:14:44 +02:00
|
|
|
if (type == P_ANYTHING)
|
|
|
|
{
|
|
|
|
type = P_CASH;
|
|
|
|
|
2015-03-09 01:59:33 +01:00
|
|
|
r = rand() % 9;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
switch (r)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-05-26 07:08:58 +02:00
|
|
|
if ((game.difficulty == DIFFICULTY_ORIGINAL) ||
|
|
|
|
(game.difficulty == DIFFICULTY_NIGHTMARE))
|
|
|
|
{
|
|
|
|
type = P_PLASMA_AMMO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((!shield_useless) &&
|
|
|
|
(CHANCE(2 * (player.maxShield - player.shield) / player.maxShield)))
|
|
|
|
{
|
|
|
|
type = P_SHIELD;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if ((!rockets_useless) && (game.maxRocketAmmo > 0) &&
|
|
|
|
(CHANCE((game.maxRocketAmmo - player.ammo[1]) / game.maxRocketAmmo)))
|
|
|
|
{
|
|
|
|
type = P_ROCKET;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = P_PLASMA_AMMO;
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
2019-05-26 07:08:58 +02:00
|
|
|
|
2011-08-24 14:14:44 +02:00
|
|
|
case 1:
|
|
|
|
type = P_SHIELD;
|
|
|
|
break;
|
2019-05-26 07:08:58 +02:00
|
|
|
|
2011-08-24 14:14:44 +02:00
|
|
|
case 2:
|
2019-05-26 07:08:58 +02:00
|
|
|
if ((game.difficulty == DIFFICULTY_ORIGINAL) ||
|
|
|
|
(game.difficulty == DIFFICULTY_NIGHTMARE))
|
|
|
|
{
|
|
|
|
type = P_ROCKET;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((!shield_useless) &&
|
|
|
|
(CHANCE(2 * (player.maxShield - player.shield) / player.maxShield)))
|
|
|
|
{
|
|
|
|
type = P_SHIELD;
|
|
|
|
}
|
|
|
|
else if ((!plasma_useless) && (game.maxPlasmaAmmo > 0) &&
|
|
|
|
(CHANCE((game.maxPlasmaAmmo - player.ammo[0]) / game.maxPlasmaAmmo)))
|
|
|
|
{
|
|
|
|
type = P_PLASMA_AMMO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = P_ROCKET;
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == P_WEAPONS)
|
|
|
|
{
|
|
|
|
type = P_PLASMA_RATE;
|
|
|
|
|
2015-05-21 01:41:43 +02:00
|
|
|
if ((game.difficulty == DIFFICULTY_NIGHTMARE) ||
|
|
|
|
((game.difficulty != DIFFICULTY_EASY) &&
|
|
|
|
(game.difficulty != DIFFICULTY_ORIGINAL) &&
|
|
|
|
((game.area == MISN_MOEBO) ||
|
|
|
|
(game.area == MISN_ELAMALE) ||
|
|
|
|
(game.area == MISN_ELLESH) ||
|
|
|
|
(game.area == MISN_EARTH))))
|
2015-03-09 01:59:33 +01:00
|
|
|
{
|
|
|
|
// Deny the Super Charge in Nightmare difficulty, and on bosses.
|
|
|
|
r = rand() % 59;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
r = rand() % 61;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
if (r <= 19)
|
|
|
|
type = P_PLASMA_DAMAGE;
|
|
|
|
else if (r <= 39)
|
|
|
|
type = P_PLASMA_SHOT;
|
|
|
|
else if (r <= 59)
|
|
|
|
type = P_PLASMA_RATE;
|
|
|
|
else
|
|
|
|
type = P_SUPER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == P_SUPER)
|
2015-03-17 21:54:00 +01:00
|
|
|
value = MAX(value, 1);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2015-02-28 15:45:26 +01:00
|
|
|
if (value == 0)
|
|
|
|
return; // don't bother!
|
|
|
|
|
2015-03-01 00:56:24 +01:00
|
|
|
// No point in giving the player plasma ammo if the weapons aren't
|
2019-05-21 19:28:09 +02:00
|
|
|
// upgraded! Give them money instead. (Except in Classic difficulty.)
|
|
|
|
if ((type == P_PLASMA_AMMO) && (game.difficulty != DIFFICULTY_ORIGINAL))
|
2015-03-01 00:56:24 +01:00
|
|
|
{
|
2019-05-26 07:08:58 +02:00
|
|
|
if (plasma_useless)
|
2015-03-01 00:56:24 +01:00
|
|
|
{
|
|
|
|
type = P_CASH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 14:14:44 +02:00
|
|
|
// If the player has a charge cannon or a laser cannon, don't give them
|
|
|
|
// rockets. Causes problems otherwise :)
|
|
|
|
if (type == P_ROCKET)
|
|
|
|
{
|
|
|
|
if ((player.weaponType[1] == W_CHARGER) || (player.weaponType[1] == W_LASER))
|
|
|
|
{
|
|
|
|
type = P_CASH;
|
|
|
|
}
|
2019-05-26 07:08:58 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
value /= 10;
|
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 07:08:58 +02:00
|
|
|
// Shield bonus is useless if you can't heal; give cash instead.
|
|
|
|
if ((type == P_SHIELD) && (game.difficulty != DIFFICULTY_ORIGINAL))
|
2015-02-28 04:16:53 +01:00
|
|
|
{
|
2019-05-26 07:08:58 +02:00
|
|
|
if ((game.difficulty == DIFFICULTY_NIGHTMARE) ||
|
|
|
|
(player.shield >= player.maxShield))
|
2015-02-28 04:16:53 +01:00
|
|
|
{
|
|
|
|
type = P_CASH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-21 01:41:43 +02:00
|
|
|
if (game.difficulty == DIFFICULTY_ORIGINAL)
|
2015-03-14 00:11:14 +01:00
|
|
|
{
|
2015-03-28 18:59:33 +01:00
|
|
|
// Cash is just rare in the original game. You can still grind,
|
|
|
|
// just not as much.
|
2015-05-21 01:41:43 +02:00
|
|
|
if ((game.area == MISN_INTERCEPTION) && (type == P_CASH))
|
2015-03-28 18:59:33 +01:00
|
|
|
{
|
|
|
|
if (rand() % 10 > 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No cash or ammo on interceptions. Completely stops grinding.
|
2015-05-21 01:41:43 +02:00
|
|
|
if ((game.area == MISN_INTERCEPTION) &&
|
2015-03-28 18:59:33 +01:00
|
|
|
((type == P_CASH) || (type == P_PLASMA_AMMO) || (type == P_ROCKET)))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-03-14 00:11:14 +01:00
|
|
|
}
|
|
|
|
|
2019-05-23 17:25:54 +02:00
|
|
|
collectable = malloc(sizeof(*collectable));
|
2019-05-20 00:22:53 +02:00
|
|
|
if (collectable == NULL)
|
|
|
|
{
|
|
|
|
engine_warn("Failed to allocate memory for collectable");
|
|
|
|
return;
|
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
collectable->next = NULL;
|
2016-11-19 17:43:50 +01:00
|
|
|
collectable->active = 1;
|
2011-08-24 14:14:44 +02:00
|
|
|
collectable->x = x;
|
|
|
|
collectable->y = y;
|
|
|
|
|
2015-03-29 16:19:53 +02:00
|
|
|
collectable->dx = RANDRANGE(-100, 100);
|
2011-08-24 14:14:44 +02:00
|
|
|
if (collectable->dx != 0)
|
|
|
|
collectable->dx /= 100;
|
|
|
|
|
2015-03-29 16:19:53 +02:00
|
|
|
collectable->dy = RANDRANGE(-100, 100);
|
2011-08-24 14:14:44 +02:00
|
|
|
if (collectable->dy != 0)
|
|
|
|
collectable->dy /= 100;
|
|
|
|
|
|
|
|
collectable->type = type;
|
|
|
|
collectable->value = value;
|
|
|
|
collectable->life = life;
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case P_CASH:
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
collectable->image = gfx_sprites[SP_PICKUP_MONEY];
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case P_ROCKET:
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
collectable->image = gfx_sprites[SP_PICKUP_ROCKETS];
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case P_PLASMA_AMMO:
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
collectable->image = gfx_sprites[SP_PICKUP_PLASMA];
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case P_SHIELD:
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
collectable->image = gfx_sprites[SP_PICKUP_SHIELD];
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case P_PLASMA_SHOT:
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
collectable->image = gfx_sprites[SP_PICKUP_PLASMA_OUTPUT];
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case P_PLASMA_RATE:
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
collectable->image = gfx_sprites[SP_PICKUP_PLASMA_RATE];
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case P_PLASMA_DAMAGE:
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
collectable->image = gfx_sprites[SP_PICKUP_PLASMA_POWER];
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case P_CARGO:
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
collectable->image = gfx_sprites[SP_CARGO];
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case P_SUPER:
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
collectable->image = gfx_sprites[SP_SUPERCHARGE];
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case P_MINE:
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
collectable->image = gfx_sprites[SP_MINE];
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case P_SLAVES:
|
|
|
|
case P_ESCAPEPOD:
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
collectable->image = gfx_sprites[SP_ESCAPE_POD];
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case P_ORE:
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
collectable->image = gfx_sprites[RANDRANGE(SP_ORE, SP_ORE_L)];
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
engine.collectableTail->next = collectable;
|
|
|
|
engine.collectableTail = collectable;
|
|
|
|
}
|
|
|
|
|
2016-11-25 18:37:26 +01:00
|
|
|
int collectable_collision(Collectable *collectable, Object *ship)
|
2015-09-25 22:28:09 +02:00
|
|
|
{
|
|
|
|
float x0 = collectable->x;
|
|
|
|
float y0 = collectable->y;
|
|
|
|
float w0 = collectable->image->w;
|
|
|
|
float h0 = collectable->image->h;
|
|
|
|
|
|
|
|
float x2 = ship->x;
|
|
|
|
float y2 = ship->y;
|
|
|
|
float w1 = ship->image[0]->w;
|
|
|
|
float h1 = ship->image[0]->h;
|
|
|
|
|
|
|
|
float x1 = x0 + w0;
|
|
|
|
float y1 = y0 + h0;
|
|
|
|
|
|
|
|
float x3 = x2 + w1;
|
|
|
|
float y3 = y2 + h1;
|
|
|
|
|
|
|
|
return !(x1<x2 || x3<x0 || y1<y2 || y3<y0);
|
|
|
|
}
|
|
|
|
|
2016-11-25 18:37:26 +01:00
|
|
|
void collectable_explode(Collectable *collectable)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2016-01-11 05:56:26 +01:00
|
|
|
audio_playSound(SFX_EXPLOSION, collectable->x, collectable->y);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
for (int i = 0 ; i < 10 ; i++)
|
Fixed more magic numbers.
God, this one was definitely the biggest headache of all of the
magic number erasing. Never did I expect such cryptic problems.
The first problem was that the entirety of the player's weapon
struct was a part of the save file, *including the weapon's "image
indexes"*. Since the indexes have been changed, and the originally
used one is now unavailable when it's requested, this was causing
a segfault later on. Had to fix this by setting the image index
when the game is loaded.
The second problem was related to another bug I've been confused
about for years: the one that causes mobile rays to fire 5 green
shots. The entire reason those shots were green was because
the weapon's image indexes were undefined, and *that was causing
them to default to 0*. 0 was simply the index of green plasma.
Of course, though, now attempting to use that image causes a
segfault, so for now, I've fixed this by changing the image index
of the mobile rays to the red plasma bolts.
There are still some magic numbers left, related to the intermission
screen. But the hardest part is now done, thank God.
2016-01-06 04:12:29 +01:00
|
|
|
explosion_add(RANDRANGE(collectable->x - 25, collectable->x + 25),
|
2016-01-07 02:49:02 +01:00
|
|
|
RANDRANGE(collectable->y - 25, collectable->y + 25), SP_BIG_EXPLOSION);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2015-04-24 22:37:55 +02:00
|
|
|
player_checkShockDamage(collectable->x, collectable->y);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|