[Add] Save purchased ships in a stack. Just need to be able to change them.
This commit is contained in:
parent
829d24eb79
commit
697876409e
44
src/land.c
44
src/land.c
@ -41,7 +41,7 @@ int landed = 0;
|
|||||||
static int land_wid = 0; // Primary land window.
|
static int land_wid = 0; // Primary land window.
|
||||||
// For the second opened land window (We can only have 2 max).
|
// For the second opened land window (We can only have 2 max).
|
||||||
static int secondary_wid = 0;
|
static int secondary_wid = 0;
|
||||||
static Planet* planet = NULL;
|
Planet* land_planet = NULL;
|
||||||
|
|
||||||
// Commodity excahnge.
|
// Commodity excahnge.
|
||||||
static void commodity_exchange(void);
|
static void commodity_exchange(void);
|
||||||
@ -102,13 +102,14 @@ static void commodity_exchange(void) {
|
|||||||
window_addText(secondary_wid, -40, -100, BUTTON_WIDTH-20,
|
window_addText(secondary_wid, -40, -100, BUTTON_WIDTH-20,
|
||||||
BUTTON_WIDTH, 0, "txtDesc", &gl_smallFont, &cBlack, NULL);
|
BUTTON_WIDTH, 0, "txtDesc", &gl_smallFont, &cBlack, NULL);
|
||||||
|
|
||||||
goods = malloc(sizeof(char*)*planet->ncommodities);
|
goods = malloc(sizeof(char*)*land_planet->ncommodities);
|
||||||
for(i = 0; i < planet->ncommodities; i++)
|
for(i = 0; i < land_planet->ncommodities; i++)
|
||||||
goods[i] = strdup(planet->commodities[i]->name);
|
goods[i] = strdup(land_planet->commodities[i]->name);
|
||||||
|
|
||||||
window_addList(secondary_wid, 20, -40,
|
window_addList(secondary_wid, 20, -40,
|
||||||
COMMODITY_WIDTH-BUTTON_WIDTH-60, COMMODITY_HEIGHT-80-BUTTON_HEIGHT,
|
COMMODITY_WIDTH-BUTTON_WIDTH-60,
|
||||||
"lstGoods", goods, planet->ncommodities, 0, commodity_update);
|
COMMODITY_HEIGHT-80-BUTTON_HEIGHT, "lstGoods",
|
||||||
|
goods, land_planet->ncommodities, 0, commodity_update);
|
||||||
|
|
||||||
commodity_update(NULL);
|
commodity_update(NULL);
|
||||||
}
|
}
|
||||||
@ -185,7 +186,7 @@ static void outfits(void) {
|
|||||||
int noutfits;
|
int noutfits;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
snprintf(buf, 128, "%s - Outfits", planet->name);
|
snprintf(buf, 128, "%s - Outfits", land_planet->name);
|
||||||
secondary_wid = window_create(buf, -1, -1,
|
secondary_wid = window_create(buf, -1, -1,
|
||||||
OUTFITS_WIDTH, OUTFITS_HEIGHT);
|
OUTFITS_WIDTH, OUTFITS_HEIGHT);
|
||||||
|
|
||||||
@ -229,7 +230,7 @@ static void outfits(void) {
|
|||||||
&gl_smallFont, NULL, NULL);
|
&gl_smallFont, NULL, NULL);
|
||||||
|
|
||||||
// Set up the outfits to buy/sell.
|
// Set up the outfits to buy/sell.
|
||||||
outfits = outfit_getTech(&noutfits, planet->tech, PLANET_TECH_MAX);
|
outfits = outfit_getTech(&noutfits, land_planet->tech, PLANET_TECH_MAX);
|
||||||
window_addList(secondary_wid, 20, 40,
|
window_addList(secondary_wid, 20, 40,
|
||||||
200, OUTFITS_HEIGHT-80, "lstOutfits",
|
200, OUTFITS_HEIGHT-80, "lstOutfits",
|
||||||
outfits, noutfits, 0, outfits_update);
|
outfits, noutfits, 0, outfits_update);
|
||||||
@ -371,7 +372,7 @@ static void shipyard(void) {
|
|||||||
int nships;
|
int nships;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
snprintf(buf, 128, "%s - Shipyard", planet->name);
|
snprintf(buf, 128, "%s - Shipyard", land_planet->name);
|
||||||
secondary_wid = window_create(buf,
|
secondary_wid = window_create(buf,
|
||||||
-1, -1, SHIPYARD_WIDTH, SHIPYARD_HEIGHT);
|
-1, -1, SHIPYARD_WIDTH, SHIPYARD_HEIGHT);
|
||||||
|
|
||||||
@ -411,7 +412,7 @@ static void shipyard(void) {
|
|||||||
&gl_smallFont, NULL, NULL);
|
&gl_smallFont, NULL, NULL);
|
||||||
|
|
||||||
// Setup the ships to buy/sell.
|
// Setup the ships to buy/sell.
|
||||||
ships = ship_getTech(&nships, planet->tech, PLANET_TECH_MAX);
|
ships = ship_getTech(&nships, land_planet->tech, PLANET_TECH_MAX);
|
||||||
window_addList(secondary_wid, 20, 40,
|
window_addList(secondary_wid, 20, 40,
|
||||||
200, SHIPYARD_HEIGHT-80, "lstShipyard",
|
200, SHIPYARD_HEIGHT-80, "lstShipyard",
|
||||||
ships, nships, 0, shipyard_update);
|
ships, nships, 0, shipyard_update);
|
||||||
@ -482,7 +483,8 @@ static void spaceport_bar(void) {
|
|||||||
|
|
||||||
window_addText(secondary_wid, 20, -30,
|
window_addText(secondary_wid, 20, -30,
|
||||||
BAR_WIDTH-40, BAR_HEIGHT - 40 - BUTTON_HEIGHT, 0,
|
BAR_WIDTH-40, BAR_HEIGHT - 40 - BUTTON_HEIGHT, 0,
|
||||||
"txtDescription", &gl_smallFont, &cBlack, planet->bar_description);
|
"txtDescription", &gl_smallFont, &cBlack,
|
||||||
|
land_planet->bar_description);
|
||||||
|
|
||||||
window_addButton(secondary_wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
|
window_addButton(secondary_wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||||
"btnCloseBar", "Close", spaceport_bar_close);
|
"btnCloseBar", "Close", spaceport_bar_close);
|
||||||
@ -526,7 +528,7 @@ void land(Planet* p) {
|
|||||||
music_load(MUSIC_LAND);
|
music_load(MUSIC_LAND);
|
||||||
music_play();
|
music_play();
|
||||||
|
|
||||||
planet = p;
|
land_planet = p;
|
||||||
land_wid = window_create(p->name, -1, -1, LAND_WIDTH, LAND_HEIGHT);
|
land_wid = window_create(p->name, -1, -1, LAND_WIDTH, LAND_HEIGHT);
|
||||||
|
|
||||||
// Pretty display.
|
// Pretty display.
|
||||||
@ -537,25 +539,26 @@ void land(Planet* p) {
|
|||||||
window_addButton(land_wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
|
window_addButton(land_wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||||
"btnTakeoff", "Takeoff", (void(*)(char*))takeoff);
|
"btnTakeoff", "Takeoff", (void(*)(char*))takeoff);
|
||||||
|
|
||||||
if(planet_hasService(planet, PLANET_SERVICE_COMMODITY))
|
if(planet_hasService(land_planet, PLANET_SERVICE_COMMODITY))
|
||||||
window_addButton(land_wid, -20, 20 + BUTTON_HEIGHT + 20,
|
window_addButton(land_wid, -20, 20 + BUTTON_HEIGHT + 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodity",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodity",
|
||||||
"Commodity Exchange", (void(*)(char*))commodity_exchange);
|
"Commodity Exchange", (void(*)(char*))commodity_exchange);
|
||||||
|
|
||||||
if(planet_hasService(planet, PLANET_SERVICE_SHIPYARD))
|
if(planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD))
|
||||||
window_addButton(land_wid, -20 - BUTTON_WIDTH - 20, 20,
|
window_addButton(land_wid, -20 - BUTTON_WIDTH - 20, 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnShipyard",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnShipyard",
|
||||||
"Shipyard", (void(*)(char*))shipyard);
|
"Shipyard", (void(*)(char*))shipyard);
|
||||||
|
|
||||||
if(planet_hasService(planet, PLANET_SERVICE_OUTFITS))
|
if(planet_hasService(land_planet, PLANET_SERVICE_OUTFITS))
|
||||||
window_addButton(land_wid, -20 - BUTTON_WIDTH - 20, 20 + BUTTON_HEIGHT + 20,
|
window_addButton(land_wid, -20 - BUTTON_WIDTH - 20, 20 + BUTTON_HEIGHT + 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnOutfits",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnOutfits",
|
||||||
"Outfits", (void(*)(char*))outfits);
|
"Outfits", (void(*)(char*))outfits);
|
||||||
|
|
||||||
if(planet_hasService(planet, PLANET_SERVICE_BASIC)) {
|
if(planet_hasService(land_planet, PLANET_SERVICE_BASIC)) {
|
||||||
window_addButton(land_wid, 20, 20,
|
window_addButton(land_wid, 20, 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnNews",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnNews",
|
||||||
"Mission Terminal", NULL);
|
"Mission Terminal", NULL);
|
||||||
|
|
||||||
window_addButton(land_wid, 20, 20 + BUTTON_HEIGHT + 20,
|
window_addButton(land_wid, 20, 20 + BUTTON_HEIGHT + 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnBar",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnBar",
|
||||||
"Spaceport Bar", (void(*)(char*))spaceport_bar);
|
"Spaceport Bar", (void(*)(char*))spaceport_bar);
|
||||||
@ -573,14 +576,15 @@ void takeoff(void) {
|
|||||||
music_play();
|
music_play();
|
||||||
|
|
||||||
int sw, sh;
|
int sw, sh;
|
||||||
sw = planet->gfx_space->w;
|
sw = land_planet->gfx_space->w;
|
||||||
sh = planet->gfx_space->h;
|
sh = land_planet->gfx_space->h;
|
||||||
|
|
||||||
// No longer authorized to land.
|
// No longer authorized to land.
|
||||||
player_rmFlag(PLAYER_LANDACK);
|
player_rmFlag(PLAYER_LANDACK);
|
||||||
|
|
||||||
// Set player to another position with random facing direction and no velocity.
|
// Set player to another position with random facing direction and no velocity.
|
||||||
player_warp(planet->pos.x + RNG(-sw/2, sw/2), planet->pos.y + RNG(-sh/2, sh/2));
|
player_warp(land_planet->pos.x + RNG(-sw/2, sw/2),
|
||||||
|
land_planet->pos.y + RNG(-sh/2, sh/2));
|
||||||
vect_pset(&player->solid->vel, 0., 0.);
|
vect_pset(&player->solid->vel, 0., 0.);
|
||||||
player->solid->dir = RNG(0, 359) * M_PI/180.;
|
player->solid->dir = RNG(0, 359) * M_PI/180.;
|
||||||
|
|
||||||
@ -591,7 +595,7 @@ void takeoff(void) {
|
|||||||
|
|
||||||
space_init(NULL);
|
space_init(NULL);
|
||||||
|
|
||||||
planet = NULL;
|
land_planet = NULL;
|
||||||
window_destroy(land_wid);
|
window_destroy(land_wid);
|
||||||
landed = 0;
|
landed = 0;
|
||||||
}
|
}
|
||||||
|
@ -205,6 +205,7 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unload data.
|
// Unload data.
|
||||||
|
player_cleanup(); // Cleans up the player stuff.
|
||||||
weapon_exit(); // Destroy all active weapons.
|
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:
|
||||||
|
@ -49,7 +49,7 @@ static void pilot_update(Pilot* pilot, const double dt);
|
|||||||
static void pilot_hyperspace(Pilot* pilot);
|
static void pilot_hyperspace(Pilot* pilot);
|
||||||
void pilot_render(Pilot* pilot);
|
void pilot_render(Pilot* pilot);
|
||||||
static void pilot_calcStats(Pilot* pilot);
|
static void pilot_calcStats(Pilot* pilot);
|
||||||
static void pilot_free(Pilot* p);
|
void pilot_free(Pilot* p);
|
||||||
static Fleet* fleet_parse(const xmlNodePtr parent);
|
static Fleet* fleet_parse(const xmlNodePtr parent);
|
||||||
static void pilot_dead(Pilot* p);
|
static void pilot_dead(Pilot* p);
|
||||||
static int pilot_oquantity(Pilot* p, PilotOutfit* w);
|
static int pilot_oquantity(Pilot* p, PilotOutfit* w);
|
||||||
@ -749,7 +749,8 @@ unsigned int pilot_create(Ship* ship, char* name, Faction* faction,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy src pilot to dest.
|
// Copy src pilot to dest.
|
||||||
void pilot_copy(Pilot* dest, Pilot* src) {
|
Pilot* pilot_copy(Pilot* src) {
|
||||||
|
Pilot* dest = malloc(sizeof(Pilot));
|
||||||
memcpy(dest, src, sizeof(Pilot));
|
memcpy(dest, src, sizeof(Pilot));
|
||||||
if(src->name) dest->name = strdup(src->name);
|
if(src->name) dest->name = strdup(src->name);
|
||||||
|
|
||||||
@ -775,10 +776,12 @@ void pilot_copy(Pilot* dest, Pilot* src) {
|
|||||||
|
|
||||||
// Will set afterburner and correct stats.
|
// Will set afterburner and correct stats.
|
||||||
pilot_calcStats(dest);
|
pilot_calcStats(dest);
|
||||||
|
|
||||||
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Frees and cleans up a pilot.
|
// Frees and cleans up a pilot.
|
||||||
static void pilot_free(Pilot* p) {
|
void pilot_free(Pilot* p) {
|
||||||
if(player == p) player = NULL;
|
if(player == p) player = NULL;
|
||||||
solid_free(p->solid);
|
solid_free(p->solid);
|
||||||
if(p->outfits) free(p->outfits);
|
if(p->outfits) free(p->outfits);
|
||||||
|
@ -149,12 +149,13 @@ unsigned int pilot_create(Ship* ship, char* name, Faction* faction,
|
|||||||
AI_Profile* ai, const double dir, const Vec2* pos,
|
AI_Profile* ai, const double dir, const Vec2* pos,
|
||||||
const Vec2* vel, const int flags);
|
const Vec2* vel, const int flags);
|
||||||
|
|
||||||
void pilot_copy(Pilot* dest, Pilot* src);
|
Pilot* pilot_copy(Pilot* src);
|
||||||
|
|
||||||
// Init/Cleanup.
|
// Init/Cleanup.
|
||||||
void pilot_destroy(Pilot* p);
|
void pilot_destroy(Pilot* p);
|
||||||
void pilots_free(void);
|
void pilots_free(void);
|
||||||
void pilots_clean(void);
|
void pilots_clean(void);
|
||||||
|
void pilot_free(Pilot* p);
|
||||||
int fleet_load(void); // TODO
|
int fleet_load(void); // TODO
|
||||||
void fleet_free(void);
|
void fleet_free(void);
|
||||||
|
|
||||||
|
42
src/player.c
42
src/player.c
@ -32,6 +32,10 @@ Pilot* player = NULL; // extern in pilot.h
|
|||||||
static Ship* player_ship = NULL; // Temp ship to hold when naming it.
|
static Ship* player_ship = NULL; // Temp ship to hold when naming it.
|
||||||
// More hacks.
|
// More hacks.
|
||||||
static double player_px, player_py, player_vx, player_vy, player_dir;
|
static double player_px, player_py, player_vx, player_vy, player_dir;
|
||||||
|
// Player pilot stack - Ships she owns.
|
||||||
|
static Pilot** player_stack = NULL;
|
||||||
|
static char** player_lstack = NULL; // Names of the planet the ships are at.
|
||||||
|
static int player_nstack = 0;
|
||||||
// Player global properties.
|
// Player global properties.
|
||||||
char* player_name = NULL; // Player name.
|
char* player_name = NULL; // Player name.
|
||||||
int player_credits = 0; // Ze monies.
|
int player_credits = 0; // Ze monies.
|
||||||
@ -55,6 +59,9 @@ extern int pilots;
|
|||||||
// Space stuff for GUI.
|
// Space stuff for GUI.
|
||||||
extern StarSystem* systems_stack;
|
extern StarSystem* systems_stack;
|
||||||
|
|
||||||
|
// Land stuff for the player_stack.
|
||||||
|
extern Planet* land_planet;
|
||||||
|
|
||||||
// GUI crap.
|
// GUI crap.
|
||||||
typedef struct Radar_ {
|
typedef struct Radar_ {
|
||||||
double x,y; // Position.
|
double x,y; // Position.
|
||||||
@ -135,10 +142,14 @@ void player_destroyed(void);
|
|||||||
void player_new(void) {
|
void player_new(void) {
|
||||||
unsigned int wid;
|
unsigned int wid;
|
||||||
|
|
||||||
|
// Let's not seg fault due to a lack of environment.
|
||||||
player_setFlag(PLAYER_DESTROYED);
|
player_setFlag(PLAYER_DESTROYED);
|
||||||
vectnull(&player_cam);
|
vectnull(&player_cam);
|
||||||
gl_bindCamera(&player_cam);
|
gl_bindCamera(&player_cam);
|
||||||
|
|
||||||
|
// Cleanup player stuff if we'll be re-creating.
|
||||||
|
player_cleanup();
|
||||||
|
|
||||||
wid = window_create("Player Name", -1, -1, 240, 140);
|
wid = window_create("Player Name", -1, -1, 240, 140);
|
||||||
|
|
||||||
window_addText(wid, 30, -30, 180, 20, 0, "txtInfo",
|
window_addText(wid, 30, -30, 180, 20, 0, "txtInfo",
|
||||||
@ -152,7 +163,6 @@ static void player_nameClose(char* str) {
|
|||||||
unsigned int wid;
|
unsigned int wid;
|
||||||
|
|
||||||
wid = window_get("Player Name");
|
wid = window_get("Player Name");
|
||||||
if(player_name) free(player_name);
|
|
||||||
player_name = strdup(window_getInput(wid, "inpName"));
|
player_name = strdup(window_getInput(wid, "inpName"));
|
||||||
window_destroy(wid);
|
window_destroy(wid);
|
||||||
|
|
||||||
@ -267,8 +277,14 @@ static void player_nameShipClose(char* str) {
|
|||||||
// Change the players ship.
|
// Change the players ship.
|
||||||
static void player_newShipMake(char* name) {
|
static void player_newShipMake(char* name) {
|
||||||
Vec2 vp, vv;
|
Vec2 vp, vv;
|
||||||
if(player)
|
if(player) {
|
||||||
|
player_stack = realloc(player_stack, sizeof(Pilot*)*(player_nstack+1));
|
||||||
|
player_stack[player_nstack] = pilot_copy(player);
|
||||||
|
player_lstack = realloc(player_lstack, sizeof(char*)*(player_nstack+1));
|
||||||
|
player_lstack[player_nstack] = strdup(land_planet->name);
|
||||||
|
player_nstack++;
|
||||||
pilot_destroy(player);
|
pilot_destroy(player);
|
||||||
|
}
|
||||||
|
|
||||||
// In case we're respawning.
|
// In case we're respawning.
|
||||||
player_rmFlag(PLAYER_DESTROYED);
|
player_rmFlag(PLAYER_DESTROYED);
|
||||||
@ -282,6 +298,28 @@ static void player_newShipMake(char* name) {
|
|||||||
gl_bindCamera(&player->solid->pos); // Set opengl camera.
|
gl_bindCamera(&player->solid->pos); // Set opengl camera.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up player stuff like player_stack.
|
||||||
|
void player_cleanup(void) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// Cleanup name.
|
||||||
|
if(player_name) free(player_name);
|
||||||
|
|
||||||
|
// Clean up the stack.
|
||||||
|
if(player_stack) {
|
||||||
|
for(i = 0; i < player_nstack; i++) {
|
||||||
|
pilot_free(player_stack[i]);
|
||||||
|
free(player_lstack[i]);
|
||||||
|
}
|
||||||
|
free(player_stack);
|
||||||
|
player_stack = NULL;
|
||||||
|
free(player_lstack);
|
||||||
|
player_lstack = NULL;
|
||||||
|
// Nothing left.
|
||||||
|
player_nstack = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void player_message(const char* fmt, ...) {
|
void player_message(const char* fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int i;
|
int i;
|
||||||
|
@ -29,10 +29,11 @@ extern int combat_crating;
|
|||||||
// For render functions.
|
// For render functions.
|
||||||
typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape;
|
typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape;
|
||||||
|
|
||||||
// Creation.
|
// Creation/Cleanup.
|
||||||
void player_new(void);
|
void player_new(void);
|
||||||
void player_newShip(Ship* ship, double px, double py,
|
void player_newShip(Ship* ship, double px, double py,
|
||||||
double vx, double vy, double dir);
|
double vx, double vy, double dir);
|
||||||
|
void player_cleanup(void);
|
||||||
|
|
||||||
// Render.
|
// Render.
|
||||||
int gui_init(void);
|
int gui_init(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user