[Add] You may buy new outfits now. :D

This commit is contained in:
Allanis 2013-03-07 18:44:01 +00:00
parent b3c9fe74ca
commit 36a8847248
6 changed files with 140 additions and 11 deletions

View File

@ -6,6 +6,7 @@
<tech>2</tech>
<mass>5</mass>
<price>5000</price>
<description>Your basic laser.</description>
</general>
<specific type="1">
<gfx>lasergreen</gfx>
@ -27,6 +28,7 @@
<tech>4</tech>
<mass>20</mass>
<price>25000</price>
<description>Two laser cannons added on a rotating turret, allowing for 360 degrees of firepower!</description>
</general>
<specific type="13">
<gfx>lasergreen</gfx>
@ -48,6 +50,7 @@
<tech>4</tech>
<mass>10</mass>
<price>25000</price>
<description>Base for launching dumb missiles.</description>
</general>
<specific type="5" secondary="1">
<ammo>Missile</ammo>
@ -60,6 +63,7 @@
<tech>2</tech>
<mass>1</mass>
<price>800</price>
<description>The cheapest missile on the market, what it lacks in a decent tracking system it makes up for in affordability and firepower.</description>
</general>
<specific type="6">
<gfx>missile</gfx>
@ -82,6 +86,7 @@
<tech>8</tech>
<mass>12</mass>
<price>40000</price>
<description>The Headhunter Launcher is one of the most used missile launcher by the security companies. Much more reliable then the regular missiles, Headhunters feature more sensors and an advanced tracking system making them much better at hitting their targets.</description>
</general>
<specific type="5" secondary="1">
<ammo>Headhunter</ammo>
@ -94,6 +99,7 @@
<tech>4</tech>
<mass>1</mass>
<price>2000</price>
<description>Headhunters first gained fame in the crush of the Vroen, a fearsome battle against a pirate stronghold where the Empire crushed the pirates thanks to the advanced guidance system on the Headhunter. Now used by mercenaries and bounty hunters all over.</description>
</general>
<specific type="6">
<gfx>headhunter</gfx>

View File

