naev 0.12.5
tech.c File Reference

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

#include "tech.h"
#include "array.h"
#include "commodity.h"
#include "conf.h"
#include "log.h"
#include "ndata.h"
#include "nxml.h"
#include "outfit.h"
#include "rng.h"
#include "ship.h"
Include dependency graph for tech.c:

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 tech_item_ttech_addItemOutfit (tech_group_t *grp, const char *name)
static tech_item_ttech_addItemShip (tech_group_t *grp, const char *name)
 Loads a group item pertaining to a outfit.
static tech_item_ttech_addItemCommodity (tech_group_t *grp, const char *name)
 Loads a group item pertaining to a outfit.
static tech_item_ttech_addItemTechInternal (tech_group_t *tech, const char *value)
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 tech_item_ttech_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.
static int tech_cmp (const void *p1, const void *p2)
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.
static int tech_hasItemInternal (const tech_group_t *tech, const tech_item_t *item)
int tech_hasShip (const tech_group_t *tech, const Ship *ship)
 Checks to see whether a tech group contains a ship.
int tech_hasOutfit (const tech_group_t *tech, const Outfit *outfit)
 Checks to see whether a tech group contains a outfit.
int tech_hasCommodity (const tech_group_t *tech, const Commodity *comm)
 Checks to see whether a tech group contains a commodity.
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 26 of file tech.c.

◆ XML_TECH_TAG

#define XML_TECH_TAG   "tech"

Individual tech xml tag.

Definition at line 27 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 32 of file tech.c.

Function Documentation

◆ tech_addGroupItem()

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 623 of file tech.c.

◆ tech_addItem()

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

Adds an item to a tech.

Definition at line 443 of file tech.c.

◆ tech_addItemCommodity()

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

Loads a group item pertaining to a outfit.

Definition at line 423 of file tech.c.

◆ tech_addItemGroup()

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

Loads a group item pertaining to a group.

Definition at line 584 of file tech.c.

◆ tech_addItemGroupPointer()

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

Adds a group pointer to a group.

Definition at line 571 of file tech.c.

◆ tech_addItemOutfit()

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

Definition at line 383 of file tech.c.

◆ tech_addItemShip()

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

Loads a group item pertaining to a outfit.

Definition at line 403 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 480 of file tech.c.

◆ tech_addItemTechInternal()

tech_item_t * tech_addItemTechInternal ( tech_group_t * tech,
const char * value )
static

Definition at line 485 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 980 of file tech.c.

◆ tech_cmp()

int tech_cmp ( const void * p1,
const void * p2 )
static

Definition at line 96 of file tech.c.

◆ tech_createMetaGroup()

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 608 of file tech.c.

◆ tech_free()

void tech_free ( void )

Cleans up after the tech stuff.

Definition at line 161 of file tech.c.

◆ tech_freeGroup()

void tech_freeGroup ( tech_group_t * grp)
static

Cleans up a tech group.

Definition at line 175 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 817 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 960 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 937 of file tech.c.

◆ tech_getID()

int tech_getID ( const char * name)
static

Gets the ID of a tech.

Definition at line 558 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 785 of file tech.c.

◆ tech_getItemName()

char * tech_getItemName ( tech_item_t * item)
static

Gets an item's name.

Definition at line 217 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 797 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 839 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 864 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 887 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 913 of file tech.c.

◆ tech_groupCreate()

tech_group_t * tech_groupCreate ( void )

Creates a tech group.

Definition at line 196 of file tech.c.

◆ tech_groupCreateXML()

tech_group_t * tech_groupCreateXML ( xmlNodePtr node)

Creates a tech group from an XML node.

Definition at line 185 of file tech.c.

◆ tech_groupDestroy()

void tech_groupDestroy ( tech_group_t * grp)

Frees a tech group.

Definition at line 205 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 239 of file tech.c.

◆ tech_hasCommodity()

int tech_hasCommodity ( const tech_group_t * tech,
const Commodity * comm )

Checks to see whether a tech group contains a commodity.

Parameters
techTech group to look at.
commCommodity to see if is contained in the group.
Returns
1 if the commodity is contained, 0 otherwise.

Definition at line 771 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 680 of file tech.c.

◆ tech_hasItemInternal()

int tech_hasItemInternal ( const tech_group_t * tech,
const tech_item_t * item )
static

Definition at line 693 of file tech.c.

◆ tech_hasOutfit()

int tech_hasOutfit ( const tech_group_t * tech,
const Outfit * outfit )

Checks to see whether a tech group contains a outfit.

Parameters
techTech group to look at.
outfitOutfit to see if is contained in the group.
Returns
1 if the outfit is contained, 0 otherwise.

Definition at line 755 of file tech.c.

◆ tech_hasShip()

int tech_hasShip ( const tech_group_t * tech,
const Ship * ship )

Checks to see whether a tech group contains a ship.

Parameters
techTech group to look at.
shipShip to see if is contained in the group.
Returns
1 if the ship is contained, 0 otherwise.

Definition at line 739 of file tech.c.

◆ tech_itemGrow()

tech_item_t * tech_itemGrow ( tech_group_t * grp)
static

Adds an item to a tech.

Definition at line 374 of file tech.c.

◆ tech_load()

int tech_load ( void )

Loads the tech information.

Definition at line 106 of file tech.c.

◆ tech_parseFile()

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

Parses an XML tech node.

Definition at line 263 of file tech.c.

◆ tech_parseFileData()

int tech_parseFileData ( tech_group_t * tech)
static

Parses an XML tech node.

Definition at line 349 of file tech.c.

◆ tech_parseXMLData()

int tech_parseXMLData ( tech_group_t * tech,
xmlNodePtr parent )
static

Parses an XML tech node.

Definition at line 294 of file tech.c.

◆ tech_rmItem()

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

Removes a tech item.

Definition at line 525 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 506 of file tech.c.

Variable Documentation

◆ tech_groups

tech_group_t* tech_groups = NULL
static

Definition at line 68 of file tech.c.