[Change] Some code quality improvements.

This commit is contained in:
Allanis 2013-09-14 01:02:01 +01:00
parent e9985fc8ca
commit 2cb22a8b7a
3 changed files with 20 additions and 10 deletions

View File

@ -109,7 +109,6 @@ int CollideLineSprite(const Vec2* ap, double ad,
(void)bsx; (void)bsx;
(void)bsy; (void)bsy;
(void)bp; (void)bp;
(void)crash;
} }

View File

@ -230,6 +230,8 @@ void weapons_update(const double dt) {
static void weapons_updateLayer(const double dt, const WeaponLayer layer) { static void weapons_updateLayer(const double dt, const WeaponLayer layer) {
Weapon** wlayer; Weapon** wlayer;
int* nlayer; int* nlayer;
Weapon* w;
int i;
switch(layer) { switch(layer) {
case WEAPON_LAYER_BG: case WEAPON_LAYER_BG:
@ -241,8 +243,7 @@ static void weapons_updateLayer(const double dt, const WeaponLayer layer) {
nlayer = &nwfrontLayer; nlayer = &nwfrontLayer;
break; break;
} }
int i;
Weapon* w;
for(i = 0; i < (*nlayer); i++) { for(i = 0; i < (*nlayer); i++) {
w = wlayer[i]; w = wlayer[i];
switch(wlayer[i]->outfit->type) { switch(wlayer[i]->outfit->type) {
@ -365,9 +366,9 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) { static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) {
/* Someone should let the ai know it's been attacked. */ /* Someone should let the ai know it's been attacked. */
if(!pilot_isPlayer(p)) { if(!pilot_isPlayer(p)) {
if((player_target == p->id) || (RNG(0,2) == 0)) { /* 33% chance. */ if((player_target == p->id) || (RNGF() > 0.33)) { /* 33% chance. */
if((w->parent == PLAYER_ID) && if((w->parent == PLAYER_ID) &&
(!pilot_isFlag(p, PILOT_HOSTILE) || (RNG(0, 1) == 0))) { /* 50% chance. */ (!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */
faction_modPlayer(p->faction, -1); /* Slowly lower faction. */ faction_modPlayer(p->faction, -1); /* Slowly lower faction. */
pilot_setFlag(p, PILOT_HOSTILE); pilot_setFlag(p, PILOT_HOSTILE);
} }
@ -497,19 +498,21 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos, void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos,
const Vec2* vel, unsigned int parent, unsigned int target) { const Vec2* vel, unsigned int parent, unsigned int target) {
WeaponLayer layer;
Weapon* w;
Weapon** curLayer;
int* mLayer, *nLayer;
if(!outfit_isWeapon(outfit) && if(!outfit_isWeapon(outfit) &&
!outfit_isAmmo(outfit) && !outfit_isTurret(outfit)) { !outfit_isAmmo(outfit) && !outfit_isTurret(outfit)) {
ERR("Trying to create a weapon from a non-Weapon type Outfit"); ERR("Trying to create a weapon from a non-Weapon type Outfit");
return; return;
} }
WeaponLayer layer = (parent == PLAYER_ID) ? WEAPON_LAYER_FG : WEAPON_LAYER_BG; layer = (parent == PLAYER_ID) ? WEAPON_LAYER_FG : WEAPON_LAYER_BG;
Weapon* w = weapon_create(outfit, dir, pos, vel, parent, target); w = weapon_create(outfit, dir, pos, vel, parent, target);
/* Set the propper layer. */ /* Set the propper layer. */
Weapon** curLayer = NULL;
int* mLayer = NULL;
int* nLayer = NULL;
switch(layer) { switch(layer) {
case WEAPON_LAYER_BG: case WEAPON_LAYER_BG:
curLayer = wbackLayer; curLayer = wbackLayer;

View File

@ -2,8 +2,16 @@
#include "outfit.h" #include "outfit.h"
#include "physics.h" #include "physics.h"
/**
* @enum WeaponLayer
*
* @brief Designates the layer the wepon is on.
*
* Auomatically set up on creation (player is front, rest is back).
*/
typedef enum { WEAPON_LAYER_BG, WEAPON_LAYER_FG } WeaponLayer; typedef enum { WEAPON_LAYER_BG, WEAPON_LAYER_FG } WeaponLayer;
/* Addition */
void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos, void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos,
const Vec2* vel, unsigned int parent, const Vec2* vel, unsigned int parent,
const unsigned int target); const unsigned int target);