naev 0.11.5
equipment.c File Reference

Handles equipping ships. More...

#include "equipment.h"
#include "array.h"
#include "conf.h"
#include "debug.h"
#include "dialogue.h"
#include "escort.h"
#include "gui.h"
#include "hook.h"
#include "info.h"
#include "land.h"
#include "land_outfits.h"
#include "log.h"
#include "map.h"
#include "mission.h"
#include "ndata.h"
#include "nstring.h"
#include "nlua.h"
#include "nlua_tk.h"
#include "ntime.h"
#include "player.h"
#include "player_fleet.h"
#include "pilot_outfit.h"
#include "shipstats.h"
#include "slots.h"
#include "tk/toolkit_priv.h"
#include "toolkit.h"

Go to the source code of this file.

Macros

#define EQUIPMENT_SHIPS   "iarAvailShips"
 
#define EQUIPMENT_OUTFIT_TAB   "tabOutfits"
 
#define EQUIPMENT_OUTFITS   "iarAvailOutfits"
 
#define EQUIPMENT_FILTER   "inpFilterOutfits"
 
#define OUTFIT_TABS   5
 
#define BUTTON_WIDTH   200
 
#define BUTTON_HEIGHT   40
 
#define EQ_COMP(cur, base, inv)
 
#define EQ_COMP_I(cur, base, inv)
 

Functions

static void equipment_getDim (unsigned int wid, int *w, int *h, int *sw, int *sh, int *ow, int *oh, int *ew, int *eh, int *cw, int *ch, int *bw, int *bh)
 Gets the window dimensions.
 
static void equipment_genShipList (unsigned int wid)
 Generates the ship list.
 
static void equipment_genOutfitList (unsigned int wid)
 Generates the outfit list.
 
static void equipment_genLists (unsigned int wid)
 Generates a new ship/outfit lists if needed.
 
static void equipment_toggleFav (unsigned int wid, const char *wgt)
 Handles toggling of the favourite checkbox.
 
static void equipment_toggleDeploy (unsigned int wid, const char *wgt)
 
static void equipment_renderColumn (double x, double y, double w, double h, const PilotOutfitSlot *lst, const char *txt, int selected, Outfit *o, Pilot *p, const CstSlotWidget *wgt)
 Renders an outfit column.
 
static void equipment_renderSlots (double bx, double by, double bw, double bh, void *data)
 Renders the equipment slots.
 
static void equipment_renderMisc (double bx, double by, double bw, double bh, void *data)
 Renders the custom equipment widget.
 
static void equipment_renderOverlayColumn (double x, double y, double h, PilotOutfitSlot *lst, int mover, CstSlotWidget *wgt)
 Renders an outfit column.
 
static void equipment_renderOverlaySlots (double bx, double by, double bw, double bh, void *data)
 Renders the equipment overlay.
 
static void equipment_renderShip (double bx, double by, double bw, double bh, void *data)
 Renders the ship in the equipment window.
 
static int equipment_mouseInColumn (const PilotOutfitSlot *lst, double y, double h, double my)
 Handles a mouse press in column.
 
static int equipment_mouseSlots (unsigned int wid, const SDL_Event *event, double mx, double my, double bw, double bh, double rx, double ry, void *data)
 Does mouse input for the custom equipment widget.
 
static char eq_qCol (double cur, double base, int inv)
 Gets the colour for comparing a current value vs a ship base value.
 
static int equipment_swapSlot (unsigned int wid, Pilot *p, PilotOutfitSlot *slot)
 Swaps an equipment slot.
 
static void equipment_sellShip (unsigned int wid, const char *str)
 Player tries to sell a ship.
 
static void equipment_renameShip (unsigned int wid, const char *str)
 Renames the selected ship.
 
static void equipment_shipMode (unsigned int wid, const char *str)
 Toggles the ship visualization mode.
 
static void equipment_rightClickShips (unsigned int wid, const char *str)
 Toggles deployed status.
 
static void equipment_transChangeShip (unsigned int wid, const char *str)
 Changes ship.
 
