18#include "land_shipyard.h"
29#include "player_fleet.h"
31#include "tk/toolkit_priv.h"
47static int shipyard_canAcquire(
const Ship *ship,
const Spob *spob, credits_t price );
48static void shipyard_buy(
unsigned int wid,
const char* str );
50static void shipyard_rmouse(
unsigned int wid,
const char* widget_name );
53static void shipyard_find(
unsigned int wid,
const char* str );
60 ImageArrayCell *cships;
64 int bw, bh, padding, off;
68 land_tabGenerate(LAND_WINDOW_SHIPYARD);
77 iw = 440 + (w - LAND_WIDTH);
85 padding = 40 + 20 * 4;
88 bw = (w - iw - padding) / 4;
89 bh = LAND_BUTTON_HEIGHT;
93 window_addButtonKey( wid, off, 20,
94 bw, bh,
"btnCloseShipyard",
97 window_addButtonKey( wid, off, 20,
98 bw, bh,
"btnTradeShip",
101 window_addButtonKey( wid, off, 20,
102 bw, bh,
"btnBuyShip",
105 window_addButtonKey( wid, off, 20,
106 bw, bh,
"btnFindShips",
110 window_addRect( wid, -40+4, -40+4, sw+8, sh+8,
"rctTarget", &cBlack, 1 );
111 window_addImage( wid, -40, -40, sw, sh,
"imgTarget", NULL, 0);
114 window_addCust( wid, -20, -sh-50, sw-10, 80,
"cstSlots", 0.,
119 window_addText( wid, -4, -sw-50-70-20, sw, -sh-60-70-20+h-bh, 0,
"txtStats",
123 window_addText( wid, iw+40, -35, 133, 427, 0,
"txtSDesc", &
gl_defFont, &cFontGrey, NULL );
124 window_addText( wid, iw+173, -35, w-sw-iw-208, 427, 0,
"txtDDesc", &
gl_defFont, NULL, NULL );
125 window_addText( wid, 20+iw+20, -462, w-(iw+40) - (sw+40), -482+h-bh, 0,
"txtDescription", &
gl_defFont, NULL, NULL );
130 cships = calloc(
MAX(1,nships),
sizeof(ImageArrayCell) );
132 cships[0].image = NULL;
133 cships[0].caption = strdup(_(
"None"));
137 for (
int i=0; i<nships; i++) {
143 cships[i].layers =
gl_addTexArray( cships[i].layers, &cships[i].nlayers, t );
150 if (toolkit_simImageArrayVisibleElements(iw,ih,iconsize,iconsize) < nships)
157 window_addImageArray( wid, 20, 20,
158 iw, ih,
"iarShipyard", iconsize, iconsize,
174 int i, tw, th, y, w, h, sw, iw, bh;
176 char lbl[STRMAX], buf[STRMAX], buf_price[ECON_CRED_STRLEN], buf_credits[ECON_CRED_STRLEN];
177 char buf_license[STRMAX_SHORT];
178 double aspect, gw, gh;
181 i = toolkit_getImageArrayPos( wid,
"iarShipyard" );
187 window_modifyImage( wid,
"imgTarget", NULL, 0, 0 );
188 window_disableButton( wid,
"btnBuyShip");
189 window_disableButton( wid,
"btnTradeShip");
190 window_modifyImage( wid,
"imgTarget", NULL, 0, 0 );
191 window_modifyText( wid,
"txtStats", NULL );
192 window_modifyText( wid,
"txtDescription", NULL );
193 window_modifyText( wid,
"txtSDesc", NULL );
194 window_modifyText( wid,
"txtDDesc", NULL );
213 window_addImage( wid, -40-(SHIP_GFX_W-gw)/2, -30-(SHIP_GFX_H-gh)/2, gw, gh,
"imgTarget", NULL, 0 );
214 window_modifyImage( wid,
"imgTarget",
shipyard_comm, gw, gh );
217 window_modifyText( wid,
"txtStats", ship->
desc_stats );
222 strncpy( buf_license, _(
"None"),
sizeof(buf_license)-1 );
225 strncpy( buf_license, _(ship->
license),
sizeof(buf_license)-1 );
227 snprintf( buf_license,
sizeof(buf_license),
"#r%s#0", _(ship->
license) );
229 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"%s", _(
"Model:") );
230 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s", _(ship->
name) );
231 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Class:") );
233 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Fabricator:") );
235 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Crew:") );
236 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%d", ship->
crew );
238 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Fleet Capacity:") );
242 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n\n%s", _(
"Base Properties") );
243 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n\n%s",
"");
245 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"CPU:") );
246 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%.0f %s", ship->
cpu, n_(
"teraflop",
"teraflops", ship->
cpu ) );
249 char buf_mass[ECON_MASS_STRLEN];
250 tonnes2str( buf_mass, ship->
mass );
251 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Mass:") );
252 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", buf_mass );
255 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Thrust:") );
256 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"");
257 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%.0f kN/tonne"), ship->
thrust );
260 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Speed:") );
261 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
262 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%.0f m/s"), ship->
speed );
265 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Turn:") );
266 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
267 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%.0f deg/s"), ship->
turn*180/M_PI );
270 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Time Constant:") );
275 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Absorption:") );
276 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
280 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Shield:") );
281 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
285 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Armour:") );
286 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
290 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Energy:") );
291 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
295 char buf_cargo[ECON_MASS_STRLEN];
296 tonnes2str( buf_cargo, ship->
cap_cargo );
297 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Cargo Space:") );
298 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", buf_cargo );
301 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Fuel:") );
302 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%d %s", ship->
fuel, n_(
"unit",
"units", ship->
fuel ) );
305 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Fuel Use:") );
309 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n\n%s", _(
"Price:") );
310 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n\n%s", buf_price );
311 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Money:") );
312 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", buf_credits );
313 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"License:") );
314 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", buf_license );
316 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Requires:") );
325 iw = 440 + (w - LAND_WIDTH);
327 bh = LAND_BUTTON_HEIGHT;
331 window_modifyText( wid,
"txtSDesc", lbl );
334 window_modifyText( wid,
"txtDDesc", buf );
337 y =
MIN( y-th, -40-SHIP_GFX_H-20 );
338 window_modifyText( wid,
"txtDescription", _(ship->
description) );
343 window_disableButtonSoft( wid,
"btnBuyShip");
345 window_enableButton( wid,
"btnBuyShip");
348 window_disableButtonSoft( wid,
"btnTradeShip");
350 window_enableButton( wid,
"btnTradeShip");
373 map_inputFindType(wid,
"ship");
395 char buf[STRMAX_SHORT];
399 i = toolkit_getImageArrayPos( wid,
"iarShipyard" );
410 credits2str( buf, targetprice, 2 );
412 _(
"Do you really want to spend %s on a new ship?"), buf )==0)
427 hparam[0].
type = HOOK_PARAM_STRING;
429 hparam[1].
type = HOOK_PARAM_SENTINEL;
431 land_needsTakeoff( 1 );
434static int shipyard_canAcquire(
const Ship *ship,
const Spob *spob, credits_t price )
437 int blackmarket = ((spob != NULL) && spob_hasService(spob, SPOB_SERVICE_BLACKMARKET));
453 char buf[ECON_CRED_STRLEN];
470 return shipyard_canAcquire( ship, spob, price );
502 "You have %d tonne more cargo than the new ship can hold.",
503 "You have %d tonnes more cargo than the new ship can hold.",
524 return shipyard_canAcquire( ship, spob, price );
536 char buf[STRMAX_SHORT], buf2[ECON_CRED_STRLEN],
537 buf3[ECON_CRED_STRLEN], buf4[ECON_CRED_STRLEN];
540 i = toolkit_getImageArrayPos( wid,
"iarShipyard" );
552 credits2str( buf, targetprice, 2 );
553 credits2str( buf2, playerprice, 2 );
554 credits2str( buf3, targetprice - playerprice, 2 );
555 credits2str( buf4, playerprice - targetprice, 2 );
558 if ( targetprice == playerprice ) {
560 _(
"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?"),
564 else if ( targetprice < playerprice ) {
566 _(
"Your %s is worth %s, more than the new ship. For your ship, you will get the new %s and %s. Are you sure you want to trade your ship in?"),
570 else if ( targetprice > playerprice ) {
572 _(
"Your %s is worth %s, so the new ship will cost %s. Are you sure you want to trade your ship in?"),
655 else if (s[i].exclusive)
657 else if (s[i].slot.spid != 0)
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
int cond_check(const char *cond)
Checks to see if a condition is true.
int dialogue_YesNo(const char *caption, const char *fmt,...)
Runs a dialogue with both yes and no options.
int gl_printHeightRaw(const glFont *ft_font, const int width, const char *text)
Gets the height of a non-formatted string.
int gl_printWidthRaw(const glFont *ft_font, const char *text)
Gets the width that it would take to print some text.
int gl_printMidRaw(const glFont *ft_font, int width, double x, double y, const glColour *c, double outlineR, const char *text)
Displays text centered in position and width.
void gl_print(const glFont *ft_font, const double x, const double y, const glColour *c, const char *fmt,...)
Prints text on screen like printf.
int hooks_runParam(const char *stack, const HookParam *param)
Runs all the hooks of stack.
unsigned int land_getWid(int window)
Gets the WID of a window by type.
void land_errDialogueBuild(const char *fmt,...)
Generates error dialogues used by several landing tabs.
int land_errDialogue(const char *name, const char *type)
Generates error dialogues used by several landing tabs.
void land_buttonTakeoff(unsigned int wid, const char *unused)
Wrapper for takeoff mission button.
void land_refuel(void)
Refuels the player's current ship, if possible.
static void shipyard_renderSlotsRow(double bx, double by, double bw, const char *str, ShipOutfitSlot *s)
Renders a row of ship slots.
void shipyard_open(unsigned int wid)
Opens the shipyard window.
int can_sell(const char *shipname)
Makes sure it's valid to sell a ship.
int shipyard_canBuy(const char *shipname, const Spob *spob)
Makes sure it's valid to buy a ship.
static void shipyard_find(unsigned int wid, const char *str)
Starts the map find with ship search selected.
int can_swap(const char *shipname)
Makes sure it's valid to change ships.
static glTexture * shipyard_comm
static void shipyard_rmouse(unsigned int wid, const char *widget_name)
Player right-clicks on a ship.
void shipyard_cleanup(void)
Cleans up shipyard data.
static Ship ** shipyard_list
int shipyard_canTrade(const char *shipname, const Spob *spob)
Makes sure it's valid to buy a ship, trading the old one in simultaneously.
static void shipyard_renderSlots(double bx, double by, double bw, double bh, void *data)
Custom widget render function for the slot widget.
static void shipyard_buy(unsigned int wid, const char *str)
Player attempts to buy a ship.
void shipyard_update(unsigned int wid, const char *str)
Updates the ships in the shipyard window.
static void shipyard_trade(unsigned int wid, const char *str)
Player attempts to buy a ship, trading the current ship in.
static Ship * shipyard_selected
Header file with generic functions and naev-specifics.
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
void gl_renderRectEmpty(double x, double y, double w, double h, const glColour *c)
Renders a rectangle.
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
glTexture ** gl_copyTexArray(glTexture **tex, int *n)
Copy a texture array.
glTexture ** gl_addTexArray(glTexture **tex, int *n, glTexture *t)
Adds an element to a texture array.
void gl_freeTexture(glTexture *texture)
Frees a texture.
glTexture * rarity_texture(int rarity)
const glColour * outfit_slotSizeColour(const OutfitSlot *os)
Gets the slot size colour for an outfit slot.
int pilot_cargoFree(const Pilot *p)
Gets the pilot's free cargo space.
int pilot_cargoUsedMission(const Pilot *p)
Gets how much mission cargo ship has on board.
int pilot_cargoUsed(const Pilot *p)
Gets how much cargo ship has on board.
int pilot_hasDeployed(Pilot *p)
Checks to see if the pilot has deployed ships.
int player_hasLicense(const char *license)
Checks to see if player has license.
credits_t player_shipPrice(const char *shipname)
Calculates the price of one of the player's ships.
PlayerShip_t * player_newShip(const Ship *ship, const char *def_name, int trade, const char *acquired, int noname)
Creates a new ship for player.
credits_t player_modCredits(credits_t amount)
Modifies the amount of credits the player has.
int player_hasCredits(credits_t amount)
Checks to see if the player has enough credits.
int pfleet_cargoFree(void)
Gets the total amount of free cargo space in the player's fleet.
const char * ship_classDisplay(const Ship *s)
Gets the ship's display class in human readable form.
credits_t ship_buyPrice(const Ship *s)
The ship buy price, includes default outfits.
glTexture * ship_loadCommGFX(const Ship *s)
Loads the ship's comm graphic.
const Ship * ship_get(const char *name)
Gets a ship based on its name.
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
The actual hook parameter.
ShipOutfitSlot * outfit_utility
ShipOutfitSlot * outfit_weapon
ShipOutfitSlot * outfit_structure
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Abstraction for rendering sprite sheets.
Ship ** tech_getShip(const tech_group_t *tech)
Gets all of the ships associated to a tech group.