18#include "land_shipyard.h"
29#include "player_fleet.h"
32#include "tk/toolkit_priv.h"
41typedef struct CstShipSlotWidget_ {
58static int shipyard_canAcquire(
const Ship *ship,
const Spob *spob, credits_t price );
59static void shipyard_buy(
unsigned int wid,
const char* str );
61static void shipyard_rmouse(
unsigned int wid,
const char* widget_name );
64static int shipyard_mouseSlots(
unsigned int wid,
const SDL_Event* event,
65 double x,
double y,
double w,
double h,
double rx,
double ry,
void *data );
66static void shipyard_renderSlotsOver(
double bx,
double by,
double bw,
double bh,
void *data );
67static void shipyard_find(
unsigned int wid,
const char* str );
74 ImageArrayCell *cships;
78 int bw, bh, padding, off;
83 land_tabGenerate(LAND_WINDOW_SHIPYARD);
92 iw = 440 + (w - LAND_WIDTH);
100 padding = 40 + 20 * 4;
103 bw = (w - iw - padding) / 4;
104 bh = LAND_BUTTON_HEIGHT;
108 window_addButtonKey( wid, off, 20,
109 bw, bh,
"btnCloseShipyard",
112 window_addButtonKey( wid, off, 20,
113 bw, bh,
"btnTradeShip",
116 window_addButtonKey( wid, off, 20,
117 bw, bh,
"btnBuyShip",
120 window_addButtonKey( wid, off, 20,
121 bw, bh,
"btnFindShips",
125 window_addRect( wid, -40+4, -40+4, sw+8, sh+8,
"rctTarget", &cBlack, 1 );
126 window_addImage( wid, -40, -40, sw, sh,
"imgTarget", NULL, 0);
130 window_addCust( wid, -20, -sh-50, sw-10, 80,
"cstSlots", 0.,
132 window_custSetOverlay( wid,
"cstSlots", shipyard_renderSlotsOver );
133 window_custSetClipping( wid,
"cstSlots", 0 );
135 window_custAutoFreeData( wid,
"cstSlots" );
138 window_addText( wid, -4, -sw-50-70-20, sw, -sh-60-70-20+h-bh, 0,
"txtStats",
142 window_addText( wid, iw+40, -35, 133, 427, 0,
"txtSDesc", &
gl_defFont, &cFontGrey, NULL );
143 window_addText( wid, iw+173, -35, w-sw-iw-208, 427, 0,
"txtDDesc", &
gl_defFont, NULL, NULL );
144 window_addText( wid, 20+iw+20, -462, w-(iw+40) - (sw+40), -482+h-bh, 0,
"txtDescription", &
gl_defFont, NULL, NULL );
149 cships = calloc(
MAX(1,nships),
sizeof(ImageArrayCell) );
151 cships[0].image = NULL;
152 cships[0].caption = strdup(_(
"None"));
156 for (
int i=0; i<nships; i++) {
169 if (toolkit_simImageArrayVisibleElements(iw,ih,iconsize,iconsize) < nships)
176 window_addImageArray( wid, 20, 20,
177 iw, ih,
"iarShipyard", iconsize, iconsize,
193 int i, tw, th, y, w, h, sw, iw, bh;
195 char lbl[STRMAX], buf[STRMAX], buf_price[ECON_CRED_STRLEN], buf_credits[ECON_CRED_STRLEN];
196 double aspect, gw, gh;
198 int blackmarket = ((
land_spob!=NULL) && spob_hasService(
land_spob, SPOB_SERVICE_BLACKMARKET ));
200 i = toolkit_getImageArrayPos( wid,
"iarShipyard" );
206 window_modifyImage( wid,
"imgTarget", NULL, 0, 0 );
207 window_disableButton( wid,
"btnBuyShip");
208 window_disableButton( wid,
"btnTradeShip");
209 window_modifyImage( wid,
"imgTarget", NULL, 0, 0 );
210 window_modifyText( wid,
"txtStats", NULL );
211 window_modifyText( wid,
"txtDescription", NULL );
212 window_modifyText( wid,
"txtSDesc", NULL );
213 window_modifyText( wid,
"txtDDesc", NULL );
232 window_addImage( wid, -40-(SHIP_GFX_W-gw)/2, -30-(SHIP_GFX_H-gh)/2, gw, gh,
"imgTarget", NULL, 0 );
233 window_modifyImage( wid,
"imgTarget",
shipyard_comm, gw, gh );
236 window_modifyText( wid,
"txtStats", ship->
desc_stats );
240 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"%s", _(
"Model:") );
241 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s", _(ship->
name) );
242 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Class:") );
244 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Fabricator:") );
246 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Crew:") );
247 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%d", ship->
crew );
249 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Fleet Capacity:") );
253 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n\n%s", _(
"Base Properties") );
254 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n\n%s",
"");
256 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"CPU:") );
257 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%.0f %s", ship->
cpu, UNIT_CPU );
260 char buf_mass[ECON_MASS_STRLEN];
262 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Mass:") );
263 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", buf_mass );
266 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Accel:") );
267 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n");
268 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%.0f %s"), ship->
accel, UNIT_ACCEL );
271 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Speed:") );
272 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
273 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%.0f %s"), ship->
speed, UNIT_SPEED );
276 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Turn:") );
277 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
278 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%.0f %s"), ship->
turn*180/M_PI, UNIT_ROTATION );
281 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Time Constant:") );
286 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Absorption:") );
287 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
291 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Shield:") );
292 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
296 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Armour:") );
297 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
301 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Energy:") );
302 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
306 char buf_cargo[ECON_MASS_STRLEN];
308 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Cargo Space:") );
309 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", buf_cargo );
312 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Fuel:") );
313 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%d %s", ship->
fuel, UNIT_UNIT );
316 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Fuel Use:") );
320 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n\n%s", _(
"Price:") );
321 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n\n%s", buf_price );
322 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Money:") );
323 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", buf_credits );
326 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"License:") );
328 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s#0", _(
"Not Necessary (Blackmarket)") );
330 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s%s#0", meets_reqs ?
"" :
"#r", _(ship->
license) );
336 k +=
scnprintf( &lbl[k],
sizeof(lbl)-k,
"\n%s", _(
"Requires:") );
338 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s#0", _(
"Not Necessary (Blackmarket)") );
340 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s%s#0", meets_reqs ?
"" :
"#r", _(ship->
condstr) );
345 iw = 440 + (w - LAND_WIDTH);
347 bh = LAND_BUTTON_HEIGHT;
351 window_modifyText( wid,
"txtSDesc", lbl );
354 window_modifyText( wid,
"txtDDesc", buf );
357 y =
MIN( y-th, -40-SHIP_GFX_H-20 );
360 window_modifyText( wid,
"txtDescription", buf );
363 window_modifyText( wid,
"txtDescription", _(ship->
description) );
368 window_disableButtonSoft( wid,
"btnBuyShip");
370 window_enableButton( wid,
"btnBuyShip");
373 window_disableButtonSoft( wid,
"btnTradeShip");
375 window_enableButton( wid,
"btnTradeShip");
398 map_inputFindType(wid,
"ship");
420 char buf[STRMAX_SHORT];
424 i = toolkit_getImageArrayPos( wid,
"iarShipyard" );
439 _(
"Do you really want to spend %s on a new ship?"), buf )==0)
454 hparam[0].
type = HOOK_PARAM_SHIP;
455 hparam[0].
u.
ship = ship;
456 hparam[1].
type = HOOK_PARAM_SENTINEL;
458 land_needsTakeoff( 1 );
461static int shipyard_canAcquire(
const Ship *ship,
const Spob *spob, credits_t price )
464 int blackmarket = ((spob != NULL) && spob_hasService(spob, SPOB_SERVICE_BLACKMARKET));
481 char buf[ECON_CRED_STRLEN];
497 return shipyard_canAcquire( ship, spob, price );
514 return shipyard_canAcquire( ship, spob, price );
526 char buf[STRMAX_SHORT], buf2[ECON_CRED_STRLEN],
527 buf3[ECON_CRED_STRLEN], buf4[ECON_CRED_STRLEN];
530 i = toolkit_getImageArrayPos( wid,
"iarShipyard" );
550 if ( targetprice == playerprice ) {
552 _(
"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?"),
556 else if ( targetprice < playerprice ) {
558 _(
"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?"),
562 else if ( targetprice > playerprice ) {
564 _(
"Your %s is worth %s, so the new ship will cost %s. Are you sure you want to trade your ship in?"),
654 else if (s[i].exclusive)
656 else if (s[i].slot.spid != 0)
662 icon =
sp_icon( s[i].slot.spid );
668 if (icon->
flags & OPENGL_TEX_SDF)
676static int shipyard_mouseSlots(
unsigned int wid,
const SDL_Event *event,
677 double mx,
double my,
double bw,
double bh,
678 double rx,
double ry,
void *data )
684 int x = floor((mx-30.-21.) / 21.);
685 int y = floor((bh-my-15.) / 20.);
695 if (event->type != SDL_MOUSEMOTION)
722 wgt->alty = 30. + (2-y)*20.;
723 wgt->altx = 15. + (x+2)*21.;
727static void shipyard_renderSlotsOver(
double bx,
double by,
double bw,
double bh,
void *data )
731 char alt[STRMAX_SHORT];
736 if (wgt->mouseover <= 0)
747 pos +=
scnprintf( &alt[pos],
sizeof(alt)-pos, _(
"#%c%s #%c%s #0slot" ),
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.
void credits2str(char *str, credits_t credits, int decimals)
Converts credits to a usable string for displaying.
void tonnes2str(char *str, int tonnes)
Converts tonnes to a usable string for displaying.
void price2str(char *str, credits_t price, credits_t credits, int decimals)
Given a price and on-hand credits, outputs a colourized string.
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.
void land_errClear(void)
Clear error dialogues.
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.
int land_errDisplay(void)
Displays an error if applicable.
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.
static void shipyard_find(unsigned int wid, const char *str)
Starts the map find with ship search selected.
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.
int shipyard_canBuy(const Ship *ship, const Spob *spob)
Makes sure it's valid to buy a ship.
static Ship ** shipyard_list
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.
int shipyard_canTrade(const Ship *ship, const Spob *spob)
Makes sure it's valid to buy a ship, trading the old one in simultaneously.
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_renderSDF(const glTexture *texture, double x, double y, double w, double h, const glColour *c, double angle, double outline)
SDF Texture blitting backend.
void gl_renderScaleAspect(const glTexture *texture, double bx, double by, double bw, double bh, const glColour *c)
Blits a texture scaling it to fit a rectangle, but conserves aspect ratio.
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_addTexArray(glTexture **tex, glTexture *t)
Adds an element to a texture array.
glTexture ** gl_copyTexArray(glTexture **tex)
Copy a texture array.
void gl_freeTexture(glTexture *texture)
Frees a texture.
char outfit_slotTypeColourFont(const OutfitSlot *os)
Gets a font colour character that roughly matches an outfit slot type colour.
char outfit_slotSizeColourFont(const OutfitSlot *os)
Gets a font colour character that roughly matches an outfit slot size colour.
const char * slotName(const OutfitSlotType type)
const char * slotSize(const OutfitSlotSize o)
Gets the slot size as a string.
glTexture * rarity_texture(int rarity)
const glColour * outfit_slotSizeColour(const OutfitSlot *os)
Gets the slot size colour for an outfit slot.
int pilot_cargoUsedMission(const Pilot *p)
Gets how much mission cargo ship has on board.
int player_hasLicense(const char *license)
Checks to see if player has license.
credits_t player_shipPrice(const char *shipname, int count_unique)
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.
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 glTexture * sp_icon(unsigned int spid)
Gets the icon associated with the slot.
const char * sp_display(unsigned int spid)
Gets the display name of a slot property (in English).
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.