naev 0.12.6
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 "ndata.h"
#include "nlua.h"
#include "nlua_tk.h"
#include "nstring.h"
#include "ntime.h"
#include "pilot_outfit.h"
#include "player.h"
#include "player_fleet.h"
#include "shipstats.h"
#include "slots.h"
#include "tk/toolkit_priv.h"
#include "toolkit.h"
Include dependency graph for equipment.c:

Go to the source code of this file.

Data Structures

struct  ShipWidgetData

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 void equipment_freeShipData (unsigned int wid, const char *unused)
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.
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)
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 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.
void equipment_slotSelect (CstSlotWidget *wgt, PlayerShip_t *p)

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
static int(* tabfilters [])(const Outfit *o)

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 55 of file equipment.c.

◆ BUTTON_WIDTH

#define BUTTON_WIDTH   200

Default button width.

Definition at line 54 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:1974
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:1962

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

◆ EQUIPMENT_FILTER

#define EQUIPMENT_FILTER   "inpFilterOutfits"

Definition at line 50 of file equipment.c.

◆ EQUIPMENT_OUTFIT_TAB

#define EQUIPMENT_OUTFIT_TAB   "tabOutfits"

Definition at line 48 of file equipment.c.

◆ EQUIPMENT_OUTFITS

#define EQUIPMENT_OUTFITS   "iarAvailOutfits"

Definition at line 49 of file equipment.c.

◆ EQUIPMENT_SHIPS

#define EQUIPMENT_SHIPS   "iarAvailShips"

Definition at line 47 of file equipment.c.

◆ OUTFIT_TABS

#define OUTFIT_TABS   5

Definition at line 51 of file equipment.c.

Function Documentation

◆ eq_qCol()

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 1962 of file equipment.c.

◆ eq_qSym()

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 1974 of file equipment.c.

◆ equipment_addAmmo()

void equipment_addAmmo ( void )

Adds all the ammo it can to the player.

Definition at line 1578 of file equipment.c.

◆ equipment_autoequipShip()

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

Does the autoequip magic on the player's ship.

Definition at line 2608 of file equipment.c.

◆ equipment_calculateSlots()

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 598 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 1500 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 1516 of file equipment.c.

◆ equipment_changeShip()

void equipment_changeShip ( unsigned int wid)
static

Player attempts to change ship.

Parameters
widWindow player is attempting to change ships in.

Definition at line 2476 of file equipment.c.

◆ equipment_changeTab()

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 2395 of file equipment.c.

◆ equipment_cleanup()

void equipment_cleanup ( void )

Cleans up after the equipment stuff.

Definition at line 2810 of file equipment.c.

◆ equipment_filter()

int equipment_filter ( const Outfit * o)
static

Definition at line 1789 of file equipment.c.

◆ equipment_filterCore()

int equipment_filterCore ( const Outfit * o)
static

Definition at line 1847 of file equipment.c.

◆ equipment_filterOutfits()

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 2328 of file equipment.c.

◆ equipment_filterStructure()

int equipment_filterStructure ( const Outfit * o)
static

Definition at line 1843 of file equipment.c.

◆ equipment_filterUtility()

int equipment_filterUtility ( const Outfit * o)
static

Definition at line 1839 of file equipment.c.

◆ equipment_filterWeapon()

int equipment_filterWeapon ( const Outfit * o)
static

Definition at line 1835 of file equipment.c.

◆ equipment_freeShipData()

void equipment_freeShipData ( unsigned int wid,
const char * unused )
static

Definition at line 1080 of file equipment.c.

◆ equipment_genLists()

void equipment_genLists ( unsigned int wid)
static

Generates a new ship/outfit lists if needed.

Parameters
widParent window id.

Definition at line 1683 of file equipment.c.

◆ equipment_genOutfitList()

void equipment_genOutfitList ( unsigned int wid)
static

Generates the outfit list.

Parameters
widWindow to generate list on.

Definition at line 1856 of file equipment.c.

◆ equipment_genShipList()

void equipment_genShipList ( unsigned int wid)
static

Generates the ship list.

Parameters
widWindow to generate list on.

Definition at line 1693 of file equipment.c.

◆ equipment_getDim()

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 286 of file equipment.c.

◆ equipment_mouseColumn()

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.
Returns
Whether the event was used or not.

