[Fix] One seg fault! No idea how many more to go.
This commit is contained in:
parent
998a1bf68b
commit
cf86e5b0c7
@ -264,6 +264,7 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unload data.
|
// Unload data.
|
||||||
|
weapon_exit(); // Destroy all active weapons.
|
||||||
space_exit(); // Clean up the universe!!!
|
space_exit(); // Clean up the universe!!!
|
||||||
pilots_free(); // Free the pilots, they where locked up D:
|
pilots_free(); // Free the pilots, they where locked up D:
|
||||||
ships_free();
|
ships_free();
|
||||||
|
@ -88,8 +88,10 @@ static void outfit_parseSWeapon(Outfit* tmp, const xmlNodePtr parent) {
|
|||||||
tmp->speed = (double)atoi((char*)node->children->content);
|
tmp->speed = (double)atoi((char*)node->children->content);
|
||||||
else if(strcmp((char*)node->name, "delay")==0)
|
else if(strcmp((char*)node->name, "delay")==0)
|
||||||
tmp->delay = atoi((char*)node->children->content);
|
tmp->delay = atoi((char*)node->children->content);
|
||||||
|
else if(strcmp((char*)node->name, "range")==0)
|
||||||
|
tmp->range = atof((char*) node->children->content);
|
||||||
else if(strcmp((char*)node->name, "accuracy")==0)
|
else if(strcmp((char*)node->name, "accuracy")==0)
|
||||||
tmp->accuracy = atof((char*)node->children->content)*M_PI/180.; // to rad.
|
tmp->accuracy = atof((char*)node->children->content);
|
||||||
else if(strcmp((char*)node->name, "gfx")==0) {
|
else if(strcmp((char*)node->name, "gfx")==0) {
|
||||||
snprintf(str, strlen((char*)node->children->content)+sizeof(OUTFIT_GFX),
|
snprintf(str, strlen((char*)node->children->content)+sizeof(OUTFIT_GFX),
|
||||||
OUTFIT_GFX"%s", (char*)node->children->content);
|
OUTFIT_GFX"%s", (char*)node->children->content);
|
||||||
@ -106,9 +108,11 @@ static void outfit_parseSWeapon(Outfit* tmp, const xmlNodePtr parent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#define MELEMENT(o,s) if((o) == 0) WARN("Outfit '%s' missing '"s"' element", tmp->name)
|
#define MELEMENT(o,s) if((o) == 0) WARN("Outfit '%s' missing '"s"' element", tmp->name)
|
||||||
MELEMENT(tmp->speed, "speed");
|
|
||||||
MELEMENT(tmp->accuracy, "tech");
|
MELEMENT(tmp->accuracy, "tech");
|
||||||
MELEMENT(tmp->delay, "delay");
|
MELEMENT(tmp->delay, "delay");
|
||||||
|
MELEMENT(tmp->speed, "speed");
|
||||||
|
MELEMENT(tmp->range, "range");
|
||||||
|
MELEMENT(tmp->accuracy, "accuracy");
|
||||||
MELEMENT(tmp->damage_armor, "armor' from element 'damage");
|
MELEMENT(tmp->damage_armor, "armor' from element 'damage");
|
||||||
MELEMENT(tmp->damage_shield, "shield' from element 'damage");
|
MELEMENT(tmp->damage_shield, "shield' from element 'damage");
|
||||||
#undef MELEMENT
|
#undef MELEMENT
|
||||||
|
@ -53,7 +53,7 @@ void pilot_shoot(Pilot* p, int secondary) {
|
|||||||
if(outfit_isWeapon(p->outfits[i].outfit) || // Is a weapon or launch?
|
if(outfit_isWeapon(p->outfits[i].outfit) || // Is a weapon or launch?
|
||||||
outfit_isLauncher(p->outfits[i].outfit))
|
outfit_isLauncher(p->outfits[i].outfit))
|
||||||
// Ready to shoot again.
|
// Ready to shoot again.
|
||||||
if((SDL_GetTicks()-p->outfits[i].timer) > p->outfits[i].outfit->delay)
|
if((SDL_GetTicks()-p->outfits[i].timer) > (p->outfits[i].outfit->delay/p->outfits[i].quantity))
|
||||||
// Different weapons have different behaviours.
|
// Different weapons have different behaviours.
|
||||||
switch(p->outfits[i].outfit->type) {
|
switch(p->outfits[i].outfit->type) {
|
||||||
case OUTFIT_TYPE_BOLT:
|
case OUTFIT_TYPE_BOLT:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define RNG(L,H) (rand()%(H-L+1)+L)
|
#define RNG(L,H) (rand()%(int)(H-L+1)+L)
|
||||||
|
|
||||||
void rng_init(void);
|
void rng_init(void);
|
||||||
|
|
||||||
|
15
src/ship.c
15
src/ship.c
@ -97,10 +97,10 @@ static Ship* ship_parse(xmlNodePtr parent) {
|
|||||||
else if(strcmp((char*)node->name, "outfits")==0) {
|
else if(strcmp((char*)node->name, "outfits")==0) {
|
||||||
cur = node->children;
|
cur = node->children;
|
||||||
while((cur = cur->next)) {
|
while((cur = cur->next)) {
|
||||||
if(strcmp((char*)cur->name, "outfit")==0)
|
if(strcmp((char*)cur->name, "outfit")==0) {
|
||||||
otmp = MALLOC_L(ShipOutfit);
|
otmp = MALLOC_L(ShipOutfit);
|
||||||
otmp->data = outfit_get((char*)cur->children->content);
|
otmp->data = outfit_get((char*)cur->children->content);
|
||||||
xstr = xmlGetProp(cur, (xmlChar*)"qunatity");
|
xstr = xmlGetProp(cur, (xmlChar*)"quantity");
|
||||||
if(!xstr)
|
if(!xstr)
|
||||||
WARN("Ship '%s' is missing tag 'quantity for outfit '%s'", tmp->name, otmp->data->name);
|
WARN("Ship '%s' is missing tag 'quantity for outfit '%s'", tmp->name, otmp->data->name);
|
||||||
otmp->quantity = atoi((char*)xstr);
|
otmp->quantity = atoi((char*)xstr);
|
||||||
@ -115,6 +115,7 @@ static Ship* ship_parse(xmlNodePtr parent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tmp->thrust *= tmp->mass; // Helps keep number sane.
|
tmp->thrust *= tmp->mass; // Helps keep number sane.
|
||||||
|
|
||||||
@ -138,6 +139,7 @@ static Ship* ship_parse(xmlNodePtr parent) {
|
|||||||
|
|
||||||
DEBUG("Loaded ship '%s'", tmp->name);
|
DEBUG("Loaded ship '%s'", tmp->name);
|
||||||
return tmp;
|
return tmp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ships_load(void) {
|
int ships_load(void) {
|
||||||
@ -178,10 +180,17 @@ int ships_load(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ships_free(void) {
|
void ships_free(void) {
|
||||||
|
ShipOutfit* so, *sot;
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < ships; i++) {
|
for(i = 0; i < ships; i++) {
|
||||||
if((ship_stack+i)->name)
|
if((ship_stack+i)->name) // Free the name.
|
||||||
free((ship_stack+i)->name);
|
free((ship_stack+i)->name);
|
||||||
|
so = (ship_stack+i)->outfit;
|
||||||
|
while(so) { // free the ship outfit.
|
||||||
|
sot = so;
|
||||||
|
so = so->next;
|
||||||
|
free(sot);
|
||||||
|
}
|
||||||
gl_freeTexture((ship_stack+i)->gfx_ship);
|
gl_freeTexture((ship_stack+i)->gfx_ship);
|
||||||
}
|
}
|
||||||
free(ship_stack);
|
free(ship_stack);
|
||||||
|
50
src/weapon.c
50
src/weapon.c
@ -6,6 +6,7 @@
|
|||||||
#include "physics.h"
|
#include "physics.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "rng.h"
|
||||||
#include "weapon.h"
|
#include "weapon.h"
|
||||||
|
|
||||||
typedef struct Weapon {
|
typedef struct Weapon {
|
||||||
@ -33,6 +34,7 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir,
|
|||||||
|
|
||||||
static void weapon_render(const Weapon* w);
|
static void weapon_render(const Weapon* w);
|
||||||
static void weapon_update(Weapon* w, const double dt);
|
static void weapon_update(Weapon* w, const double dt);
|
||||||
|
static void weapon_destroy(Weapon* w, WeaponLayer layer);
|
||||||
static void weapon_free(Weapon* w);
|
static void weapon_free(Weapon* w);
|
||||||
|
|
||||||
// Update all weapons in the layer.
|
// Update all weapons in the layer.
|
||||||
@ -51,8 +53,20 @@ void weapons_update(const double dt, WeaponLayer layer) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < nlayer; i++)
|
for(i = 0; i < nlayer; i++) {
|
||||||
|
switch(wlayer[i]->outfit->type) {
|
||||||
|
case OUTFIT_TYPE_BOLT:
|
||||||
|
if(SDL_GetTicks() > (wlayer[i]->timer + 1000*(unsigned int)
|
||||||
|
wlayer[i]->outfit->range/wlayer[i]->outfit->speed)) {
|
||||||
|
weapon_destroy(wlayer[i],layer);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
weapon_update(wlayer[i], dt);
|
weapon_update(wlayer[i], dt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the weapons.
|
// Render the weapons.
|
||||||
@ -68,8 +82,7 @@ static void weapon_render(const Weapon* w) {
|
|||||||
|
|
||||||
// Update the weapon.
|
// Update the weapon.
|
||||||
static void weapon_update(Weapon* w, const double dt) {
|
static void weapon_update(Weapon* w, const double dt) {
|
||||||
if(w->think)
|
if(w->think) (*w->think)(w);
|
||||||
(*w->think)(w);
|
|
||||||
(*w->solid->update)(w->solid, dt);
|
(*w->solid->update)(w->solid, dt);
|
||||||
|
|
||||||
weapon_render(w);
|
weapon_render(w);
|
||||||
@ -137,6 +150,29 @@ void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos, const V
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destroy the weapon.
|
||||||
|
static void weapon_destroy(Weapon* w, WeaponLayer layer) {
|
||||||
|
int i;
|
||||||
|
Weapon** wlayer;
|
||||||
|
int* nlayer;
|
||||||
|
switch(layer) {
|
||||||
|
case WEAPON_LAYER_BG:
|
||||||
|
wlayer = backLayer;
|
||||||
|
nlayer = &nbackLayer;
|
||||||
|
break;
|
||||||
|
case WEAPON_LAYER_FG:
|
||||||
|
wlayer = frontLayer;
|
||||||
|
nlayer = &nfrontLayer;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for(i = 0; wlayer[i] != w; i++) // Get us to the current posision.
|
||||||
|
weapon_free(wlayer[i]);
|
||||||
|
(*nlayer)--;
|
||||||
|
|
||||||
|
for(; (*nlayer); i++)
|
||||||
|
wlayer[i] = wlayer[i+1];
|
||||||
|
}
|
||||||
|
|
||||||
// Clear the weapon.
|
// Clear the weapon.
|
||||||
static void weapon_free(Weapon* w) {
|
static void weapon_free(Weapon* w) {
|
||||||
solid_free(w->solid);
|
solid_free(w->solid);
|
||||||
@ -149,10 +185,14 @@ void weapon_clear(void) {
|
|||||||
for(i = 0; i < nbackLayer; i++)
|
for(i = 0; i < nbackLayer; i++)
|
||||||
weapon_free(backLayer[i]);
|
weapon_free(backLayer[i]);
|
||||||
nbackLayer = 0;
|
nbackLayer = 0;
|
||||||
backLayer = NULL;
|
|
||||||
for(i = 0; i < nfrontLayer; i++)
|
for(i = 0; i < nfrontLayer; i++)
|
||||||
weapon_free(frontLayer[i]);
|
weapon_free(frontLayer[i]);
|
||||||
nfrontLayer = 0;
|
nfrontLayer = 0;
|
||||||
frontLayer = NULL;
|
}
|
||||||
|
|
||||||
|
void weapon_exit(void) {
|
||||||
|
weapon_clear();
|
||||||
|
free(backLayer);
|
||||||
|
free(frontLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,3 +9,6 @@ void weapon_add(const Outfit* outfit, const double dir,
|
|||||||
|
|
||||||
void weapons_update(const double dt, WeaponLayer layer);
|
void weapons_update(const double dt, WeaponLayer layer);
|
||||||
|
|
||||||
|
void weapon_clear(void);
|
||||||
|
void weapon_exit(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user