[Add] Jammers are now implemented fully.
This commit is contained in:
parent
fe1ab6ea0f
commit
da83f105e0
25
src/pilot.c
25
src/pilot.c
@ -714,16 +714,19 @@ void pilot_calcStats(Pilot* pilot) {
|
|||||||
pilot->armour_regen = pilot->ship->armour_regen;
|
pilot->armour_regen = pilot->ship->armour_regen;
|
||||||
pilot->shield_regen = pilot->ship->shield_regen;
|
pilot->shield_regen = pilot->ship->shield_regen;
|
||||||
pilot->energy_regen = pilot->ship->energy_regen;
|
pilot->energy_regen = pilot->ship->energy_regen;
|
||||||
|
/* Jamming. */
|
||||||
|
pilot->jam_range = 0.;
|
||||||
|
pilot->jam_chance = 0.;
|
||||||
|
|
||||||
/* Cargo has to be reset. */
|
/* Cargo has to be reset. */
|
||||||
pilot_calcCargo(pilot);
|
pilot_calcCargo(pilot);
|
||||||
|
|
||||||
/* Now add outfit changes. */
|
/* Now add outfit changes. */
|
||||||
for(i = 0; i < pilot->noutfits; i++) {
|
for(i = 0; i < pilot->noutfits; i++) {
|
||||||
if(outfit_isMod(pilot->outfits[i].outfit)) {
|
o = pilot->outfits[i].outfit;
|
||||||
q = (double) pilot->outfits[i].quantity;
|
q = (double) pilot->outfits[i].quantity;
|
||||||
o = pilot->outfits[i].outfit;
|
|
||||||
|
|
||||||
|
if(outfit_isMod(o)) { /* Modification. */
|
||||||
/* Movement. */
|
/* Movement. */
|
||||||
pilot->thrust += o->u.mod.thrust * q;
|
pilot->thrust += o->u.mod.thrust * q;
|
||||||
pilot->turn += o->u.mod.turn * q;
|
pilot->turn += o->u.mod.turn * q;
|
||||||
@ -740,9 +743,15 @@ void pilot_calcStats(Pilot* pilot) {
|
|||||||
/* Misc. */
|
/* Misc. */
|
||||||
pilot->cargo_free += o->u.mod.cargo * q;
|
pilot->cargo_free += o->u.mod.cargo * q;
|
||||||
}
|
}
|
||||||
else if(outfit_isAfterburner(pilot->outfits[i].outfit)) /* Set afterburner. */
|
else if(outfit_isAfterburner(o)) /* Afterburner. */
|
||||||
/* Set the afterburner. */
|
pilot->afterburner = &pilot->outfits[i]; /* Set afterburner. */
|
||||||
pilot->afterburner = &pilot->outfits[i];
|
else if(outfit_isJammer(o)) { /* Jammer. */
|
||||||
|
if(pilot->jam_chance < o->u.jam.chance) { /* Substitude. */
|
||||||
|
pilot->jam_range = o->u.jam.range;
|
||||||
|
pilot->jam_chance = o->u.jam.chance;
|
||||||
|
}
|
||||||
|
pilot->energy_regen -= o->u.jam.energy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Give the pilot her health proportion back. */
|
/* Give the pilot her health proportion back. */
|
||||||
@ -946,6 +955,10 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Jamming - must be set before calcStats. */
|
||||||
|
pilot->jam_range = 0.;
|
||||||
|
pilot->jam_chance = 0.;
|
||||||
|
|
||||||
/* Cargo must be set before calcStats. */
|
/* Cargo must be set before calcStats. */
|
||||||
pilot->credits = 0;
|
pilot->credits = 0;
|
||||||
pilot->commodities = NULL;
|
pilot->commodities = NULL;
|
||||||
|
@ -96,6 +96,10 @@ typedef struct Pilot_ {
|
|||||||
PilotOutfit* ammo; /* Secondary ammo (if needed). */
|
PilotOutfit* ammo; /* Secondary ammo (if needed). */
|
||||||
PilotOutfit* afterburner; /* Ze afterburner. */
|
PilotOutfit* afterburner; /* Ze afterburner. */
|
||||||
|
|
||||||
|
/* Jamming. */
|
||||||
|
double jam_range;
|
||||||
|
double jam_chance;
|
||||||
|
|
||||||
/* Cargo. */
|
/* Cargo. */
|
||||||
int credits; /* Moniez the pilot has. */
|
int credits; /* Moniez the pilot has. */
|
||||||
PilotCommodity* commodities; /* Commodity and quantity. */
|
PilotCommodity* commodities; /* Commodity and quantity. */
|
||||||
|
83
src/weapon.c
83
src/weapon.c
@ -19,7 +19,12 @@
|
|||||||
#define VOICE_PRIORITY_AMMO 8 /* Higher. */
|
#define VOICE_PRIORITY_AMMO 8 /* Higher. */
|
||||||
#define VOICE_PRIORITY_BEAM 6 /* Even higher. */
|
#define VOICE_PRIORITY_BEAM 6 /* Even higher. */
|
||||||
|
|
||||||
#define WEAPON_CHUNK 32
|
#define WEAPON_CHUNK 128 /* Size to increment array with. */
|
||||||
|
|
||||||
|
/* Weapon status. */
|
||||||
|
#define WEAPON_STATUS_OK 0 /* Weapon is fine. */
|
||||||
|
#define WEAPON_STATUS_JAMMED 1 /* Got jammed. */
|
||||||
|
#define WEAPON_STATUS_UNJAMMED 2 /* Surviving jaming. */
|
||||||
|
|
||||||
/* Some stuff from pilot. */
|
/* Some stuff from pilot. */
|
||||||
extern Pilot** pilot_stack;
|
extern Pilot** pilot_stack;
|
||||||
@ -47,6 +52,8 @@ typedef struct Weapon_ {
|
|||||||
/* Update position and render. */
|
/* Update position and render. */
|
||||||
void(*update)(struct Weapon_*, const double, WeaponLayer); /* Position update and render. */
|
void(*update)(struct Weapon_*, const double, WeaponLayer); /* Position update and render. */
|
||||||
void(*think)(struct Weapon_*, const double); /* Some missiles need to be inteligent.a */
|
void(*think)(struct Weapon_*, const double); /* Some missiles need to be inteligent.a */
|
||||||
|
|
||||||
|
char status; /* Weapon status - to check for jamming. */
|
||||||
} Weapon;
|
} Weapon;
|
||||||
|
|
||||||
/* Behind Pilot layer. */
|
/* Behind Pilot layer. */
|
||||||
@ -105,27 +112,68 @@ void weapon_minimap(const double res, const double w,
|
|||||||
static void think_seeker(Weapon* w, const double dt) {
|
static void think_seeker(Weapon* w, const double dt) {
|
||||||
double diff;
|
double diff;
|
||||||
double vel;
|
double vel;
|
||||||
|
Pilot* p;
|
||||||
|
int effect;
|
||||||
|
|
||||||
if(w->target == w->parent) return; /* HEY! Self harm is not allowed. */
|
if(w->target == w->parent) return; /* HEY! Self harm is not allowed. */
|
||||||
|
|
||||||
Pilot* p = pilot_get(w->target);
|
p = pilot_get(w->target); /* No null pilot_nstack. */
|
||||||
if(p == NULL) {
|
if(p == NULL) {
|
||||||
limit_speed(&w->solid->vel, w->outfit->u.amm.speed, dt);
|
w->solid->dir_vel = 0.; /* Go straight. */
|
||||||
|
vectnull(&w->solid->force); /* No force. */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ammo isn't locked on yet.. */
|
/* Ammo isn't locked on yet.. */
|
||||||
if(SDL_GetTicks() > (w->outfit->u.amm.lockon)) {
|
if(SDL_GetTicks() > (w->outfit->u.amm.lockon)) {
|
||||||
diff = angle_diff(w->solid->dir, vect_angle(&w->solid->pos, &p->solid->pos));
|
switch(w->status) {
|
||||||
|
case WEAPON_STATUS_OK: /* Check to see if can get jammed. */
|
||||||
|
if((p->jam_range != 0.) && /* Target has jammer and weapon is in range. */
|
||||||
|
(vect_dist(&w->solid->pos, &p->solid->pos) < p->jam_range)) {
|
||||||
|
|
||||||
/*diff = angle_diff(w->solid->dir, CollidePath(*&w->solid->pos, &w->solid->vel,
|
if(RNGF() < p->jam_chance) { /* Is jammed? */
|
||||||
&p->solid->pos, &p->solid->vel, 0.01));*/
|
w->status = WEAPON_STATUS_JAMMED;
|
||||||
|
/* Give it a nice random effect. */
|
||||||
|
effect = RNG(0, 4);
|
||||||
|
switch(effect) {
|
||||||
|
case 0: /* Blow up. */
|
||||||
|
w->timer = -1.;
|
||||||
|
break;
|
||||||
|
case 1: /* Stuck in left loop. */
|
||||||
|
w->solid->dir_vel = w->outfit->u.amm.turn;
|
||||||
|
break;
|
||||||
|
case 2: /* Stuck in right loop. */
|
||||||
|
w->solid->dir_vel = -w->outfit->u.amm.turn;
|
||||||
|
break;
|
||||||
|
default: /* Go straight. */
|
||||||
|
w->solid->dir_vel = 0.;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* Can't get jammed anymore. */
|
||||||
|
w->status = WEAPON_STATUS_UNJAMMED;
|
||||||
|
}
|
||||||
|
|
||||||
w->solid->dir_vel = 10 * diff * w->outfit->u.amm.turn;
|
/* Purpose fallthrough. */
|
||||||
/* Face the target. */
|
case WEAPON_STATUS_UNJAMMED: /* Work as expected. */
|
||||||
if(w->solid->dir_vel > w->outfit->u.amm.turn)
|
diff = angle_diff(w->solid->dir, /* Get angle to target pos. */
|
||||||
w->solid->dir_vel = w->outfit->u.amm.turn;
|
vect_angle(&w->solid->pos, &p->solid->pos));
|
||||||
else if(w->solid->dir_vel < -w->outfit->u.amm.turn)
|
w->solid->dir_vel = 10 * diff * w->outfit->u.amm.turn; /* Face pos. */
|
||||||
w->solid->dir_vel = -w->outfit->u.amm.turn;
|
/* Check for under/overflows. */
|
||||||
|
if(w->solid->dir_vel > w->outfit->u.amm.turn)
|
||||||
|
w->solid->dir_vel = w->outfit->u.amm.turn;
|
||||||
|
else if(w->solid->dir_vel < -w->outfit->u.amm.turn)
|
||||||
|
w->solid->dir_vel = -w->outfit->u.amm.turn;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WEAPON_STATUS_JAMMED: /* Continue doinng whatever. */
|
||||||
|
/* Do nothing. */
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
WARN("Unknown weapon status for '%s'", w->outfit->name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Limit speed here. */
|
/* Limit speed here. */
|
||||||
@ -345,11 +393,12 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
|
|||||||
/* Create basic features. */
|
/* Create basic features. */
|
||||||
w = MALLOC_L(Weapon);
|
w = MALLOC_L(Weapon);
|
||||||
w->faction = pilot_get(parent)->faction; /*Non-Changeable. */
|
w->faction = pilot_get(parent)->faction; /*Non-Changeable. */
|
||||||
w->parent = parent; /* Non-Changeable. */
|
w->parent = parent; /* Non-Changeable. */
|
||||||
w->target = target; /* Non-Changeable. */
|
w->target = target; /* Non-Changeable. */
|
||||||
w->outfit = outfit; /* Non-Changeable. */
|
w->outfit = outfit; /* Non-Changeable. */
|
||||||
w->update = weapon_update;
|
w->update = weapon_update;
|
||||||
w->think = NULL;
|
w->think = NULL;
|
||||||
|
w->status = WEAPON_STATUS_OK;
|
||||||
|
|
||||||
switch(outfit->type) {
|
switch(outfit->type) {
|
||||||
/* Bolts treated together. */
|
/* Bolts treated together. */
|
||||||
|
Loading…
Reference in New Issue
Block a user