2015-03-13 15:10:58 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Parallel Realities
|
|
|
|
Copyright (C) 2011, 2012 Guus Sliepen
|
2020-05-24 03:10:45 +02:00
|
|
|
Copyright (C) 2015-2020 Layla Marchant <diligentcircle@riseup.net>
|
2015-03-13 15:10:58 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 3
|
|
|
|
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
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-01-25 16:48:29 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "SDL.h"
|
2015-03-13 15:10:58 +01:00
|
|
|
|
2016-11-26 00:21:31 +01:00
|
|
|
#include "defs.h"
|
|
|
|
#include "structs.h"
|
|
|
|
|
2017-01-25 16:48:29 +01:00
|
|
|
#include "alien.h"
|
|
|
|
#include "audio.h"
|
|
|
|
#include "bullet.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "explosion.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "info.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "screen.h"
|
|
|
|
#include "weapons.h"
|
|
|
|
|
2016-11-25 18:37:26 +01:00
|
|
|
int ship_collision(Object *ship, Object *otherShip)
|
2015-09-25 22:28:09 +02:00
|
|
|
{
|
|
|
|
float x0 = ship->x;
|
|
|
|
float y0 = ship->y;
|
|
|
|
float w0 = ship->image[0]->w;
|
|
|
|
float h0 = ship->image[0]->h;
|
|
|
|
|
|
|
|
float x2 = otherShip->x;
|
|
|
|
float y2 = otherShip->y;
|
|
|
|
float w1 = otherShip->image[0]->w;
|
|
|
|
float h1 = otherShip->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);
|
|
|
|
}
|
|
|
|
|
2015-03-13 15:10:58 +01:00
|
|
|
/*
|
|
|
|
Fill in later...
|
|
|
|
*/
|
2016-11-25 19:47:12 +01:00
|
|
|
void ship_fireBullet(Object *ship, int weaponIndex)
|
2015-03-13 15:10:58 +01:00
|
|
|
{
|
2016-11-25 20:20:36 +01:00
|
|
|
int y = (ship->image[0]->h) / 5;
|
|
|
|
Object *theWeapon = &weapons[ship->weaponType[weaponIndex]];
|
|
|
|
|
2016-11-25 19:47:12 +01:00
|
|
|
if (ship->reload[weaponIndex] > 0)
|
2015-03-13 15:10:58 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Remove some ammo from the player
|
2020-11-23 05:33:26 +01:00
|
|
|
if ((ship == &player) && (player.weaponType[weaponIndex] != W_LASER)
|
|
|
|
&& (player.ammo[weaponIndex] > 0) && (!engine.cheatAmmo))
|
2016-11-25 19:47:12 +01:00
|
|
|
player.ammo[weaponIndex]--;
|
2015-03-13 15:10:58 +01:00
|
|
|
|
|
|
|
switch(theWeapon->id)
|
|
|
|
{
|
|
|
|
case WT_PLASMA:
|
|
|
|
case WT_SPREAD:
|
|
|
|
case WT_DIRECTIONAL:
|
2016-01-11 05:56:26 +01:00
|
|
|
audio_playSound(SFX_PLASMA, ship->x, ship->y);
|
2015-03-13 15:10:58 +01:00
|
|
|
break;
|
|
|
|
case WT_ROCKET:
|
2016-01-11 05:56:26 +01:00
|
|
|
audio_playSound(SFX_MISSILE, ship->x, ship->y);
|
2015-03-13 15:10:58 +01:00
|
|
|
break;
|
|
|
|
case WT_LASER:
|
2016-01-11 05:56:26 +01:00
|
|
|
audio_playSound(SFX_LASER, ship->x, ship->y);
|
2015-03-13 15:10:58 +01:00
|
|
|
break;
|
|
|
|
case WT_CHARGER:
|
2016-01-11 05:56:26 +01:00
|
|
|
audio_playSound(SFX_PLASMA3, ship->x, ship->y);
|
2015-03-13 15:10:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (theWeapon->flags & WF_SPREAD && theWeapon->ammo[0] >= 3)
|
|
|
|
{
|
2020-05-26 06:57:41 +02:00
|
|
|
bullet_add(theWeapon, ship, y * 2, -1);
|
|
|
|
bullet_add(theWeapon, ship, y * 4, 1);
|
2015-03-13 15:10:58 +01:00
|
|
|
|
2015-04-08 03:14:30 +02:00
|
|
|
if (theWeapon->ammo[0] != 4)
|
2015-03-13 15:10:58 +01:00
|
|
|
bullet_add(theWeapon, ship, y * 3, 0);
|
2015-04-08 03:14:30 +02:00
|
|
|
else
|
2015-03-13 15:10:58 +01:00
|
|
|
{
|
2015-04-08 03:14:30 +02:00
|
|
|
bullet_add(theWeapon, ship, y * 2, 0);
|
|
|
|
bullet_add(theWeapon, ship, y * 4, 0);
|
2015-03-13 15:10:58 +01:00
|
|
|
}
|
|
|
|
|
2015-04-08 03:14:30 +02:00
|
|
|
if (theWeapon->ammo[0] == 5)
|
|
|
|
{
|
2020-05-26 21:51:04 +02:00
|
|
|
bullet_add(theWeapon, ship, y * 1, -2);
|
|
|
|
bullet_add(theWeapon, ship, y * 5, 2);
|
2015-04-08 03:14:30 +02:00
|
|
|
}
|
2015-03-13 15:10:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-07 02:35:37 +01:00
|
|
|
if (theWeapon->ammo[0] & 1)
|
2015-03-13 15:10:58 +01:00
|
|
|
bullet_add(theWeapon, ship, y * 3, 0);
|
|
|
|
|
2016-01-07 02:35:37 +01:00
|
|
|
if (theWeapon->ammo[0] >= 2)
|
2015-03-13 15:10:58 +01:00
|
|
|
{
|
|
|
|
bullet_add(theWeapon, ship, y * 2, 0);
|
|
|
|
bullet_add(theWeapon, ship, y * 4, 0);
|
|
|
|
}
|
|
|
|
|
2016-01-07 02:35:37 +01:00
|
|
|
if (theWeapon->ammo[0] >= 4)
|
2015-03-13 15:10:58 +01:00
|
|
|
{
|
|
|
|
bullet_add(theWeapon, ship, y * 1, 0);
|
|
|
|
bullet_add(theWeapon, ship, y * 5, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the weapon reload time. Double it if it is not friendly or
|
|
|
|
// a boss or Kline
|
2016-11-25 19:47:12 +01:00
|
|
|
ship->reload[weaponIndex] = theWeapon->reload[0];
|
2020-11-23 05:33:26 +01:00
|
|
|
if ((ship->flags & FL_WEAPCO) && (ship != &aliens[ALIEN_BOSS])
|
|
|
|
&& (ship != &aliens[ALIEN_KLINE]) && (theWeapon->id != W_LASER))
|
2016-11-25 19:47:12 +01:00
|
|
|
ship->reload[weaponIndex] *= 2;
|
2015-03-13 15:10:58 +01:00
|
|
|
|
2016-11-25 19:47:12 +01:00
|
|
|
if ((ship == &player) && (weaponIndex == 0))
|
2015-03-13 15:10:58 +01:00
|
|
|
{
|
2016-11-25 19:47:12 +01:00
|
|
|
if (player.ammo[weaponIndex] <= 0)
|
2015-03-13 15:10:58 +01:00
|
|
|
{
|
2016-11-25 19:47:12 +01:00
|
|
|
weapons[W_PLAYER_WEAPON].ammo[0] = game.minPlasmaOutput;
|
|
|
|
weapons[W_PLAYER_WEAPON].damage = game.minPlasmaDamage;
|
|
|
|
weapons[W_PLAYER_WEAPON].reload[0] = rate2reload[game.minPlasmaRate];
|
2015-03-13 15:10:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-17 15:34:29 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Fill in later...
|
|
|
|
*/
|
2016-11-25 18:37:26 +01:00
|
|
|
void ship_fireRay(Object *ship)
|
2015-03-17 15:34:29 +01:00
|
|
|
{
|
|
|
|
SDL_Rect ray;
|
|
|
|
|
|
|
|
if (ship->face == 0)
|
|
|
|
{
|
|
|
|
ray.x = (int)(ship->x + ship->image[0]->w);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ray.x = (int)(ship->x - 800);
|
|
|
|
}
|
|
|
|
ray.y = (int)(ship->y + ship->engineY - 1);
|
|
|
|
ray.h = 3;
|
|
|
|
ray.w = 800;
|
|
|
|
|
|
|
|
int red = SDL_MapRGB(screen->format, rand() % 256, 0x00, 0x00);
|
|
|
|
SDL_FillRect(screen, &ray, red);
|
2015-11-02 23:53:05 +01:00
|
|
|
screen_addBuffer(ray.x, ray.y, ray.w, ray.h);
|
2015-03-17 15:34:29 +01:00
|
|
|
|
|
|
|
if (ship != &player)
|
|
|
|
{
|
|
|
|
if (player.shield > 0)
|
|
|
|
{
|
2015-09-25 22:28:09 +02:00
|
|
|
if (game_collision(player.x, player.y, player.image[0]->w,
|
2020-11-23 05:33:26 +01:00
|
|
|
player.image[0]->h, ray.x, ray.y, ray.w, ray.h)
|
|
|
|
&& (!engine.cheatShield)
|
|
|
|
&& (engine.missionCompleteTimer == 0))
|
2015-03-17 15:34:29 +01:00
|
|
|
{
|
2019-05-21 07:51:39 +02:00
|
|
|
player_damage(1, RAY_DAMAGE_DELAY);
|
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(player.x, player.y, SP_SMALL_EXPLOSION);
|
2015-03-17 15:34:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0 ; i < ALIEN_MAX ; i++)
|
|
|
|
{
|
|
|
|
if (aliens[i].flags & FL_IMMORTAL)
|
|
|
|
continue;
|
|
|
|
|
2020-11-23 05:33:26 +01:00
|
|
|
if ((aliens[i].shield > 0) && (ship != &aliens[i])
|
|
|
|
&& (ship->classDef != aliens[i].classDef))
|
2015-03-17 15:34:29 +01:00
|
|
|
{
|
2015-09-25 22:28:09 +02:00
|
|
|
if (game_collision(aliens[i].x, aliens[i].y, aliens[i].image[0]->w,
|
2015-03-17 15:34:29 +01:00
|
|
|
aliens[i].image[0]->h, ray.x, ray.y, ray.w, ray.h))
|
|
|
|
{
|
2016-11-19 17:43:50 +01:00
|
|
|
alien_hurt(&aliens[i], ship->owner, 1, 0);
|
2015-03-17 15:34:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ship->ammo[0]--;
|
|
|
|
if (ship->ammo[0] < 1)
|
|
|
|
ship->flags &= ~FL_FIRERAY;
|
|
|
|
}
|