/** * @brief Checks if should add the refuel button and does if needed. */ void land_checkAddRefuel (void) { char buf[ECON_CRED_STRLEN], cred[ECON_CRED_STRLEN]; unsigned int w; /* Check to see if fuel conditions are met. */ if (!planet_hasService(land_planet, PLANET_SERVICE_REFUEL)) { if (!widget_exists( land_windows[0], "txtRefuel" )) window_addText( land_windows[0], -20, 20 + (LAND_BUTTON_HEIGHT + 20) + 20, 200, gl_defFont.h, 1, "txtRefuel", &gl_defFont, &cBlack, "No refueling services." ); return; } /* Full fuel. */ if (player.p->fuel >= player.p->fuel_max) { if (widget_exists( land_windows[0], "btnRefuel" )) window_destroyWidget( land_windows[0], "btnRefuel" ); if (widget_exists( land_windows[0], "txtRefuel" )) window_destroyWidget( land_windows[0], "txtRefuel" ); return; } /* Autorefuel. */ if (conf.autorefuel) { spaceport_refuel( land_windows[0], "btnRefuel" ); w = land_getWid( LAND_WINDOW_EQUIPMENT ); if (w > 0) equipment_updateShips( w, NULL ); /* Must update counter. */ if (player.p->fuel >= player.p->fuel_max) return; } /* Just enable button if it exists. */ if (widget_exists( land_windows[0], "btnRefuel" )) { window_enableButton( land_windows[0], "btnRefuel"); credits2str( cred, player.p->credits, 2 ); snprintf( buf, sizeof(buf), "Credits: %s", cred ); window_modifyText( land_windows[0], "txtRefuel", buf ); } /* Else create it. */ else { /* Refuel button. */ credits2str( cred, refuel_price(), 2 ); snprintf( buf, sizeof(buf), "Refuel %s", cred ); window_addButton( land_windows[0], -20, 20 + (LAND_BUTTON_HEIGHT + 20), LAND_BUTTON_WIDTH,LAND_BUTTON_HEIGHT, "btnRefuel", buf, spaceport_refuel ); /* Player credits. */ credits2str( cred, player.p->credits, 2 ); snprintf( buf, sizeof(buf), "Credits: %s", cred ); window_addText( land_windows[0], -20, 20 + 2*(LAND_BUTTON_HEIGHT + 20), LAND_BUTTON_WIDTH, gl_smallFont.h, 1, "txtRefuel", &gl_smallFont, &cBlack, buf ); } /* Make sure player can click it. */ if (!player_hasCredits( refuel_price() )) window_disableButton( land_windows[0], "btnRefuel" ); }
/** * @brief Buys a local system map. */ static void spaceport_buyMap( unsigned int wid, char *str ) { (void) wid; (void) str; Outfit *o; unsigned int w; /* Make sure the map isn't already known, etc. */ if (land_errDialogue( LOCAL_MAP_NAME, "buyOutfit" )) return; o = outfit_get( LOCAL_MAP_NAME ); if (o == NULL) { WARN("Outfit '%s' does not exist!", LOCAL_MAP_NAME); return; } player_modCredits( -o->price ); player_addOutfit(o, 1); /* Disable the button. */ window_disableButtonSoft( land_windows[0], "btnMap" ); /* Update map quantity in outfitter. */ w = land_getWid( LAND_WINDOW_OUTFITS ); if (w > 0) outfits_regenList( w, NULL ); }
/** * @brief Player attempts to buy a ship, trading the current ship in. * @param wid Window player is buying ship from. * @param str Unused. */ static void shipyard_trade( unsigned int wid, char* str ) { (void)str; char *shipname, buf[ECON_CRED_STRLEN], buf2[ECON_CRED_STRLEN], buf3[ECON_CRED_STRLEN], buf4[ECON_CRED_STRLEN]; Ship* ship; shipname = toolkit_getImageArray( wid, "iarShipyard" ); if (strcmp(shipname, "None") == 0) return; ship = ship_get( shipname ); credits_t targetprice = ship_buyPrice(ship); credits_t playerprice = player_shipPrice(player.p->name); if (land_errDialogue( shipname, "tradeShip" )) return; credits2str( buf, targetprice, 2 ); credits2str( buf2, playerprice, 2 ); credits2str( buf3, targetprice - playerprice, 2 ); credits2str( buf4, playerprice - targetprice, 2 ); /* Display the correct dialogue depending on the new ship's price versus the player's. */ if ( targetprice == playerprice ) { if (dialogue_YesNo("Are you sure?", /* confirm */ "Your %s is worth %s, exactly as much as the new ship, so no credits need be exchanged. Are you sure you want to trade your ship in?", player.p->ship->name, buf2)==0) return; } else if ( targetprice < playerprice ) { if (dialogue_YesNo("Are you sure?", /* confirm */ "Your %s is worth %s credits, more than the new ship. For your ship, you will get the new %s and %s credits. Are you sure you want to trade your ship in?", player.p->ship->name, buf2, ship->name, buf4)==0) return; } else if ( targetprice > playerprice ) { if (dialogue_YesNo("Are you sure?", /* confirm */ "Your %s is worth %s, so the new ship will cost %s credits. Are you sure you want to trade your ship in?", player.p->ship->name, buf2, buf3)==0) return; } /* player just got a new ship */ if (player_newShip( ship, NULL, 1, 0 ) == NULL) return; /* Player aborted the naming process. */ player_modCredits( playerprice - targetprice ); /* Modify credits by the difference between ship values. */ land_refuel(); /* The newShip call will trigger a loadGUI that will recreate the land windows. Therefore the land ID will * be void. We must reload in in order to properly update it again.*/ wid = land_getWid(LAND_WINDOW_SHIPYARD); /* Update shipyard. */ shipyard_update(wid, NULL); }
/** * @brief Updates the outfitter and equipment outfit image arrays. */ void outfits_updateEquipmentOutfits( void ) { int ew, ow; if (landed && land_doneLoading()) { if planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) { ow = land_getWid( LAND_WINDOW_OUTFITS ); outfits_update(ow, NULL); outfits_updateQuantities(ow); } else if (!planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD))
/** * @brief Renders the commodity buying modifier. * @param bx Base X position to render at. * @param by Base Y position to render at. * @param w Width to render at. * @param h Height to render at. */ static void commodity_renderMod( double bx, double by, double w, double h, void *data ) { (void) data; (void) h; int q; char buf[8]; q = commodity_getMod(); if (q != commodity_mod) { commodity_update( land_getWid(LAND_WINDOW_COMMODITY), NULL ); commodity_mod = q; } nsnprintf( buf, 8, "%dx", q ); gl_printMid( &gl_smallFont, w, bx, by, &cBlack, buf ); }
/** * @brief Refuels the player's current ship, if possible. */ void land_refuel (void) { unsigned int w; /* Full fuel. */ if (player.p->fuel >= player.p->fuel_max) return; /* No refuel service. */ if (!planet_hasService(land_planet, PLANET_SERVICE_REFUEL)) return; player.p->fuel = player.p->fuel_max; w = land_getWid( LAND_WINDOW_EQUIPMENT ); if (w > 0) equipment_updateShips( w, NULL ); /* Must update counter. */ }
/** * @brief Regenerates the bar list. */ void bar_regen (void) { if (!landed) return; bar_genList( land_getWid(LAND_WINDOW_BAR) ); }
/** * @brief Saves the last place the player was. * * @param wid Unused. * @param wgt Unused. * @param tab Tab changed to. */ static void land_changeTab( unsigned int wid, char *wgt, int tab ) { int i; (void) wid; (void) wgt; unsigned int w; const char *torun_hook; unsigned int to_visit; /* Sane defaults. */ torun_hook = NULL; to_visit = 0; /* Find what switched. */ for (i=0; i<LAND_NUMWINDOWS; i++) { if (land_windowsMap[i] == tab) { last_window = i; w = land_getWid( i ); /* Must regenerate outfits. */ switch (i) { case LAND_WINDOW_MAIN: land_checkAddRefuel(); break; case LAND_WINDOW_OUTFITS: outfits_update( w, NULL ); outfits_updateQuantities( w ); to_visit = VISITED_OUTFITS; torun_hook = "outfits"; break; case LAND_WINDOW_SHIPYARD: shipyard_update( w, NULL ); to_visit = VISITED_SHIPYARD; torun_hook = "shipyard"; break; case LAND_WINDOW_BAR: bar_update( w, NULL ); to_visit = VISITED_BAR; torun_hook = "bar"; break; case LAND_WINDOW_MISSION: misn_update( w, NULL ); to_visit = VISITED_MISSION; torun_hook = "mission"; break; case LAND_WINDOW_COMMODITY: commodity_update( w, NULL ); to_visit = VISITED_COMMODITY; torun_hook = "commodity"; break; case LAND_WINDOW_EQUIPMENT: equipment_updateShips( w, NULL ); equipment_updateOutfits( w, NULL ); to_visit = VISITED_EQUIPMENT; torun_hook = "equipment"; break; default: break; } /* Clear markers if closing Mission Computer. */ if (i != LAND_WINDOW_MISSION) { space_clearComputerMarkers(); } break; } } /* Check land missions - always run hooks. */ /*if ((to_visit != 0) && !has_visited(to_visit)) {*/ { /* Run hooks, run after music in case hook wants to change music. */ if (torun_hook != NULL) if (hooks_run( torun_hook ) > 0) bar_genList( land_getWid(LAND_WINDOW_BAR) ); visited(to_visit); if (land_takeoff) takeoff(1); } }
/** * @brief Recreates the land windows. * * @param load Is loading game? * @param changetab Should it change to the last open tab? */ void land_genWindows( int load, int changetab ) { int i, j; const char *names[LAND_NUMWINDOWS]; int w, h; Planet *p; int regen; /* Destroy old window if exists. */ if (land_wid > 0) { land_regen = 2; /* Mark we're regenning. */ window_destroy(land_wid); } land_loaded = 0; /* Get planet. */ p = land_planet; regen = landed; /* Create window. */ if ((SCREEN_W < 1024) || (SCREEN_H < 768)) { w = -1; /* Fullscreen. */ h = -1; } else { w = 800 + 0.5 * (SCREEN_W - 800); h = 600 + 0.5 * (SCREEN_H - 600); } land_wid = window_create( p->name, -1, -1, w, h ); window_onClose( land_wid, land_cleanupWindow ); /* Set window map to invalid. */ for (i=0; i<LAND_NUMWINDOWS; i++) land_windowsMap[i] = -1; /* See what is available. */ j = 0; /* Main. */ land_windowsMap[LAND_WINDOW_MAIN] = j; names[j++] = land_windowNames[LAND_WINDOW_MAIN]; /* Bar. */ if (planet_hasService(land_planet, PLANET_SERVICE_BAR)) { land_windowsMap[LAND_WINDOW_BAR] = j; names[j++] = land_windowNames[LAND_WINDOW_BAR]; } /* Missions. */ if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS)) { land_windowsMap[LAND_WINDOW_MISSION] = j; names[j++] = land_windowNames[LAND_WINDOW_MISSION]; } /* Outfits. */ if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS)) { land_windowsMap[LAND_WINDOW_OUTFITS] = j; names[j++] = land_windowNames[LAND_WINDOW_OUTFITS]; } /* Shipyard. */ if (planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) { land_windowsMap[LAND_WINDOW_SHIPYARD] = j; names[j++] = land_windowNames[LAND_WINDOW_SHIPYARD]; } /* Equipment. */ if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) || planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) { land_windowsMap[LAND_WINDOW_EQUIPMENT] = j; names[j++] = land_windowNames[LAND_WINDOW_EQUIPMENT]; } /* Commodity. */ if (planet_hasService(land_planet, PLANET_SERVICE_COMMODITY)) { land_windowsMap[LAND_WINDOW_COMMODITY] = j; names[j++] = land_windowNames[LAND_WINDOW_COMMODITY]; } /* Create tabbed window. */ land_windows = window_addTabbedWindow( land_wid, -1, -1, -1, -1, "tabLand", j, names ); /* * Order here is very important: * * 1) Create main tab - must have decent background. * 2) Set landed, play music and run land hooks - so hooks run well. * 3) Generate missions - so that campaigns are fluid. * 4) Create other tabs - lists depend on NPC and missions. */ /* 1) Create main tab. */ land_createMainTab( land_getWid(LAND_WINDOW_MAIN) ); /* 2) Set as landed and run hooks. */ if (!regen) { landed = 1; music_choose("land"); /* Must be before hooks in case hooks change music. */ if (!load) { events_trigger( EVENT_TRIGGER_LAND ); hooks_run("land"); } /* 3) Generate computer and bar missions. */ if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS)) mission_computer = missions_genList( &mission_ncomputer, land_planet->faction, land_planet->name, cur_system->name, MIS_AVAIL_COMPUTER ); if (planet_hasService(land_planet, PLANET_SERVICE_BAR)) npc_generate(); /* Generate bar npc. */ } /* 4) Create other tabs. */ /* Basic - bar + missions */ if (planet_hasService(land_planet, PLANET_SERVICE_BAR)) bar_open( land_getWid(LAND_WINDOW_BAR) ); if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS)) misn_open( land_getWid(LAND_WINDOW_MISSION) ); /* Outfits. */ if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS)) outfits_open( land_getWid(LAND_WINDOW_OUTFITS) ); /* Shipyard. */ if (planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) shipyard_open( land_getWid(LAND_WINDOW_SHIPYARD) ); /* Equipment. */ if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) || planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) equipment_open( land_getWid(LAND_WINDOW_EQUIPMENT) ); /* Commodity. */ if (planet_hasService(land_planet, PLANET_SERVICE_COMMODITY)) commodity_exchange_open( land_getWid(LAND_WINDOW_COMMODITY) ); if (!regen) { /* Reset markers if needed. */ mission_sysMark(); /* Check land missions. */ if (!has_visited(VISITED_LAND)) { missions_run(MIS_AVAIL_LAND, land_planet->faction, land_planet->name, cur_system->name); visited(VISITED_LAND); } } /* Go to last open tab. */ window_tabWinOnChange( land_wid, "tabLand", land_changeTab ); if (changetab && land_windowsMap[ last_window ] != -1) window_tabWinSetActive( land_wid, "tabLand", land_windowsMap[ last_window ] ); /* Add fuel button if needed - AFTER missions pay :). */ land_checkAddRefuel(); /* Finished loading. */ land_loaded = 1; }
/** * @brief Updates the outfitter and equipment outfit image arrays. */ void outfits_updateEquipmentOutfits( void ) { int ew, ow; if (landed && land_doneLoading()) { if planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) { ow = land_getWid( LAND_WINDOW_OUTFITS ); outfits_update(ow, NULL); outfits_updateQuantities(ow); } else if (!planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) return; ew = land_getWid( LAND_WINDOW_EQUIPMENT ); equipment_addAmmo(); equipment_regenLists( ew, 1, 0 ); } } /** * @brief Checks to see if the player can buy the outfit. * @param outfit Outfit to buy. * @param q Quantity to buy. * @param errmsg Should alert the player? */ static int outfit_canBuy( Outfit* outfit, int q, int errmsg ) { char buf[ECON_CRED_STRLEN];
/** * @brief Recreates the land windows. * * @param load Is loading game? * @param changetab Should it change to the last open tab? */ void land_genWindows( int load, int changetab ) { int i, j; const char *names[LAND_NUMWINDOWS]; int w, h; Planet *p; int regen; /* Destroy old window if exists. */ if (land_wid > 0) { land_regen = 2; /* Mark we're regenning. */ window_destroy(land_wid); /* Mark tabs as not generated. */ land_generated = 0; } land_loaded = 0; /* Get planet. */ p = land_planet; regen = landed; /* Create window. */ if ((gl_screen.rw < 1024) || (gl_screen.rh < 768)) { w = -1; /* Fullscreen. */ h = -1; } else { w = 800 + 0.5 * (SCREEN_W - 800); h = 600 + 0.5 * (SCREEN_H - 600); } land_wid = window_create( p->name, -1, -1, w, h ); window_onClose( land_wid, land_cleanupWindow ); /* Set window map to invalid. */ for (i=0; i<LAND_NUMWINDOWS; i++) land_windowsMap[i] = -1; /* See what is available. */ j = 0; /* Main. */ land_windowsMap[LAND_WINDOW_MAIN] = j; names[j++] = _("Landing Main"); /* Bar. */ if (planet_hasService(land_planet, PLANET_SERVICE_BAR)) { land_windowsMap[LAND_WINDOW_BAR] = j; names[j++] = _("Spaceport Bar"); } /* Missions. */ if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS)) { land_windowsMap[LAND_WINDOW_MISSION] = j; names[j++] = _("Missions"); } /* Outfits. */ if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS)) { land_windowsMap[LAND_WINDOW_OUTFITS] = j; names[j++] = _("Outfits"); } /* Shipyard. */ if (planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) { land_windowsMap[LAND_WINDOW_SHIPYARD] = j; names[j++] = _("Shipyard"); } /* Equipment. */ if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) || planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) { land_windowsMap[LAND_WINDOW_EQUIPMENT] = j; names[j++] = _("Equipment"); } /* Commodity. */ if (planet_hasService(land_planet, PLANET_SERVICE_COMMODITY)) { land_windowsMap[LAND_WINDOW_COMMODITY] = j; names[j++] = _("Commodity"); } /* Create tabbed window. */ land_windows = window_addTabbedWindow( land_wid, -1, -1, -1, -1, "tabLand", j, names, 0 ); /* * Order here is very important: * * 1) Create main tab - must have decent background. * 2) Set landed, play music and run land hooks - so hooks run well. * 3) Generate missions - so that campaigns are fluid. * 4) Create other tabs - lists depend on NPC and missions. */ /* 1) Create main tab. */ land_createMainTab( land_getWid(LAND_WINDOW_MAIN) ); /* Add local system map button. */ land_checkAddMap(); /* 2) Set as landed and run hooks. */ if (!regen) { landed = 1; music_choose("land"); /* Must be before hooks in case hooks change music. */ if (!load) { hooks_run("land"); } events_trigger( EVENT_TRIGGER_LAND ); /* 3) Generate computer and bar missions. */ if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS)) mission_computer = missions_genList( &mission_ncomputer, land_planet->faction, land_planet->name, cur_system->name, MIS_AVAIL_COMPUTER ); if (planet_hasService(land_planet, PLANET_SERVICE_BAR)) npc_generate(); /* Generate bar npc. */ } /* 4) Create other tabs. */ #define should_open(s, w) \ (planet_hasService(land_planet, s) && (!land_tabGenerated(w))) /* Things get a bit hairy here. Hooks may have triggered a GUI reload via * e.g. player.swapShip, so the land tabs may have been generated already * and we need to check that before regenerating them. */ /* Basic - bar + missions */ if (should_open( PLANET_SERVICE_BAR, LAND_WINDOW_BAR )) bar_open( land_getWid(LAND_WINDOW_BAR) ); if (should_open( PLANET_SERVICE_MISSIONS, LAND_WINDOW_MISSION )) misn_open( land_getWid(LAND_WINDOW_MISSION) ); /* Outfits. */ if (should_open( PLANET_SERVICE_OUTFITS, LAND_WINDOW_OUTFITS )) outfits_open( land_getWid(LAND_WINDOW_OUTFITS) ); /* Shipyard. */ if (should_open( PLANET_SERVICE_SHIPYARD, LAND_WINDOW_SHIPYARD )) shipyard_open( land_getWid(LAND_WINDOW_SHIPYARD) ); /* Equipment. */ if ((planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) || planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) && !land_tabGenerated( LAND_WINDOW_EQUIPMENT )) equipment_open( land_getWid(LAND_WINDOW_EQUIPMENT) ); /* Commodity. */ if (should_open( PLANET_SERVICE_COMMODITY, LAND_WINDOW_COMMODITY )) commodity_exchange_open( land_getWid(LAND_WINDOW_COMMODITY) ); #undef should_open if (!regen) { /* Reset markers if needed. */ mission_sysMark(); /* Check land missions. */ if (!has_visited(VISITED_LAND)) { missions_run(MIS_AVAIL_LAND, land_planet->faction, land_planet->name, cur_system->name); visited(VISITED_LAND); } } /* Go to last open tab. */ window_tabWinOnChange( land_wid, "tabLand", land_changeTab ); if (changetab && land_windowsMap[ last_window ] != -1) window_tabWinSetActive( land_wid, "tabLand", land_windowsMap[ last_window ] ); /* Refresh the map button in case the player couldn't afford it prior to * mission payment. */ land_checkAddMap(); /* Refuel if necessary. */ land_refuel(); /* Finished loading. */ land_loaded = 1; }