[Add] Enemy pilots die with a big ass explosion. :D

This commit is contained in:
Allanis 2013-02-27 22:16:09 +00:00
parent ba89db90a4
commit 495a9ccb74
7 changed files with 74 additions and 11 deletions

View File

@ -7,6 +7,8 @@
#include "weapon.h"
#include "pack.h"
#include "xml.h"
#include "spfx.h"
#include "rng.h"
#include "pilot.h"
#define XML_ID "Fleets" // XML section identifier.
@ -42,6 +44,7 @@ static void pilot_hyperspace(Pilot* pilot);
void pilot_render(Pilot* pilot);
static void pilot_free(Pilot* p);
static Fleet* fleet_parse(const xmlNodePtr parent);
static void pilot_dead(Pilot* p);
// Get the next pilot based on id.
unsigned int pilot_getNext(const unsigned int id) {
@ -150,7 +153,7 @@ static void pilot_shootWeapon(Pilot* p, PilotOutfit* w, const unsigned int t) {
// WElll... Trying to shoot when you have no ammo?? FUUU
quantity = (outfit_isAmmo(w->outfit) && p->secondary) ?
p->secondary->quantity : w->quantity;
delay = (outfit_isWeapon(w->outfit)) ? w->outfit->u.wpn.delay : w->outfit->u.lau.delay;
delay = (outfit_isWeapon(w->outfit)) ? w->outfit->u.wpn.delay : w->outfit->u.wpn.delay;
// Check to see if weapon is ready.
if((SDL_GetTicks() - w->timer) < (unsigned int)(delay/quantity)) return;
@ -206,8 +209,7 @@ void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter,
dam_mod = 0.;
if(!pilot_isFlag(p, PILOT_DEAD)) {
pilot_setFlag(p, PILOT_DEAD);
pilot_dead(p);
// Adjust the combat rating based on pilot mass.
if(shooter == PLAYER_ID) combat_rating += MAX(1, p->ship->mass/50);
}
@ -220,6 +222,14 @@ void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter,
w->vel.y * (dam_mod/6. + w->mass/p->solid->mass/6.));
}
void pilot_dead(Pilot* p) {
// Basically just set the timers..
p->timer[0] = SDL_GetTicks(); // No need for AI anymore.
p->ptimer = p->timer[0] + 1000 + (unsigned int)sqrt(10*p->armour_max*p->shield_max);
p->timer[1] = p->timer[0]; // Explosion timer.
pilot_setFlag(p, PILOT_DEAD);
}
// Set the pilot's ammo based on their secondary weapon.
void pilot_setAmmo(Pilot* p) {
int i;
@ -253,6 +263,46 @@ void pilot_render(Pilot* p) {
// Update the pilot.
static void pilot_update(Pilot* pilot, const double dt) {
unsigned int t;
double px, py, vx, vy;
if((pilot != player) && pilot_isFlag(pilot, PILOT_DEAD)) {
t = SDL_GetTicks();
if(t > pilot->ptimer) {
pilot_setFlag(pilot, PILOT_DELETE); // It'll get deleted next frame.
return;
}
if(!pilot_isFlag(pilot, PILOT_EXPLODED) && (t > pilot->ptimer - 200)) {
spfx_add(spfx_get("ExpL"),
VX(pilot->solid->pos), VY(pilot->solid->pos),
VX(pilot->solid->vel), VY(pilot->solid->vel), SPFX_LAYER_BACK);
pilot_setFlag(pilot, PILOT_EXPLODED);
}
else if(t > pilot->timer[1]) {
pilot->timer[1] = t +
(unsigned int)(100*(double)(pilot->ptimer - pilot->timer[1]) /
(double)(pilot->ptimer - pilot->timer[0]));
// Random position on ship.
px = VX(pilot->solid->pos) + pilot->ship->gfx_space->sw * RNGF()
- pilot->ship->gfx_space->sw/2.;
py = VY(pilot->solid->pos) + pilot->ship->gfx_space->sh * RNGF()
- pilot->ship->gfx_space->sh/2.;
vx = VX(pilot->solid->vel);
vy = VY(pilot->solid->vel);
if(RNGF() > 0.8)
spfx_add(spfx_get("ExpM"), px, py, vx, vy, SPFX_LAYER_BACK);
else
spfx_add(spfx_get("ExpS"), px, py, vx, vy, SPFX_LAYER_BACK);
}
}
else if((pilot != player) && (pilot->armour <= 0.)) // PWNED!
pilot_dead(pilot);
// Pupose fallthrough to get the movement similar to disabled.
if(pilot != player && pilot->armour < PILOT_DISABLED_ARMOUR * pilot->armour_max) {
// We are disabled.
pilot_setFlag(pilot, PILOT_DISABLED);

View File

@ -34,6 +34,7 @@
#define PILOT_BOARDED (1<<8) // Pilot has been boarded already!
#define PILOT_DISABLED (1<<9) // Pilot is disabled.
#define PILOT_DEAD (1<<10) // Pilot is on it's death bed.
#define PILOT_EXPLODED (1<<11) // Pilot did dinal death explosion.
#define PILOT_DELETE (1<<15) // Pilot will get delete asap.
// Just makes life simpler.

View File

@ -274,7 +274,8 @@ void player_render(void) {
// Render the player target graphics.
if(player_target != PLAYER_ID) p = pilot_get(player_target);
else p = NULL;
if(p == NULL) player_target = PLAYER_ID; // No more pilot target.
if((p == NULL) || pilot_isFlag(p, PILOT_DEAD))
player_target = PLAYER_ID; // No more pilot target.
else {
// There is still a pilot target.
if(pilot_isDisabled(p)) c = &cInert;

View File

@ -1,7 +1,8 @@
#pragma once
#include <stdlib.h>
#define RNG(L,H) (rand()%(int)(H-L+1)+L)
#define RNG(L,H) ((int)L + (int)((double)(H-L+1) * (rand()/(RAND_MAX+1.))))
#define RNGF() (rand()/(RAND_MAX+1.))
void rng_init(void);

View File

@ -103,7 +103,10 @@ void spfx_free(void) {
spfx_neffects = 0;
}
void spfx_add(int effect, const Vec2* pos, const Vec2* vel, const int layer) {
void spfx_add(int effect,
const double px, const double py,
const double vx, const double vy,
const int layer) {
SPFX* cur_spfx;
if(layer == SPFX_LAYER_FRONT) {
@ -128,8 +131,8 @@ void spfx_add(int effect, const Vec2* pos, const Vec2* vel, const int layer) {
}
cur_spfx->effect = effect;
vectcpy(&cur_spfx->pos, pos);
vectcpy(&cur_spfx->vel, vel);
vect_csetmin(&cur_spfx->pos, px, py);
vect_csetmin(&cur_spfx->vel, vx, vy);
cur_spfx->t = SDL_GetTicks();
}

View File

@ -7,7 +7,9 @@
// Stack manipulation.
int spfx_get(char* name);
void spfx_add(const int effect,
const Vec2* pos, const Vec2* vel, const int layer);
const double px, const double py,
const double vx, const double vy,
const int layer);
// Stack mass manipulation functions.
void spfx_update(const double dt);

View File

@ -260,9 +260,14 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer) {
// Someone should let the ai know it's been attacked.
if(!pilot_isPlayer(p)) {
ai_attacked(p, w->parent);
spfx_add(outfit_spfx(w->outfit), &w->solid->pos, &p->solid->vel, SPFX_LAYER_BACK);
spfx_add(outfit_spfx(w->outfit),
VX(w->solid->pos), VY(w->solid->pos),
VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_BACK);
} else
spfx_add(outfit_spfx(w->outfit), &w->solid->pos, &p->solid->vel, SPFX_LAYER_FRONT);
spfx_add(outfit_spfx(w->outfit),
VX(w->solid->pos), VY(w->solid->pos),
VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_FRONT);
if(w->parent == PLAYER_ID)
// Make hostile to player.
pilot_setFlag(p, PILOT_HOSTILE);