static void equipment_changeShip (unsigned int wid)
 Player attempts to change ship.
 
static void equipment_unequipShip (unsigned int wid, const char *str)
 Unequips the player's ship.
 
static void equipment_autoequipShip (unsigned int wid, const char *str)
 Does the autoequip magic on the player's ship.
 
static void equipment_filterOutfits (unsigned int wid, const char *str)
 Handles text input in the filter input widget.
 
static void equipment_rightClickOutfits (unsigned int wid, const char *str)
 Handles right-click on unequipped outfit.
 
static void equipment_outfitPopdown (unsigned int wid, const char *str)
 
static void equipment_changeTab (unsigned int wid, const char *wgt, int old, int tab)
 Ensures the tab's selected item is reflected in the ship slot list.
 
static int equipment_playerAddOutfit (const Outfit *o, int quantity)
 Wrapper to only add unique outfits.
 
static int equipment_playerRmOutfit (const Outfit *o, int quantity)
 Wrapper to only remove unique outfits.
 
void equipment_open (unsigned int wid)
 Opens the player's equipment window.
 
void equipment_slotWidget (unsigned int wid, double x, double y, double w, double h, CstSlotWidget *data)
 Creates the slot widget and initializes it.
 
static void equipment_calculateSlots (const Pilot *p, double bw, double bh, double *w, double *h, int *n, int *m)
 Calculates the size the slots need to be for a given window.
 
static int equipment_mouseColumn (unsigned int wid, const SDL_Event *event, double mx, double my, double y, double h, PilotOutfitSlot *os, Pilot *p, int selected, CstSlotWidget *wgt)
 Handles a mouse press in a column.
 
void equipment_regenLists (unsigned int wid, int outfits, int ships)
 Regenerates the equipment window lists.
 
int equipment_canSellPlayerShip (const char *shipname)
 Makes sure it's valid to sell a ship.
 
int equipment_canSwapPlayerShip (const char *shipname)
 Makes sure it's valid to change ships in the equipment view.
 
void equipment_addAmmo (void)
 Adds all the ammo it can to the player.
 
int equipment_shipStats (char *buf, int max_len, const Pilot *s, int dpseps, int name)
 Creates and allocates a string containing the ship stats.
 
static int equipment_filter (const Outfit *o)
 
static int equipment_filterWeapon (const Outfit *o)
 
static int equipment_filterUtility (const Outfit *o)
 
static int equipment_filterStructure (const Outfit *o)
 
static int equipment_filterCore (const Outfit *o)
 
static const char * eq_qSym (double cur, double base, int inv)
 Gets the symbol for comparing a current value vs a ship base value.
 
void equipment_updateShips (unsigned int wid, const char *str)
 Updates the player's ship window.
 
void equipment_updateOutfits (unsigned int wid, const char *str)
 Updates the player's outfit list.
 
static void equipment_outfitPopdownSelect (unsigned int wid, const char *str)
 
static void equipment_outfitPopdownActivate (unsigned int wid, const char *str)
 
void equipment_cleanup (void)
 Cleans up after the equipment stuff.
 
void equipment_slotDeselect (CstSlotWidget *wgt)
 Deselects equipment stuff.
 

Variables

static CstSlotWidget eq_wgt
 
static double equipment_dir = 0.
 
static unsigned int equipment_lastick = 0
 
static unsigned int equipment_wid = 0
 
static int equipment_creating = 0
 
static int ship_mode = 0
 
static iar_data_t iar_data [OUTFIT_TABS]
 
static Outfit ** iar_outfits [OUTFIT_TABS]
 
static nlua_env autoequip_env = LUA_NOREF
 
static int equipment_outfitMode = 0
 

Detailed Description

Handles equipping ships.

Definition in file equipment.c.

Macro Definition Documentation

◆ BUTTON_HEIGHT

#define BUTTON_HEIGHT   40

Default button height.

Definition at line 56 of file equipment.c.

◆ BUTTON_WIDTH

#define BUTTON_WIDTH   200

Default button width.

Definition at line 55 of file equipment.c.

