naev 0.11.5
tech.c File Reference

Handles tech groups and metagroups for populating the spob outfitter, shipyard and commodity exchange. More...

#include "tech.h"
#include "conf.h"
#include "array.h"
#include "economy.h"
#include "log.h"
#include "ndata.h"
#include "nxml.h"
#include "outfit.h"
#include "ship.h"

Go to the source code of this file.

Data Structures

struct  tech_item_t
 Item contained in a tech group. More...
 
struct  tech_group_t
 Group of tech items, basic unit of the tech trees. More...
 

Macros

#define XML_TECH_ID   "Techs"
 
#define XML_TECH_TAG   "tech"
 

Enumerations

enum  tech_item_type_t {
  TECH_TYPE_OUTFIT , TECH_TYPE_SHIP , TECH_TYPE_COMMODITY , TECH_TYPE_GROUP ,
  TECH_TYPE_GROUP_POINTER
}
 Different tech types. More...
 

Functions

static void tech_createMetaGroup (tech_group_t *grp, tech_group_t **tech, int num)
 Creates a meta-tech group pointing only to other groups.
 
static void tech_freeGroup (tech_group_t *grp)
 Cleans up a tech group.
 
static char * tech_getItemName (tech_item_t *item)
 Gets an item's name.
 
static tech_item_ttech_itemGrow (tech_group_t *grp)
 Adds an item to a tech.
 
static int tech_parseFile (tech_group_t *tech, const char *file)
 Parses an XML tech node.
 
static int tech_parseFileData (tech_group_t *tech)
 Parses an XML tech node.
 
static int tech_parseXMLData (tech_group_t *tech, xmlNodePtr parent)
 Parses an XML tech node.
 
static int tech_addItemOutfit (tech_group_t *grp, const char *name)
 
static int tech_addItemShip (tech_group_t *grp, const char *name)
 Loads a group item pertaining to a outfit.
 
static int tech_addItemCommodity (tech_group_t *grp, const char *name)
 Loads a group item pertaining to a outfit.
 
static int tech_getID (const char *name)
 Gets the ID of a tech.
 
static int tech_addItemGroupPointer (tech_group_t *grp, const tech_group_t *ptr)
 Adds a group pointer to a group.
 
static int tech_addItemGroup (tech_group_t *grp, const char *name)
 Loads a group item pertaining to a group.
 
static void ** tech_addGroupItem (void **items, tech_item_type_t type, const tech_group_t *tech)
 Recursive function for creating an array of commodities from a tech group.
 
int tech_load (void)
 Loads the tech information.
 
void tech_free (void)
 Cleans up after the tech stuff.
 
tech_group_t * tech_groupCreateXML (xmlNodePtr node)
 Creates a tech group from an XML node.
 
tech_group_t * tech_groupCreate (void)
 Creates a tech group.
 
void tech_groupDestroy (tech_group_t *grp)
 Frees a tech group.
 
int tech_groupWrite (xmlTextWriterPtr writer, tech_group_t *grp)
 Writes a group in an xml node.
 
int tech_addItem (const char *name, const char *value)
 Adds an item to a tech.
 
int tech_addItemTech (tech_group_t *tech, const char *value)
 Adds an item to a tech.
 
int tech_rmItemTech (tech_group_t *tech, const char *value)
 Removes an item from a tech.
 
int tech_rmItem (const char *name, const char *value)
 Removes a tech item.
 
int tech_hasItem (const tech_group_t *tech, const char *item)
 Checks whether a given tech group has the specified item.
 
int tech_getItemCount (const tech_group_t *tech)
 Gets the number of techs within a given group.
 
char ** tech_getItemNames (const tech_group_t *tech, int *n)
 Gets the names of all techs within a given group.
 
char ** tech_getAllItemNames (int *n)
 Gets the names of all techs.
 
Outfit ** tech_getOutfit (const tech_group_t *tech)
 Gets all of the outfits associated to a tech group.
 
Outfit ** tech_getOutfitArray (tech_group_t **tech, int num)
 Gets the outfits from an array of techs.
 
Ship ** tech_getShip (const tech_group_t *tech)
 Gets all of the ships associated to a tech group.
 
Ship ** tech_getShipArray (tech_group_t **tech, int num)
 Gets the ships from an array of techs.
 
Commodity ** tech_getCommodityArray (tech_group_t **tech, int num)
 Gets the ships from an array of techs.
 
Commodity ** tech_getCommodity (const tech_group_t *tech)
 Gets all of the ships associated to a tech group.
 