@ -47,6 +47,8 @@ static void commodity_exchange_close(char* str);
// Outfits.
static void outfits(void);
static void outfits_close(char* str);
static void outfits_update(char* str);
static void outfits_buy(char* str);
// Shipyard.
static void shipyard(void);
static void shipyard_close(char* str);
@ -87,12 +89,46 @@ static void commodity_exchange_close(char* str) {
}
static void outfits(void) {
char** outfits;
int noutfits;
secondary_wid = window_create("Outfits", -1, -1,
OUTFITS_WIDTH, OUTFITS_HEIGHT);
window_addButton(secondary_wid, -20, 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseOutfits",
"Close", outfits_close);
window_addButton(secondary_wid, -40-BUTTON_WIDTH, 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnBuyOutfits",
"Buy", outfits_buy);
window_addButton(secondary_wid, -40-BUTTON_WIDTH, 40+BUTTON_HEIGHT,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnInfoOutfit",
"Info", NULL);
window_addText(secondary_wid, 40+200+40, -80,
80, 96, 0, "txtSDesc", &gl_smallFont, &cDConsole,
"Name:\n"
"Type:\n"
"\n"
"Price:\n");
window_addText(secondary_wid, 40+200+40+80, -80,
250, 96, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL);
window_addText(secondary_wid, 20+200+40, -200,
OUTFITS_WIDTH-360, 200, 0, "txtDescription",
&gl_smallFont, NULL, NULL);
// Set up the outfits to buy/sell.
outfits = outfit_getAll(&noutfits);
window_addList(secondary_wid, 20, 40,
200, OUTFITS_HEIGHT-120, "lstOutfits",
outfits, noutfits, 0, outfits_update);
// Write the outfits stuff.
outfits_update(NULL);
}
static void outfits_close(char* str) {
@ -100,6 +136,43 @@ static void outfits_close(char* str) {
window_destroy(secondary_wid);
}
static void outfits_update(char* str) {
(void)str;
char* outfitname;
Outfit* outfit;
char buf[80], buf2[32];
outfitname = toolkit_getList(secondary_wid, "lstOutfits");
outfit = outfit_get(outfitname);
window_modifyText(secondary_wid, "txtDescription", outfit->description);
credits2str(buf2, outfit->price, 0);
snprintf(buf, 80,
"%s\n"
"%s\n"
"\n"
"%s SCred\n",
outfit->name,
outfit_getType(outfit),
buf2);
window_modifyText(secondary_wid, "txtDDesc", buf);
}
static void outfits_buy(char* str) {
(void)str;
char* outfitname;
Outfit* outfit;
int q;
outfitname = toolkit_getList(secondary_wid, "lstOutfits");
outfit = outfit_get(outfitname);
q = 1; // Q should be dependant on MOD keys. TODO
pilot_addOutfit(player, outfit, q);
}
static void shipyard(void) {
char** ships;
int nships;
@ -174,7 +247,7 @@ static void shipyard_update(char* str) {
"%s\n"
"%s\n"
"\n"
"%s Scred\n",
"%s SCred\n",
ship->name,
ship_class(ship),
ship->fabricator,

View File

@ -38,6 +38,16 @@ Outfit* outfit_get(const char* name) {
return NULL;
}
// Return all the outfits.
char** outfit_getAll(int* n) {
char** outfitnames = malloc(sizeof(Outfit*) * outfits);
for((*n) = 0; (*n) < outfits; (*n)++)
outfitnames[*n] = strdup(outfit_stack[*n].name);
return outfitnames;
}
// Return 1 if outfit is a weapon (beam/bolt).
int outfit_isWeapon(const Outfit* o) {
return ((o->type == OUTFIT_TYPE_BOLT) || (o->type == OUTFIT_TYPE_BEAM));
@ -263,6 +273,7 @@ static Outfit* outfit_parse(const xmlNodePtr parent) {
else if(xml_isNode(cur, "tech")) tmp->tech = xml_getInt(cur);
else if(xml_isNode(cur, "mass")) tmp->mass = xml_getInt(cur);
else if(xml_isNode(cur, "price")) tmp->price = xml_getInt(cur);
else if(xml_isNode(cur, "description")) tmp->description = strdup(xml_get(cur));
} while((cur = cur->next));
}
else if(xml_isNode(node, "specific")) {
@ -300,6 +311,7 @@ static Outfit* outfit_parse(const xmlNodePtr parent) {
//MELEMENT(tmp->mass==0, "mass");
MELEMENT(tmp->type==0, "type");
MELEMENT(tmp->price==0, "price");
MELEMENT(tmp->description==NULL, "description");
#undef MELEMENT
return tmp;
@ -350,14 +362,16 @@ void outfit_free(void) {
int i;
for(i = 0; i < outfits; i++) {
// Free graphics.
if(outfit_isWeapon(&outfit_stack[i]) && outfit_stack[i].u.wpn.gfx_space)
gl_freeTexture(outfit_stack[i].u.wpn.gfx_space);
else if(outfit_isAmmo(&outfit_stack[i]) && outfit_stack[i].u.amm.gfx_space)
gl_freeTexture(outfit_stack[i].u.amm.gfx_space);
if(outfit_gfx(&outfit_stack[i]))
gl_freeTexture(outfit_gfx(&outfit_stack[i]));
// Strings.
if(outfit_isLauncher(&outfit_stack[i]) && outfit_stack[i].u.lau.ammo)
free(outfit_stack[i].u.lau.ammo);
if(outfit_stack[i].description)
free(outfit_stack[i].description);
free(outfit_stack[i].name);
}
free(outfit_stack);

View File

@ -33,7 +33,10 @@ typedef struct Outfit_ {
int max;
int tech;
int mass;
// Store stuff.
unsigned int price;
char* description;
glTexture gfx_store; // Store graphic.
@ -72,7 +75,9 @@ typedef struct Outfit_ {
} u;
} Outfit;
// Get.
Outfit* outfit_get(const char* name);
char** outfit_getAll(int* n);
// Outfit types.
int outfit_isWeapon(const Outfit* o);
int outfit_isLauncher(const Outfit* o);

View File

@ -381,6 +381,36 @@ static void pilot_hyperspace(Pilot* p) {
}
}
void pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
int i;
char* s;
for(i = 0; i < pilot->noutfits; i++)
if(strcmp(outfit->name, pilot->outfits[i].outfit->name)==0) {
pilot->outfits[i].quantity += quantity;
return;
}
s = (pilot->secondary) ? pilot->secondary->outfit->name : NULL;
pilot->outfits = realloc(pilot->outfits, (pilot->noutfits+1)*sizeof(PilotOutfit));
pilot->outfits[pilot->noutfits].outfit = outfit;
pilot->outfits[pilot->noutfits].quantity = quantity;
pilot->outfits[pilot->noutfits].timer = 0;
if(outfit_isTurret(outfit))
// Used to speed up AI.
pilot_setFlag(pilot, PILOT_HASTURRET);
// Hack due to realloc possibility.
if(s) {
for(i = 0; i < pilot->noutfits; i++)
if(strcmp(s, pilot->outfits[i].outfit->name)==0) {
pilot->secondary = &pilot->outfits[i];
break;
}
}
}
// ==Init pilot.===========================================
// ship : Ship pilot is flying.
// name : Pilot's name, if NULL, ships name will be used.

View File

@ -117,6 +117,7 @@ void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter,
const double damage_shield, const double damage_armour);
void pilot_setAmmo(Pilot* p);
double pilot_face(Pilot* p, const float dir);
void pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity);
// Creation.
void pilot_init(Pilot* dest, Ship* ship, char* name, Faction* faction, AI_Profile* ai,