◆ EQ_COMP

#define EQ_COMP ( cur,
base,
inv )
Value:
eq_qCol( cur, base, inv ), eq_qSym( cur, base, inv ), cur
static const char * eq_qSym(double cur, double base, int inv)
Gets the symbol for comparing a current value vs a ship base value.
Definition equipment.c:1783
static char eq_qCol(double cur, double base, int inv)
Gets the colour for comparing a current value vs a ship base value.
Definition equipment.c:1771

Definition at line 1792 of file equipment.c.

◆ EQ_COMP_I

#define EQ_COMP_I ( cur,
base,
inv )
Value:
eq_qCol( cur, base, inv ), eq_qSym( cur, base, inv )

Definition at line 1794 of file equipment.c.

◆ EQUIPMENT_FILTER

#define EQUIPMENT_FILTER   "inpFilterOutfits"

Definition at line 51 of file equipment.c.

◆ EQUIPMENT_OUTFIT_TAB

#define EQUIPMENT_OUTFIT_TAB   "tabOutfits"

Definition at line 49 of file equipment.c.

◆ EQUIPMENT_OUTFITS

#define EQUIPMENT_OUTFITS   "iarAvailOutfits"

Definition at line 50 of file equipment.c.

◆ EQUIPMENT_SHIPS

#define EQUIPMENT_SHIPS   "iarAvailShips"

Definition at line 48 of file equipment.c.

◆ OUTFIT_TABS

#define OUTFIT_TABS   5

Definition at line 52 of file equipment.c.

Function Documentation

◆ eq_qCol()

static char eq_qCol ( double cur,
double base,
int inv )
static

Gets the colour for comparing a current value vs a ship base value.

Definition at line 1771 of file equipment.c.

◆ eq_qSym()

static const char * eq_qSym ( double cur,
double base,
int inv )
static

Gets the symbol for comparing a current value vs a ship base value.

Definition at line 1783 of file equipment.c.

◆ equipment_addAmmo()

void equipment_addAmmo ( void )

Adds all the ammo it can to the player.

Definition at line 1400 of file equipment.c.

◆ equipment_autoequipShip()

static void equipment_autoequipShip ( unsigned int wid,
const char * str )
static

Does the autoequip magic on the player's ship.

Definition at line 2333 of file equipment.c.

◆ equipment_calculateSlots()

static void equipment_calculateSlots ( const Pilot * p,
double bw,
double bh,
double * w,
double * h,
int * n,
int * m )
static

Calculates the size the slots need to be for a given window.

Parameters
pPilot to calculate the slots of.
bwBase widget width.
bhBase window height.
wWidth to use.
hHeight to use.
nNumber of columns.
mNumber of rows.

Definition at line 565 of file equipment.c.

◆ equipment_canSellPlayerShip()

int equipment_canSellPlayerShip ( const char * shipname)

Makes sure it's valid to sell a ship.

Parameters
shipnameShip being sold.

Definition at line 1332 of file equipment.c.

◆ equipment_canSwapPlayerShip()

int equipment_canSwapPlayerShip ( const char * shipname)

Makes sure it's valid to change ships in the equipment view.

Parameters
shipnameShip being changed to.

Definition at line 1348 of file equipment.c.

◆ equipment_changeShip()

static void equipment_changeShip ( unsigned int wid)
static

Player attempts to change ship.

Parameters
widWindow player is attempting to change ships in.

Definition at line 2205 of file equipment.c.

◆ equipment_changeTab()

static void equipment_changeTab ( unsigned int wid,
const char * wgt,
int old,
int tab )
static

Ensures the tab's selected item is reflected in the ship slot list.

Parameters
widUnused.
wgtUnused.
oldTab changed from.
tabTab changed to.

Definition at line 2127 of file equipment.c.

◆ equipment_cleanup()

void equipment_cleanup ( void )

Cleans up after the equipment stuff.

Definition at line 2529 of file equipment.c.

◆ equipment_filter()

static int equipment_filter ( const Outfit * o)
static

Definition at line 1601 of file equipment.c.

