naev 0.10.4
Macros | Functions | Variables
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)   eq_qCol( cur, base, inv ), eq_qSym( cur, base, inv ), cur
 

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. More...
 
static void equipment_genShipList (unsigned int wid)
 Generates the ship list. More...
 
static void equipment_genOutfitList (unsigned int wid)
 Generates the outfit list. More...
 
static void equipment_genLists (unsigned int wid)
 Generates a new ship/outfit lists if needed. More...
 
static void equipment_toggleFav (unsigned int wid, const char *wgt)
 Handles toggling of the favourite checkbox. More...
 
static void equipment_toggleDeploy (unsigned int wid, const char *wgt)
 
static void equipment_renderColumn (double x, double y, double w, double h, PilotOutfitSlot *lst, const char *txt, int selected, Outfit *o, Pilot *p, CstSlotWidget *wgt)
 Renders an outfit column. More...
 
static void equipment_renderSlots (double bx, double by, double bw, double bh, void *data)
 Renders the equipment slots. More...
 
static void equipment_renderMisc (double bx, double by, double bw, double bh, void *data)
 Renders the custom equipment widget. More...
 
static void equipment_renderOverlayColumn (double x, double y, double h, PilotOutfitSlot *lst, int mover, CstSlotWidget *wgt)
 Renders an outfit column. More...
 
static void equipment_renderOverlaySlots (double bx, double by, double bw, double bh, void *data)
 Renders the equipment overlay. More...
 
static void equipment_renderShip (double bx, double by, double bw, double bh, void *data)
 Renders the ship in the equipment window. More...
 
static int equipment_mouseInColumn (double y, double h, int n, double my)
 Handles a mouse press in column. More...
 
