[Change] Preparations for adding fuel.

This commit is contained in:
Allanis 2013-05-16 19:15:00 +01:00
parent 5f2f57f6ee
commit 25adf125e4
8 changed files with 74 additions and 81 deletions

View File

@ -25,6 +25,7 @@
<characteristics> <characteristics>
<crew>2</crew> <crew>2</crew>
<mass>32</mass> <mass>32</mass>
<fuel>400</fuel>
<cap_weapon>25</cap_weapon> <cap_weapon>25</cap_weapon>
<cap_cargo>20</cap_cargo> <cap_cargo>20</cap_cargo>
</characteristics> </characteristics>
@ -57,6 +58,7 @@
<characteristics> <characteristics>
<crew>2</crew> <crew>2</crew>
<mass>25</mass> <mass>25</mass>
<fuel>300</fuel>
<cap_weapon>30</cap_weapon> <cap_weapon>30</cap_weapon>
<cap_cargo>10</cap_cargo> <cap_cargo>10</cap_cargo>
</characteristics> </characteristics>
@ -89,6 +91,7 @@
<characteristics> <characteristics>
<crew>35</crew> <crew>35</crew>
<mass>500</mass> <mass>500</mass>
<fuel>300</fuel>
<cap_weapon>180</cap_weapon> <cap_weapon>180</cap_weapon>
<cap_cargo>70</cap_cargo> <cap_cargo>70</cap_cargo>
</characteristics> </characteristics>
@ -123,6 +126,7 @@
<characteristics> <characteristics>
<crew>9</crew> <crew>9</crew>
<mass>130</mass> <mass>130</mass>
<fuel>400</fuel>
<cap_weapon>90</cap_weapon> <cap_weapon>90</cap_weapon>
<cap_cargo>20</cap_cargo> <cap_cargo>20</cap_cargo>
</characteristics> </characteristics>
@ -157,6 +161,7 @@
<characteristics> <characteristics>
<crew>13</crew> <crew>13</crew>
<mass>350</mass> <mass>350</mass>
<fuel>500</fuel>
<cap_weapon>50</cap_weapon> <cap_weapon>50</cap_weapon>
<cap_cargo>250</cap_cargo> <cap_cargo>250</cap_cargo>
</characteristics> </characteristics>
@ -189,6 +194,7 @@
<characteristics> <characteristics>
<crew>1</crew> <crew>1</crew>
<mass>15</mass> <mass>15</mass>
<fuel>1</fuel>
<cap_weapon>24</cap_weapon> <cap_weapon>24</cap_weapon>
<cap_cargo>1</cap_cargo> <cap_cargo>1</cap_cargo>
</characteristics> </characteristics>

View File