Definition at line 1130 of file equipment.c.

◆ equipment_mouseInColumn()

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 1099 of file equipment.c.

◆ equipment_mouseSlots()

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 1244 of file equipment.c.

◆ equipment_open()

void equipment_open ( unsigned int wid)

Opens the player's equipment window.

Definition at line 329 of file equipment.c.

◆ equipment_outfitPopdown()

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

Definition at line 2355 of file equipment.c.

◆ equipment_outfitPopdownActivate()

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

Definition at line 2349 of file equipment.c.

◆ equipment_outfitPopdownSelect()

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

Functions for the popdown menu (filter outfits by size)

Definition at line 2338 of file equipment.c.

◆ equipment_playerAddOutfit()

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

Wrapper to only add unique outfits.

Definition at line 2789 of file equipment.c.

◆ equipment_playerRmOutfit()

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

Wrapper to only remove unique outfits.

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

◆ equipment_renameShip()

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

Renames the selected ship.

Parameters
widParent window id.
strUnused.

Definition at line 2748 of file equipment.c.

◆ equipment_renderColumn()

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 478 of file equipment.c.

◆ equipment_renderMisc()

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 682 of file equipment.c.

◆ equipment_renderOverlayColumn()

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 772 of file equipment.c.

◆ equipment_renderOverlaySlots()

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 859 of file equipment.c.

◆ equipment_renderShip()

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 959 of file equipment.c.

◆ equipment_renderSlots()

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 629 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 150 of file equipment.c.

◆ equipment_rightClickShips()

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

Toggles deployed status.

Definition at line 2424 of file equipment.c.

◆ equipment_sellShip()

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 2681 of file equipment.c.

◆ equipment_shipMode()

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

Toggles the ship visualization mode.

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

◆ equipment_slotDeselect()

void equipment_slotDeselect ( CstSlotWidget * wgt)

Deselects equipment stuff.

Definition at line 2823 of file equipment.c.

◆ equipment_slotSelect()

void equipment_slotSelect ( CstSlotWidget * wgt,
PlayerShip_t * p )

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

◆ equipment_swapSlot()

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 1319 of file equipment.c.

◆ equipment_toggleDeploy()

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

Definition at line 1651 of file equipment.c.

◆ equipment_toggleFav()

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

Handles toggling of the favourite checkbox.

Definition at line 1636 of file equipment.c.

◆ equipment_transChangeShip()

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 2463 of file equipment.c.

◆ equipment_unequipShip()

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

Unequips the player's ship.

Parameters
widWindow id.
strof widget.

Definition at line 2532 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 2307 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 1992 of file equipment.c.

Variable Documentation

◆ autoequip_env

nlua_env autoequip_env = LUA_NOREF
static

Definition at line 77 of file equipment.c.

◆ eq_wgt

CstSlotWidget eq_wgt
static

Equipment widget.

Definition at line 68 of file equipment.c.

◆ equipment_creating

int equipment_creating = 0
static

Whether or not creating.

Definition at line 72 of file equipment.c.

◆ equipment_dir

double equipment_dir = 0.
static

Equipment dir.

Definition at line 69 of file equipment.c.

◆ equipment_lastick

unsigned int equipment_lastick = 0
static

Last tick.

Definition at line 70 of file equipment.c.

◆ equipment_outfitMode

int equipment_outfitMode = 0
static

Outfit mode for filtering.

Definition at line 78 of file equipment.c.

◆ equipment_wid

unsigned int equipment_wid = 0
static

Global wid.

Definition at line 71 of file equipment.c.

◆ iar_data

iar_data_t iar_data[OUTFIT_TABS]
static

Stored image array positions.

Definition at line 74 of file equipment.c.

◆ iar_outfits

Outfit** iar_outfits[OUTFIT_TABS]
static

Outfits associated with the image array cells.

Definition at line 75 of file equipment.c.

◆ ship_mode

int ship_mode = 0
static

Ship mode.

Definition at line 73 of file equipment.c.

◆ tabfilters

int(* tabfilters[])(const Outfit *o) ( const Outfit * o)
static
Initial value:
= {
equipment_filter, equipment_filterWeapon, equipment_filterUtility,
equipment_filterStructure, equipment_filterCore,
}

Definition at line 140 of file equipment.c.