◆ equipment_filterCore()

static int equipment_filterCore ( const Outfit * o)
static

Definition at line 1655 of file equipment.c.

◆ equipment_filterOutfits()

static void equipment_filterOutfits ( unsigned int wid,
const char * str )
static

Handles text input in the filter input widget.

Parameters
widWindow containing the widget.
strUnused.

Definition at line 2062 of file equipment.c.

◆ equipment_filterStructure()

static int equipment_filterStructure ( const Outfit * o)
static

Definition at line 1652 of file equipment.c.

◆ equipment_filterUtility()

static int equipment_filterUtility ( const Outfit * o)
static

Definition at line 1649 of file equipment.c.

◆ equipment_filterWeapon()

static int equipment_filterWeapon ( const Outfit * o)
static

Definition at line 1646 of file equipment.c.

◆ equipment_genLists()

static void equipment_genLists ( unsigned int wid)
static

Generates a new ship/outfit lists if needed.

Parameters
widParent window id.

Definition at line 1501 of file equipment.c.

◆ equipment_genOutfitList()

static void equipment_genOutfitList ( unsigned int wid)
static

Generates the outfit list.

Parameters
widWindow to generate list on.

Definition at line 1663 of file equipment.c.

◆ equipment_genShipList()

static void equipment_genShipList ( unsigned int wid)
static

Generates the ship list.

Parameters
widWindow to generate list on.

Definition at line 1511 of file equipment.c.

◆ equipment_getDim()

static void equipment_getDim ( unsigned int wid,
int * w,
int * h,
int * sw,
int * sh,
int * ow,
int * oh,
int * ew,
int * eh,
int * cw,
int * ch,
int * bw,
int * bh )
static

Gets the window dimensions.

Definition at line 256 of file equipment.c.

◆ equipment_mouseColumn()

static int equipment_mouseColumn ( unsigned int wid,
const SDL_Event * event,
double mx,
double my,
double y,
double h,
PilotOutfitSlot * os,
Pilot * p,
int selected,
CstSlotWidget * wgt )
static

Handles a mouse press in a column.

Parameters
widParent window id.
eventMouse input event.
mxMouse X event position.
myMouse Y event position.
yY position of the column.
hHeight of the column.
osArray (array.h) of elements in the column.
pPilot to which the elements belong.
selectedCurrently selected element.
wgtSlot widget.

Definition at line 1033 of file equipment.c.

◆ equipment_mouseInColumn()

static int equipment_mouseInColumn ( const PilotOutfitSlot * lst,
double y,
double h,
double my )
static

Handles a mouse press in column.

Parameters
lstList of items in the column.
yY position of the column.
hHeight of column.
myMouse press position.
Returns
Number pressed (or -1 if none).

Definition at line 1004 of file equipment.c.

◆ equipment_mouseSlots()

static int equipment_mouseSlots ( unsigned int wid,
const SDL_Event * event,
double mx,
double my,
double bw,
double bh,
double rx,
double ry,
void * data )
static

Does mouse input for the custom equipment widget.

Parameters
widParent window id.
eventMouse input event.
mxMouse X event position.
myMouse Y event position.
bwBase window width.
bhBase window height.
rxRelative X movement (only valid for motion).
ryRelative Y movement (only valid for motion).
dataCustom widget data.

Definition at line 1101 of file equipment.c.

◆ equipment_open()

void equipment_open ( unsigned int wid)

Opens the player's equipment window.

Definition at line 299 of file equipment.c.

◆ equipment_outfitPopdown()

static void equipment_outfitPopdown ( unsigned int wid,
const char * str )
static

Definition at line 2089 of file equipment.c.

◆ equipment_outfitPopdownActivate()

static void equipment_outfitPopdownActivate ( unsigned int wid,
const char * str )
static

Definition at line 2083 of file equipment.c.

◆ equipment_outfitPopdownSelect()

static void equipment_outfitPopdownSelect ( unsigned int wid,
const char * str )
static

Functions for the popdown menu (filter outfits by size)

Definition at line 2072 of file equipment.c.