@ -263,11 +263,11 @@ static void outfit_parseSAmmo(Outfit* tmp, const xmlNodePtr parent) {
char str[PATH_MAX] = "\0"; char str[PATH_MAX] = "\0";
do { do {
if(xml_isNode(node, "thrust")) tmp->u.amm.thrust = xml_getFloat(node); xmlr_float(node, "thrust", tmp->u.amm.thrust);
else if(xml_isNode(node, "turn")) tmp->u.amm.turn = xml_getFloat(node); xmlr_float(node, "turn", tmp->u.amm.turn);
else if(xml_isNode(node, "speed")) tmp->u.amm.speed = xml_getFloat(node); xmlr_float(node, "speed", tmp->u.amm.speed);
else if(xml_isNode(node, "energy")) tmp->u.amm.energy = xml_getFloat(node); xmlr_float(node, "energy", tmp->u.amm.energy);
else if(xml_isNode(node, "duration")) if(xml_isNode(node, "duration"))
tmp->u.amm.duration = (unsigned int)1000.*xml_getFloat(node); tmp->u.amm.duration = (unsigned int)1000.*xml_getFloat(node);
else if(xml_isNode(node, "lockon")) else if(xml_isNode(node, "lockon"))
tmp->u.amm.lockon = (unsigned int)1000.*xml_getFloat(node); tmp->u.amm.lockon = (unsigned int)1000.*xml_getFloat(node);
@ -283,19 +283,19 @@ static void outfit_parseSAmmo(Outfit* tmp, const xmlNodePtr parent) {
else if(xml_isNode(node, "damage")) { else if(xml_isNode(node, "damage")) {
cur = node->children; cur = node->children;
do { do {
if(xml_isNode(cur, "armour")) tmp->u.amm.damage_armour = xml_getFloat(cur); xmlr_float(cur, "armour", tmp->u.amm.damage_armour);
else if(xml_isNode(cur, "shield")) tmp->u.amm.damage_shield = xml_getFloat(cur); xmlr_float(cur, "shield", tmp->u.amm.damage_shield);
} while((cur = cur->next)); } while((cur = cur->next));
} }
} while((node = node->next)); } while((node = node->next));
#define MELEMENT(o,s) if(o) WARN("Outfit '%s' missing '"s"' element", tmp->name) #define MELEMENT(o,s) if(o) WARN("Outfit '%s' missing '"s"' element", tmp->name)
MELEMENT(tmp->u.amm.gfx_space == NULL, "gfx"); MELEMENT(tmp->u.amm.gfx_space == NULL, "gfx");
MELEMENT((sound_lock != NULL) && (tmp->u.amm.sound == 0), "sound"); MELEMENT((sound_lock != NULL) && (tmp->u.amm.sound == 0), "sound");
MELEMENT(tmp->u.amm.thrust==0, "thrust"); MELEMENT(tmp->u.amm.thrust==0, "thrust");
MELEMENT(tmp->u.amm.turn==0, "turn"); MELEMENT(tmp->u.amm.turn==0, "turn");
MELEMENT(tmp->u.amm.speed==0, "speed"); MELEMENT(tmp->u.amm.speed==0, "speed");
MELEMENT(tmp->u.amm.duration==0, "duration"); MELEMENT(tmp->u.amm.duration==0, "duration");
MELEMENT(tmp->u.amm.lockon==0, "lockon"); MELEMENT(tmp->u.amm.lockon==0, "lockon");
MELEMENT(tmp->u.amm.damage_armour==0, "armour' from element 'damage"); MELEMENT(tmp->u.amm.damage_armour==0, "armour' from element 'damage");
MELEMENT(tmp->u.amm.damage_shield==0, "shield' from element 'damage"); MELEMENT(tmp->u.amm.damage_shield==0, "shield' from element 'damage");
#undef MELEMENT #undef MELEMENT
@ -308,21 +308,15 @@ static void outfit_parseSMod(Outfit* tmp, const xmlNodePtr parent) {
// Load all the data. // Load all the data.
do { do {
// Movement. // Movement.
if(xml_isNode(node, "thrust")) xmlr_float(node, "thrust", tmp->u.mod.thrust);
tmp->u.mod.thrust = xml_getFloat(node); xmlr_float(node, "turn", tmp->u.mod.turn);
else if(xml_isNode(node, "turn")) xmlr_float(node, "speed", tmp->u.mod.speed);
tmp->u.mod.turn = xml_getFloat(node);
else if(xml_isNode(node, "speed"))
tmp->u.mod.speed = xml_getFloat(node);
// Health. // Health.
if(xml_isNode(node, "armour")) xmlr_float(node, "armour", tmp->u.mod.armour);
tmp->u.mod.armour = xml_getFloat(node); xmlr_float(node, "shield", tmp->u.mod.shield);
else if(xml_isNode(node, "shield")) xmlr_float(node, "energy", tmp->u.mod.energy);
tmp->u.mod.shield = xml_getFloat(node); xmlr_float(node, "fuel", tmp->u.mod.fuel);
else if(xml_isNode(node, "energy")) if(xml_isNode(node, "armour_regen"))
tmp->u.mod.energy = xml_getFloat(node);
else if(xml_isNode(node, "armour_regen"))
tmp->u.mod.armour_regen = xml_getFloat(node)/60.0; tmp->u.mod.armour_regen = xml_getFloat(node)/60.0;
else if(xml_isNode(node, "shield_regen")) else if(xml_isNode(node, "shield_regen"))
tmp->u.mod.shield_regen = xml_getFloat(node)/60.0; tmp->u.mod.shield_regen = xml_getFloat(node)/60.0;
@ -371,13 +365,12 @@ static Outfit* outfit_parse(const xmlNodePtr parent) {
if(xml_isNode(node, "general")) { if(xml_isNode(node, "general")) {
cur = node->children; cur = node->children;
do { do {
if(xml_isNode(cur, "max")) tmp->max = xml_getInt(cur); xmlr_int(cur, "max", tmp->max);
else if(xml_isNode(cur, "tech")) tmp->tech = xml_getInt(cur); xmlr_int(cur, "tech", tmp->tech);
else if(xml_isNode(cur, "mass")) tmp->mass = xml_getInt(cur); xmlr_int(cur, "mass", tmp->mass);
else if(xml_isNode(cur, "price")) tmp->price = xml_getInt(cur); xmlr_int(cur, "price", tmp->price);
else if(xml_isNode(cur, "description")) xmlr_strd(cur, "description", tmp->description);
tmp->description = strdup(xml_get(cur)); if(xml_isNode(cur, "gfx_store")) {
else if(xml_isNode(cur, "gfx_store")) {
snprintf(str, strlen(xml_get(cur))+sizeof(OUTFIT_GFX)+10, snprintf(str, strlen(xml_get(cur))+sizeof(OUTFIT_GFX)+10,
OUTFIT_GFX"store/%s.png", xml_get(cur)); OUTFIT_GFX"store/%s.png", xml_get(cur));
tmp->gfx_store = gl_newImage(str); tmp->gfx_store = gl_newImage(str);

View File

@ -90,6 +90,7 @@ typedef struct Outfit_ {
double armour, armour_regen; double armour, armour_regen;
double shield, shield_regen; double shield, shield_regen;
double energy, energy_regen; double energy, energy_regen;
double fuel;
} mod; } mod;
struct { // Afterburner. struct { // Afterburner.
double thrust_perc, thrust_abs; // Percent and absolute thrust bonus. double thrust_perc, thrust_abs; // Percent and absolute thrust bonus.

View File

@ -580,7 +580,7 @@ static void pilot_calcStats(Pilot* pilot) {
int i; int i;
double q; double q;
Outfit* o; Outfit* o;
double ac, sc, ec; // Temp health coeficients to set. double ac, sc, ec, fc; // Temp health coeficients to set.
// -- Set up the basic stuff. // -- Set up the basic stuff.
// Movement. // Movement.
@ -591,9 +591,11 @@ static void pilot_calcStats(Pilot* pilot) {
ac = pilot->armour / pilot->armour_max; ac = pilot->armour / pilot->armour_max;
sc = pilot->shield / pilot->shield_max; sc = pilot->shield / pilot->shield_max;
ec = pilot->energy / pilot->energy_max; ec = pilot->energy / pilot->energy_max;
pilot->armour_max = pilot->ship->armour; fc = pilot->fuel / pilot->fuel_max;
pilot->shield_max = pilot->ship->shield; pilot->armour_max = pilot->ship->armour;
pilot->energy_max = pilot->ship->energy; pilot->shield_max = pilot->ship->shield;
pilot->energy_max = pilot->ship->energy;
pilot->fuel_max = pilot->ship->fuel;
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;
@ -615,7 +617,8 @@ static void pilot_calcStats(Pilot* pilot) {
pilot->shield_regen += o->u.mod.shield_regen * q; pilot->shield_regen += o->u.mod.shield_regen * q;
pilot->energy_max += o->u.mod.energy * q; pilot->energy_max += o->u.mod.energy * q;
pilot->energy_regen += o->u.mod.energy_regen * q; pilot->energy_regen += o->u.mod.energy_regen * q;
// Fuel.
pilot->fuel_max += o->u.mod.fuel * q;
} }
else if(outfit_isAfterburner(pilot->outfits[i].outfit)) { else if(outfit_isAfterburner(pilot->outfits[i].outfit)) {
// Set the afterburner. // Set the afterburner.
@ -627,6 +630,7 @@ static void pilot_calcStats(Pilot* pilot) {
pilot->armour = ac * pilot->armour_max; pilot->armour = ac * pilot->armour_max;
pilot->shield = sc * pilot->shield_max; pilot->shield = sc * pilot->shield_max;
pilot->energy = ec * pilot->energy_max; pilot->energy = ec * pilot->energy_max;
pilot->fuel = fc * pilot->fuel_max;
} }
// Pilot free cargo space. // Pilot free cargo space.
@ -792,10 +796,11 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction,
} }
// Set the pilot stats based on her ship and outfits. // Set the pilot stats based on her ship and outfits.
// Hack to have full armour/shield/energy. // Hack to have full armour/shield/energy/fuel.
pilot->armour = pilot->armour_max = 1.; pilot->armour = pilot->armour_max = 1.;
pilot->shield = pilot->shield_max = 1.; pilot->shield = pilot->shield_max = 1.;
pilot->energy = pilot->energy_max = 1.; pilot->energy = pilot->energy_max = 1.;
pilot->fuel = pilot->fuel_max = 1.;
pilot_calcStats(pilot); pilot_calcStats(pilot);
// Cargo. // Cargo.

View File

@ -78,10 +78,9 @@ typedef struct Pilot_ {
double thrust, turn, speed; double thrust, turn, speed;
// Current health. // Current health.
double armour, shield, energy; double armour, shield, energy, fuel;
double armour_max, shield_max, energy_max; double armour_max, shield_max, energy_max, fuel_max;
double armour_regen, shield_regen, energy_regen; double armour_regen, shield_regen, energy_regen;
double fuel; // Used only for jumps. TODO: make it do something.
void (*think)(struct Pilot_*); // AI thinking for the pilot. void (*think)(struct Pilot_*); // AI thinking for the pilot.
void (*update)(struct Pilot_*, const double); // Update the pilot. void (*update)(struct Pilot_*, const double); // Update the pilot.

View File

@ -85,7 +85,7 @@ static Ship* ship_parse(xmlNodePtr parent) {
char str[PATH_MAX] = "\0"; char str[PATH_MAX] = "\0";
char* stmp; char* stmp;
tmp->name = xml_nodeProp(parent, "name"); xmlr_attr(parent, "name", tmp->name);
if(tmp->name == NULL) WARN("Ship in "SHIP_DATA" has invalid or no name"); if(tmp->name == NULL) WARN("Ship in "SHIP_DATA" has invalid or no name");
node = parent->xmlChildrenNode; node = parent->xmlChildrenNode;
@ -104,60 +104,45 @@ static Ship* ship_parse(xmlNodePtr parent) {
tmp->gfx_target = gl_newImage(str); tmp->gfx_target = gl_newImage(str);
} }
else if(xml_isNode(node, "GUI")) xmlr_strd(node, "GUI", tmp->gui);
tmp->gui = strdup(xml_get(node)); if(xml_isNode(node, "sound"))
else if(xml_isNode(node, "sound"))
tmp->sound = sound_get(xml_get(node)); tmp->sound = sound_get(xml_get(node));
else if(xml_isNode(node, "class")) xmlr_int(node, "class", tmp->class);
tmp->class = xml_getInt(node); xmlr_int(node, "price", tmp->price);
else if(xml_isNode(node, "price")) xmlr_int(node, "tech", tmp->tech);
tmp->price = xml_getInt(node); xmlr_strd(node, "fabricator", tmp->fabricator);
else if(xml_isNode(node, "tech")) xmlr_strd(node, "description", tmp->description);
tmp->tech = xml_getInt(node); if(xml_isNode(node, "movement")) {
else if(xml_isNode(node, "fabricator"))
tmp->fabricator = strdup(xml_get(node));
else if(xml_isNode(node, "description"))
tmp->description = strdup(xml_get(node));
else if(xml_isNode(node, "movement")) {
cur = node->children; cur = node->children;
do { do {
if(xml_isNode(cur, "thrust")) xmlr_int(cur, "thrust", tmp->thrust);
tmp->thrust = xml_getInt(cur); xmlr_int(cur, "turn", tmp->turn);
else if(xml_isNode(cur, "turn")) xmlr_int(cur, "speed", tmp->speed);
tmp->turn = xml_getInt(cur); } while(xml_nextNode(cur));
else if(xml_isNode(cur, "speed"))
tmp->speed = xml_getInt(cur);
} while((cur = cur->next));
} }
else if(xml_isNode(node, "health")) { else if(xml_isNode(node, "health")) {
cur = node->children; cur = node->children;
do { do {
if(xml_isNode(cur, "armour")) xmlr_float(cur, "armour", tmp->armour);
tmp->armour = (double)xml_getInt(cur); xmlr_float(cur, "shield", tmp->shield);
else if(xml_isNode(cur, "shield")) xmlr_float(cur, "energy", tmp->energy);
tmp->shield = (double)xml_getInt(cur); if(xml_isNode(cur, "armour_regen"))
else if(xml_isNode(cur, "energy"))
tmp->energy = (double)xml_getInt(cur);
else if(xml_isNode(cur, "armour_regen"))
tmp->armour_regen = (double)(xml_getInt(cur))/60.0; tmp->armour_regen = (double)(xml_getInt(cur))/60.0;
else if(xml_isNode(cur, "shield_regen")) else if(xml_isNode(cur, "shield_regen"))
tmp->shield_regen = (double)(xml_getInt(cur))/60.0; tmp->shield_regen = (double)(xml_getInt(cur))/60.0;
else if(xml_isNode(cur, "energy_regen")) else if(xml_isNode(cur, "energy_regen"))
tmp->energy_regen = (double)(xml_getInt(cur))/60.0; tmp->energy_regen = (double)(xml_getInt(cur))/60.0;
} while((cur = cur->next)); } while(xml_nextNode(cur));
} }
else if(xml_isNode(node, "characteristics")) { else if(xml_isNode(node, "characteristics")) {
cur = node->children; cur = node->children;
do { do {
if(xml_isNode(cur, "crew")) xmlr_int(cur, "crew", tmp->crew);
tmp->crew = xml_getInt(cur); xmlr_float(cur, "mass", tmp->mass);
else if(xml_isNode(cur, "mass")) xmlr_int(cur, "fuel", tmp->fuel);
tmp->mass = (double)xml_getInt(cur); xmlr_int(cur, "cap_weapon", tmp->cap_weapon);
else if(xml_isNode(cur, "cap_weapon")) xmlr_int(cur, "cap_cargo", tmp->cap_cargo);
tmp->cap_weapon = xml_getInt(cur); } while(xml_nextNode(cur));
else if(xml_isNode(cur, "cap_cargo"))
tmp->cap_cargo = xml_getInt(cur);
} while((cur = cur->next));
} }
else if(xml_isNode(node, "outfits")) { else if(xml_isNode(node, "outfits")) {
cur = node->children; cur = node->children;
@ -179,9 +164,9 @@ static Ship* ship_parse(xmlNodePtr parent) {
ocur->next = otmp; ocur->next = otmp;
} }
} }
} while((cur = cur->next)); } while(xml_nextNode(cur));
} }
} while((node = node->next)); } while(xml_nextNode(node));
tmp->thrust *= tmp->mass; // Helps keep number sane. tmp->thrust *= tmp->mass; // Helps keep number sane.
@ -202,7 +187,8 @@ static Ship* ship_parse(xmlNodePtr parent) {
MELEMENT(tmp->shield==0, "shield"); MELEMENT(tmp->shield==0, "shield");
MELEMENT(tmp->shield_regen==0, "shield_regen"); MELEMENT(tmp->shield_regen==0, "shield_regen");
MELEMENT(tmp->energy==0, "energy"); MELEMENT(tmp->energy==0, "energy");
MELEMENT(tmp->energy_regen==0, "energt_regen"); MELEMENT(tmp->energy_regen==0, "energy_regen");
MELEMENT(tmp->fuel==0, "fuel");
MELEMENT(tmp->crew==0, "crew"); MELEMENT(tmp->crew==0, "crew");
MELEMENT(tmp->mass==0, "mass"); MELEMENT(tmp->mass==0, "mass");
MELEMENT(tmp->cap_cargo==0, "cap_cargo"); MELEMENT(tmp->cap_cargo==0, "cap_cargo");

View File

@ -57,6 +57,7 @@ typedef struct Ship_ {
// Characteristics. // Characteristics.
int crew; int crew;
int mass; int mass;
int fuel; // How many jumps by default.
// Health. // Health.
double armour, armour_regen; double armour, armour_regen;

View File

@ -34,6 +34,8 @@
if(xml_isNode(n,s)) { f = xml_getFloat(n); continue; } if(xml_isNode(n,s)) { f = xml_getFloat(n); continue; }
#define xmlr_str(n,s,str) \ #define xmlr_str(n,s,str) \
if(xml_isNode(n,s)) { str = xml_get(n); continue; } if(xml_isNode(n,s)) { str = xml_get(n); continue; }
#define xmlr_strd(n,s,str) \
if(xml_isNode(n,s)) { str = strdup(xml_get(n)); continue; }
#define xmlr_attr(n,s,a) \ #define xmlr_attr(n,s,a) \
a = xml_nodeProp(n,s) a = xml_nodeProp(n,s)