int tech_checkOutfit (const tech_group_t *tech, const Outfit *o)
 Checks to see if there is an outfit in the tech group.
 

Variables

static tech_group_t * tech_groups = NULL
 

Detailed Description

Handles tech groups and metagroups for populating the spob outfitter, shipyard and commodity exchange.

Definition in file tech.c.

Macro Definition Documentation

◆ XML_TECH_ID

#define XML_TECH_ID   "Techs"

Tech xml document tag.

Definition at line 25 of file tech.c.

◆ XML_TECH_TAG

#define XML_TECH_TAG   "tech"

Individual tech xml tag.

Definition at line 26 of file tech.c.

Enumeration Type Documentation

◆ tech_item_type_t

Different tech types.

Enumerator
TECH_TYPE_OUTFIT 

Tech contains an outfit.

TECH_TYPE_SHIP 

Tech contains a ship.

TECH_TYPE_COMMODITY 

Tech contains a commodity.

TECH_TYPE_GROUP 

Tech contains another tech group.

TECH_TYPE_GROUP_POINTER 

Tech contains a tech group pointer.

Definition at line 31 of file tech.c.

Function Documentation

◆ tech_addGroupItem()

static void ** tech_addGroupItem ( void ** items,
tech_item_type_t type,
const tech_group_t * tech )
static

Recursive function for creating an array of commodities from a tech group.

Definition at line 606 of file tech.c.

◆ tech_addItem()

int tech_addItem ( const char * name,
const char * value )

Adds an item to a tech.

Definition at line 434 of file tech.c.

◆ tech_addItemCommodity()

static int tech_addItemCommodity ( tech_group_t * grp,
const char * name )
static

Loads a group item pertaining to a outfit.

Returns
0 on success.

Definition at line 414 of file tech.c.

◆ tech_addItemGroup()

static int tech_addItemGroup ( tech_group_t * grp,
const char * name )
static

Loads a group item pertaining to a group.

Returns
0 on success.

Definition at line 569 of file tech.c.

◆ tech_addItemGroupPointer()

static int tech_addItemGroupPointer ( tech_group_t * grp,
const tech_group_t * ptr )
static

Adds a group pointer to a group.

Definition at line 555 of file tech.c.

◆ tech_addItemOutfit()

static int tech_addItemOutfit ( tech_group_t * grp,
const char * name )
static

Definition at line 370 of file tech.c.

◆ tech_addItemShip()

static int tech_addItemShip ( tech_group_t * grp,
const char * name )
static

Loads a group item pertaining to a outfit.

Returns
0 on success.

Definition at line 392 of file tech.c.

◆ tech_addItemTech()

int tech_addItemTech ( tech_group_t * tech,
const char * value )

Adds an item to a tech.

Definition at line 468 of file tech.c.

◆ tech_checkOutfit()

int tech_checkOutfit ( const tech_group_t * tech,
const Outfit * o )

Checks to see if there is an outfit in the tech group.

Definition at line 869 of file tech.c.

◆ tech_createMetaGroup()

static void tech_createMetaGroup ( tech_group_t * grp,
tech_group_t ** tech,
int num )
static

Creates a meta-tech group pointing only to other groups.

Parameters
grpGroup to initialize.
techList of tech groups to attach.
numNumber of tech groups.

Definition at line 593 of file tech.c.

◆ tech_free()

void tech_free ( void )

Cleans up after the tech stuff.

Definition at line 141 of file tech.c.

◆ tech_freeGroup()

static void tech_freeGroup ( tech_group_t * grp)
static

Cleans up a tech group.

Definition at line 155 of file tech.c.

◆ tech_getAllItemNames()

char ** tech_getAllItemNames ( int * n)

Gets the names of all techs.

Parameters
[out]nNumber of techs.
Returns
The names of all techs.

Definition at line 706 of file tech.c.

◆ tech_getCommodity()

Commodity ** tech_getCommodity ( const tech_group_t * tech)

Gets all of the ships associated to a tech group.

Note
The returned array must be freed (but not the pointers).
Parameters
techTech group to get list of ships from.
Returns
Array (array.h): The commodities found.

Definition at line 849 of file tech.c.

◆ tech_getCommodityArray()

Commodity ** tech_getCommodityArray ( tech_group_t ** tech,
int num )

Gets the ships from an array of techs.

Note
The returned list must be freed (but not the pointers).
Parameters
techArray of techs to get from.
numNumber of elements in the array.
Returns
Array (array.h): Commodities found.