◆ equipment_playerAddOutfit()

static int equipment_playerAddOutfit ( const Outfit * o,
int quantity )
static

Wrapper to only add unique outfits.

Definition at line 2509 of file equipment.c.

◆ equipment_playerRmOutfit()

static int equipment_playerRmOutfit ( const Outfit * o,
int quantity )
static

Wrapper to only remove unique outfits.

Definition at line 2519 of file equipment.c.

◆ equipment_regenLists()

void equipment_regenLists ( unsigned int wid,
int outfits,
int ships )

Regenerates the equipment window lists.

Parameters
widWindow to regenerate lists.
outfitsWhether or not should regenerate outfits list.
shipsWhether or not to regenerate ships list.

Definition at line 1261 of file equipment.c.

◆ equipment_renameShip()

static void equipment_renameShip ( unsigned int wid,
const char * str )
static

Renames the selected ship.

Parameters
widParent window id.
strUnused.

Definition at line 2470 of file equipment.c.

◆ equipment_renderColumn()

static void equipment_renderColumn ( double x,
double y,
double w,
double h,
const PilotOutfitSlot * lst,
const char * txt,
int selected,
Outfit * o,
Pilot * p,
const CstSlotWidget * wgt )
static

Renders an outfit column.

Definition at line 446 of file equipment.c.

◆ equipment_renderMisc()

static void equipment_renderMisc ( double bx,
double by,
double bw,
double bh,
void * data )
static

Renders the custom equipment widget.

Parameters
bxBase X position of the widget.
byBase Y position of the widget.
bwWidth of the widget.
bhHeight of the widget.
dataCustom widget data.

Definition at line 649 of file equipment.c.

◆ equipment_renderOverlayColumn()

static void equipment_renderOverlayColumn ( double x,
double y,
double h,
PilotOutfitSlot * lst,
int mover,
CstSlotWidget * wgt )
static

Renders an outfit column.

Parameters
xX position to render at.
yY position to render at.
hHeight.
lstArray (array.h) of elements.
moverSlot for which mouseover is active
wgtWidget rendering.

Definition at line 723 of file equipment.c.

◆ equipment_renderOverlaySlots()

static void equipment_renderOverlaySlots ( double bx,
double by,
double bw,
double bh,
void * data )
static

Renders the equipment overlay.

Parameters
bxBase X position of the widget.
byBase Y position of the widget.
bwWidth of the widget.
bhHeight of the widget.
dataCustom widget data.

Definition at line 813 of file equipment.c.

◆ equipment_renderShip()

static void equipment_renderShip ( double bx,
double by,
double bw,
double bh,
void * data )
static

Renders the ship in the equipment window.

Parameters
bxBase X position of the widget.
byBase Y position of the widget.
bwWidth of the widget.
bhHeight of the widget.
dataUnused.

Definition at line 914 of file equipment.c.

◆ equipment_renderSlots()

static void equipment_renderSlots ( double bx,
double by,
double bw,
double bh,
void * data )
static

Renders the equipment slots.

Parameters
bxBase X position of the widget.
byBase Y position of the widget.
bwWidth of the widget.
bhHeight of the widget.
dataCustom widget data.

Definition at line 594 of file equipment.c.

◆ equipment_rightClickOutfits()

void equipment_rightClickOutfits ( unsigned int wid,
const char * str )
static

Handles right-click on unequipped outfit.

Parameters
widWindow to update.
strWidget name. Must be EQUIPMENT_OUTFITS.

Definition at line 122 of file equipment.c.

◆ equipment_rightClickShips()

static void equipment_rightClickShips ( unsigned int wid,
const char * str )
static

Toggles deployed status.

Definition at line 2155 of file equipment.c.

◆ equipment_sellShip()

static void equipment_sellShip ( unsigned int wid,
const char * str )
static

Player tries to sell a ship.

Parameters
widWindow player is selling ships in.
strUnused.

Definition at line 2404 of file equipment.c.

◆ equipment_shipMode()

static void equipment_shipMode ( unsigned int wid,
const char * str )
static