static int equipment_mouseSlots (unsigned int wid, 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. More...
 
static char eq_qCol (double cur, double base, int inv)
 Gets the colour for comparing a current value vs a ship base value. More...
 
static int equipment_swapSlot (unsigned int wid, Pilot *p, PilotOutfitSlot *slot)
 Swaps an equipment slot. More...
 
static void equipment_sellShip (unsigned int wid, const char *str)
 Player tries to sell a ship. More...
 
static void equipment_renameShip (unsigned int wid, const char *str)
 Renames the selected ship. More...
 
static void equipment_shipMode (unsigned int wid, const char *str)
 Toggles the ship visualization mode. More...
 
static void equipment_rightClickShips (unsigned int wid, const char *str)
 Toggles deployed status. More...
 
static void equipment_transChangeShip (unsigned int wid, const char *str)
 Changes ship. More...
 
static void equipment_changeShip (unsigned int wid)
 Player attempts to change ship. More...
 
static void equipment_unequipShip (unsigned int wid, const char *str)
 Unequips the player's ship. More...
 
static void equipment_autoequipShip (unsigned int wid, const char *str)
 Does the autoequip magic on the player's ship. More...
 
static void equipment_filterOutfits (unsigned int wid, const char *str)
 Handles text input in the filter input widget. More...
 
static void equipment_rightClickOutfits (unsigned int wid, const char *str)
 Handles right-click on unequipped outfit. More...
 
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. More...
 
static int equipment_playerAddOutfit (const Outfit *o, int quantity)
 Wrapper to only add unique outfits. More...
 
static int equipment_playerRmOutfit (const Outfit *o, int quantity)
 Wrapper to only remove unique outfits. More...
 
void equipment_open (unsigned int wid)
 Opens the player's equipment window. More...
 
void equipment_slotWidget (unsigned int wid, double x, double y, double w, double h, CstSlotWidget *data)
 Creates the slot widget and initializes it. More...
 
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. More...
 
static int equipment_mouseColumn (unsigned int wid, 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. More...
 
void equipment_regenLists (unsigned int wid, int outfits, int ships)
 Regenerates the equipment window lists. More...
 
void equipment_addAmmo (void)
 Adds all the ammo it can to the player. More...
 
int equipment_shipStats (char *buf, int max_len, const Pilot *s, int dpseps, int name)
 Creates and allocates a string containing the ship stats. More...
 
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. More...
 
void equipment_updateShips (unsigned int wid, const char *str)
 Updates the player's ship window. More...
 
void equipment_updateOutfits (unsigned int wid, const char *str)
 Updates the player's outfit list. More...
 
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. More...
 
void equipment_slotDeselect (CstSlotWidget *wgt)
 Deselects equipment stuff. More...
 

Variables

static CstSlotWidget eq_wgt
 
static double equipment_dir = 0.
 
static unsigned int equipment_lastick = 0
 
static unsigned int equipment_wid = 0
 
static int ship_mode = 0
 
static iar_data_t * iar_data = NULL
 
static Outfit *** iar_outfits = NULL
 
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 
)    eq_qCol( cur, base, inv ), eq_qSym( cur, base, inv ), cur

Definition at line 1691 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 1670 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 1682 of file equipment.c.

◆ equipment_addAmmo()

void equipment_addAmmo ( void  )

Adds all the ammo it can to the player.

Definition at line 1301 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 2210 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 539 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 2083 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 1999 of file equipment.c.

◆ equipment_cleanup()

void equipment_cleanup ( void  )

Cleans up after the equipment stuff.

Definition at line 2396 of file equipment.c.

◆ equipment_filter()

static int equipment_filter ( const Outfit o)
static

Definition at line 1507 of file equipment.c.

◆ equipment_filterCore()

static int equipment_filterCore ( const Outfit o)
static

Definition at line 1556 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 1934 of file equipment.c.

◆ equipment_filterStructure()

static int equipment_filterStructure ( const Outfit o)
static

Definition at line 1553 of file equipment.c.

◆ equipment_filterUtility()

static int equipment_filterUtility ( const Outfit o)
static

Definition at line 1550 of file equipment.c.

◆ equipment_filterWeapon()

static int equipment_filterWeapon ( const Outfit o)
static

Definition at line 1547 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 1401 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 1564 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 1418 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 255 of file equipment.c.

◆ equipment_mouseColumn()

static int equipment_mouseColumn ( unsigned int  wid,
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 1000 of file equipment.c.

◆ equipment_mouseInColumn()

static int equipment_mouseInColumn ( double  y,
double  h,
int  n,
double  my 
)
static

Handles a mouse press in column.

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

Definition at line 976 of file equipment.c.

◆ equipment_mouseSlots()

static int equipment_mouseSlots ( unsigned int  wid,
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 1080 of file equipment.c.

◆ equipment_open()

void equipment_open ( unsigned int  wid)

Opens the player's equipment window.

Definition at line 298 of file equipment.c.

◆ equipment_outfitPopdown()

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

Definition at line 1961 of file equipment.c.

◆ equipment_outfitPopdownActivate()

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

Definition at line 1955 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 1944 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 2376 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 2386 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 1235 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 2337 of file equipment.c.

◆ equipment_renderColumn()

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

Renders an outfit column.

Definition at line 444 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 623 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 697 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 781 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 889 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 568 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 121 of file equipment.c.

◆ equipment_rightClickShips()

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

Toggles deployed status.

Definition at line 2031 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 2281 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 2367 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 1327 of file equipment.c.

◆ equipment_slotDeselect()

void equipment_slotDeselect ( CstSlotWidget wgt)

Deselects equipment stuff.

Definition at line 2414 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 427 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 1155 of file equipment.c.

◆ equipment_toggleDeploy()

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

Definition at line 1369 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 1353 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 2070 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 2138 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 1913 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 1698 of file equipment.c.

Variable Documentation

◆ autoequip_env

nlua_env autoequip_env = LUA_NOREF
static

Definition at line 68 of file equipment.c.

◆ eq_wgt

CstSlotWidget eq_wgt
static

Equipment widget.

Definition at line 61 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 69 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 = NULL
static

Stored image array positions.

Definition at line 66 of file equipment.c.

◆ iar_outfits

Outfit*** iar_outfits = NULL
static

Outfits associated with the image array cells.

Definition at line 67 of file equipment.c.

◆ ship_mode

int ship_mode = 0
static

Ship mode.

Definition at line 65 of file equipment.c.