Definition at line 826 of file tech.c.

◆ tech_getID()

static int tech_getID ( const char * name)
static

Gets the ID of a tech.

Definition at line 539 of file tech.c.

◆ tech_getItemCount()

int tech_getItemCount ( const tech_group_t * tech)

Gets the number of techs within a given group.

Returns
Number of techs.

Definition at line 674 of file tech.c.

◆ tech_getItemName()

static char * tech_getItemName ( tech_item_t * item)
static

Gets an item's name.

Definition at line 197 of file tech.c.

◆ tech_getItemNames()

char ** tech_getItemNames ( const tech_group_t * tech,
int * n )

Gets the names of all techs within a given group.

Parameters
techTech group to operate on.
[out]nNumber of techs in the group.
Returns
The names of the techs contained within the group.

Definition at line 686 of file tech.c.

◆ tech_getOutfit()

Outfit ** tech_getOutfit ( const tech_group_t * tech)

Gets all of the outfits associated to a tech group.

Note
The returned list must be freed (but not the pointers).
Parameters
techTech to get outfits from.
Returns
Array (array.h): Outfits found.

Definition at line 728 of file tech.c.

◆ tech_getOutfitArray()

Outfit ** tech_getOutfitArray ( tech_group_t ** tech,
int num )

Gets the outfits from an array of techs.

Note
The returned list must be freed (but not the pointers).
Parameters
techArray of techs to get from.
numNumber of elements in the array.
Returns
Array (array.h): Outfits found.

Definition at line 753 of file tech.c.

◆ tech_getShip()

Ship ** tech_getShip ( const tech_group_t * tech)

Gets all of the ships associated to a tech group.

Note
The returned array must be freed (but not the pointers).
Parameters
techTech group to get list of ships from.
Returns
Array (array.h): The ships found.

Definition at line 776 of file tech.c.

◆ tech_getShipArray()

Ship ** tech_getShipArray ( tech_group_t ** tech,
int num )

Gets the ships from an array of techs.

Note
The returned list must be freed (but not the pointers).
Parameters
techArray of techs to get from.
numNumber of elements in the array.
Returns
Array (array.h): Ships found.

Definition at line 802 of file tech.c.

◆ tech_groupCreate()

tech_group_t * tech_groupCreate ( void )

Creates a tech group.

Definition at line 176 of file tech.c.

◆ tech_groupCreateXML()

tech_group_t * tech_groupCreateXML ( xmlNodePtr node)

Creates a tech group from an XML node.

Definition at line 165 of file tech.c.

◆ tech_groupDestroy()

void tech_groupDestroy ( tech_group_t * grp)

Frees a tech group.

Definition at line 185 of file tech.c.

◆ tech_groupWrite()

int tech_groupWrite ( xmlTextWriterPtr writer,
tech_group_t * grp )

Writes a group in an xml node.

Definition at line 219 of file tech.c.

◆ tech_hasItem()

int tech_hasItem ( const tech_group_t * tech,
const char * item )

Checks whether a given tech group has the specified item.

Parameters
techTech to search within.
itemThe item name to search for.
Returns
Whether or not the item was found.

Definition at line 658 of file tech.c.

◆ tech_itemGrow()

static tech_item_t * tech_itemGrow ( tech_group_t * grp)
static

Adds an item to a tech.

Definition at line 363 of file tech.c.

◆ tech_load()

int tech_load ( void )

Loads the tech information.

Definition at line 91 of file tech.c.

◆ tech_parseFile()

static int tech_parseFile ( tech_group_t * tech,
const char * file )
static

Parses an XML tech node.

Definition at line 243 of file tech.c.

◆ tech_parseFileData()

static int tech_parseFileData ( tech_group_t * tech)
static

Parses an XML tech node.

Definition at line 338 of file tech.c.

◆ tech_parseXMLData()

static int tech_parseXMLData ( tech_group_t * tech,
xmlNodePtr parent )
static

Parses an XML tech node.

Definition at line 274 of file tech.c.

◆ tech_rmItem()

int tech_rmItem ( const char * name,
const char * value )

Removes a tech item.

Definition at line 507 of file tech.c.

◆ tech_rmItemTech()

int tech_rmItemTech ( tech_group_t * tech,
const char * value )

Removes an item from a tech.

Definition at line 488 of file tech.c.

Variable Documentation

◆ tech_groups

tech_group_t* tech_groups = NULL
static

Definition at line 66 of file tech.c.