Toggles the ship visualization mode.

Definition at line 2500 of file equipment.c.

◆ equipment_shipStats()

int equipment_shipStats ( char * buf,
int max_len,
const Pilot * s,
int dpseps,
int name )

Creates and allocates a string containing the ship stats.

Parameters
bufBuffer to write to.
max_lenMaximum length of the string to allocate.
sPilot to get stats of.
dpsepsWhether or not to display dps and eps.
nameWhether or not to display the pilot name.

Definition at line 1426 of file equipment.c.

◆ equipment_slotDeselect()

void equipment_slotDeselect ( CstSlotWidget * wgt)

Deselects equipment stuff.

Definition at line 2542 of file equipment.c.

◆ equipment_slotWidget()

void equipment_slotWidget ( unsigned int wid,
double x,
double y,
double w,
double h,
CstSlotWidget * data )

Creates the slot widget and initializes it.

Parameters
widParent window id.
xX position to put it at.
yY position to put it at.
wWidth.
hHeight;
dataDataset to use.

Definition at line 429 of file equipment.c.

◆ equipment_swapSlot()

static int equipment_swapSlot ( unsigned int wid,
Pilot * p,
PilotOutfitSlot * slot )
static

Swaps an equipment slot.

Parameters
widParent window id.
pPilot swapping slots.
slotSlot to swap.

Definition at line 1176 of file equipment.c.

◆ equipment_toggleDeploy()

static void equipment_toggleDeploy ( unsigned int wid,
const char * wgt )
static

Definition at line 1470 of file equipment.c.

◆ equipment_toggleFav()

static void equipment_toggleFav ( unsigned int wid,
const char * wgt )
static

Handles toggling of the favourite checkbox.

Definition at line 1454 of file equipment.c.

◆ equipment_transChangeShip()

static void equipment_transChangeShip ( unsigned int wid,
const char * str )
static

Changes ship.

Parameters
widWindow player is attempting to change ships in.
strUnused.

Definition at line 2192 of file equipment.c.

◆ equipment_unequipShip()

static void equipment_unequipShip ( unsigned int wid,
const char * str )
static

Unequips the player's ship.

Parameters
widWindow id.
strof widget.

Definition at line 2261 of file equipment.c.

◆ equipment_updateOutfits()

void equipment_updateOutfits ( unsigned int wid,
const char * str )

Updates the player's outfit list.

Parameters
widWindow to update.
strUnused.

Definition at line 2041 of file equipment.c.

◆ equipment_updateShips()

void equipment_updateShips ( unsigned int wid,
const char * str )

Updates the player's ship window.

Parameters
widWindow to update.
strUnused.

Definition at line 1801 of file equipment.c.

Variable Documentation

◆ autoequip_env

nlua_env autoequip_env = LUA_NOREF
static

Definition at line 69 of file equipment.c.

◆ eq_wgt

CstSlotWidget eq_wgt
static

Equipment widget.

Definition at line 61 of file equipment.c.

◆ equipment_creating

int equipment_creating = 0
static

Whether or not creating.

Definition at line 65 of file equipment.c.

◆ equipment_dir

double equipment_dir = 0.
static

Equipment dir.

Definition at line 62 of file equipment.c.

◆ equipment_lastick

unsigned int equipment_lastick = 0
static

Last tick.

Definition at line 63 of file equipment.c.

◆ equipment_outfitMode

int equipment_outfitMode = 0
static

Outfit mode for filtering.

Definition at line 70 of file equipment.c.

◆ equipment_wid

unsigned int equipment_wid = 0
static

Global wid.

Definition at line 64 of file equipment.c.

◆ iar_data

iar_data_t iar_data[OUTFIT_TABS]
static

Stored image array positions.

Definition at line 67 of file equipment.c.

◆ iar_outfits

Outfit** iar_outfits[OUTFIT_TABS]
static

Outfits associated with the image array cells.

Definition at line 68 of file equipment.c.

◆ ship_mode

int ship_mode = 0
static

Ship mode.

Definition at line 66 of file equipment.c.