Freeciv21
Develop your civilization from humble roots to a global empire
tech.cpp File Reference
#include <cmath>
#include <cstring>
#include "fcintl.h"
#include "iterator.h"
#include "log.h"
#include "shared.h"
#include "support.h"
#include "game.h"
#include "tech.h"
+ Include dependency graph for tech.cpp:

Go to the source code of this file.

Classes

struct  advance_req_iter
 
struct  advance_root_req_iter
 

Macros

#define ADVANCE_REQ_ITER(it)   ((struct advance_req_iter *) it)
 
#define ADVANCE_ROOT_REQ_ITER(it)   ((struct advance_root_req_iter *) it)
 

Functions

const struct advanceadvance_array_last ()
 Return the last item of advances/technologies. More...
 
Tech_type_id advance_count ()
 Return the number of advances/technologies. More...
 
Tech_type_id advance_index (const struct advance *padvance)
 Return the advance index. More...
 
Tech_type_id advance_number (const struct advance *padvance)
 Return the advance index. More...
 
struct advanceadvance_by_number (const Tech_type_id atype)
 Return the advance for the given advance index. More...
 
Tech_type_id advance_required (const Tech_type_id tech, enum tech_req require)
 Accessor for requirements. More...
 
struct advanceadvance_requires (const struct advance *padvance, enum tech_req require)
 Accessor for requirements. More...
 
struct advancevalid_advance (struct advance *padvance)
 Returns pointer when the advance "exists" in this game, returns nullptr otherwise. More...
 
struct advancevalid_advance_by_number (const Tech_type_id id)
 Returns pointer when the advance "exists" in this game, returns nullptr otherwise. More...
 
struct advanceadvance_by_translated_name (const char *name)
 Does a linear search of advances[].name.translated Returns nullptr when none match. More...
 
struct advanceadvance_by_rule_name (const char *name)
 Does a linear search of advances[].name.vernacular Returns nullptr when none match. More...
 
bool advance_has_flag (Tech_type_id tech, enum tech_flag_id flag)
 Return TRUE if the tech has this flag otherwise FALSE. More...
 
void techs_precalc_data ()
 Function to precalculate needed data for technologies. More...
 
bool is_future_tech (Tech_type_id tech)
 Is the given tech a future tech. More...
 
const char * advance_name_translation (const struct advance *padvance)
 Return the (translated) name of the given advance/technology. More...
 
const char * advance_rule_name (const struct advance *padvance)
 Return the (untranslated) rule name of the advance/technology. More...
 
void tech_classes_init ()
 Initialize tech classes. More...
 
struct tech_classtech_class_by_number (const int idx)
 Return the tech_class for the given index. More...
 
const char * tech_class_name_translation (const struct tech_class *ptclass)
 Return the (translated) name of the given tech_class You must not free the return pointer. More...
 
const char * tech_class_rule_name (const struct tech_class *ptclass)
 Return the (untranslated) rule name of tech_class You must not free the return pointer. More...
 
struct tech_classtech_class_by_rule_name (const char *name)
 Does a linear search of tech_classes[].name.vernacular Returns nullptr when none match. More...
 
void user_tech_flags_init ()
 Initialize user tech flags. More...
 
void user_tech_flags_free ()
 Frees the memory associated with all user tech flags. More...
 
void set_user_tech_flag_name (enum tech_flag_id id, const char *name, const char *helptxt)
 Sets user defined name for tech flag. More...
 
const char * tech_flag_id_name_cb (enum tech_flag_id flag)
 Tech flag name callback, called from specenum code. More...
 
const char * tech_flag_helptxt (enum tech_flag_id id)
 Return the (untranslated) helptxt of the user tech flag. More...
 
bool techs_have_fixed_costs ()
 Returns true if the costs for the given technology will stay constant during the game. More...
 
void techs_init ()
 Initialize tech structures. More...
 
static void tech_free (Tech_type_id tech)
 De-allocate resources associated with the given tech. More...
 
void techs_free ()
 De-allocate resources of all techs. More...
 
size_t advance_req_iter_sizeof ()
 Return the size of the advance requirements iterator. More...
 
static void * advance_req_iter_get (const struct iterator *it)
 Return the current advance. More...
 
static void advance_req_iter_next (struct iterator *it)
 Jump to next advance requirement. More...
 
static bool advance_req_iter_valid (const struct iterator *it)
 Return whether we finished to iterate or not. More...
 
struct iteratoradvance_req_iter_init (struct advance_req_iter *it, const struct advance *goal)
 Initialize an advance requirements iterator. More...
 
size_t advance_root_req_iter_sizeof ()
 Return the size of the advance root requirements iterator. More...
 
static void * advance_root_req_iter_get (const struct iterator *it)
 Return the current root_req. More...
 
static bool advance_root_req_iter_valid (const struct iterator *it)
 Return whether we finished to iterate or not. More...
 
static void advance_root_req_iter_next (struct iterator *it)
 Jump to next advance which has a previously unseen root_req. More...
 
struct iteratoradvance_root_req_iter_init (struct advance_root_req_iter *it, const struct advance *goal)
 Initialize a root requirements iterator. More...
 

Variables

struct advance advances [A_ARRAY_SIZE]
 
struct tech_class tech_classes [MAX_NUM_TECH_CLASSES]
 
static struct user_flag user_tech_flags [MAX_NUM_USER_TECH_FLAGS]
 

Macro Definition Documentation

◆ ADVANCE_REQ_ITER

#define ADVANCE_REQ_ITER (   it)    ((struct advance_req_iter *) it)

Definition at line 34 of file tech.cpp.

◆ ADVANCE_ROOT_REQ_ITER

#define ADVANCE_ROOT_REQ_ITER (   it)    ((struct advance_root_req_iter *) it)

Definition at line 42 of file tech.cpp.

Function Documentation

◆ advance_array_last()

const struct advance* advance_array_last ( )

Return the last item of advances/technologies.

Definition at line 57 of file tech.cpp.

◆ advance_by_number()

◆ advance_by_rule_name()

struct advance* advance_by_rule_name ( const char *  name)

◆ advance_by_translated_name()

struct advance* advance_by_translated_name ( const char *  name)

Does a linear search of advances[].name.translated Returns nullptr when none match.

Definition at line 163 of file tech.cpp.

Referenced by help_dialog::make_tree(), and help_widget::set_topic_tech().

◆ advance_count()

◆ advance_has_flag()

bool advance_has_flag ( Tech_type_id  tech,
enum tech_flag_id  flag 
)

Return TRUE if the tech has this flag otherwise FALSE.

Definition at line 198 of file tech.cpp.

Referenced by found_new_tech(), helptext_advance(), research_invention_set(), and save_techs_ruleset().

◆ advance_index()

◆ advance_name_translation()

◆ advance_number()

◆ advance_req_iter_get()

static void* advance_req_iter_get ( const struct iterator it)
static

Return the current advance.

Definition at line 501 of file tech.cpp.

Referenced by advance_req_iter_init().

◆ advance_req_iter_init()

struct iterator* advance_req_iter_init ( struct advance_req_iter it,
const struct advance goal 
)

Initialize an advance requirements iterator.

Definition at line 547 of file tech.cpp.

◆ advance_req_iter_next()

static void advance_req_iter_next ( struct iterator it)
static

Jump to next advance requirement.

Definition at line 509 of file tech.cpp.

Referenced by advance_req_iter_init().

◆ advance_req_iter_sizeof()

size_t advance_req_iter_sizeof ( )

Return the size of the advance requirements iterator.

Definition at line 496 of file tech.cpp.

◆ advance_req_iter_valid()

static bool advance_req_iter_valid ( const struct iterator it)
static

Return whether we finished to iterate or not.

Definition at line 537 of file tech.cpp.

Referenced by advance_req_iter_init().

◆ advance_required()

Tech_type_id advance_required ( const Tech_type_id  tech,
enum tech_req  require 
)

◆ advance_requires()

struct advance* advance_requires ( const struct advance padvance,
enum tech_req  require 
)

◆ advance_root_req_iter_get()

static void* advance_root_req_iter_get ( const struct iterator it)
static

Return the current root_req.

Definition at line 575 of file tech.cpp.

◆ advance_root_req_iter_init()

struct iterator* advance_root_req_iter_init ( struct advance_root_req_iter it,
const struct advance goal 
)

Initialize a root requirements iterator.

Definition at line 647 of file tech.cpp.

◆ advance_root_req_iter_next()

static void advance_root_req_iter_next ( struct iterator it)
static

Jump to next advance which has a previously unseen root_req.

Definition at line 594 of file tech.cpp.

◆ advance_root_req_iter_sizeof()

size_t advance_root_req_iter_sizeof ( )

Return the size of the advance root requirements iterator.

Definition at line 567 of file tech.cpp.

◆ advance_root_req_iter_valid()

static bool advance_root_req_iter_valid ( const struct iterator it)
static

Return whether we finished to iterate or not.

Definition at line 584 of file tech.cpp.

Referenced by advance_root_req_iter_next().

◆ advance_rule_name()

◆ is_future_tech()

◆ set_user_tech_flag_name()

void set_user_tech_flag_name ( enum tech_flag_id  id,
const char *  name,
const char *  helptxt 
)

Sets user defined name for tech flag.

Definition at line 378 of file tech.cpp.

Referenced by handle_ruleset_tech_flag(), and load_tech_names().

◆ tech_class_by_number()

struct tech_class* tech_class_by_number ( const int  idx)

Return the tech_class for the given index.

Definition at line 304 of file tech.cpp.

Referenced by handle_ruleset_tech(), handle_ruleset_tech_class(), and tech_class_by_rule_name().

◆ tech_class_by_rule_name()

struct tech_class* tech_class_by_rule_name ( const char *  name)

Does a linear search of tech_classes[].name.vernacular Returns nullptr when none match.

Definition at line 335 of file tech.cpp.

Referenced by load_ruleset_techs().

◆ tech_class_name_translation()

const char* tech_class_name_translation ( const struct tech_class ptclass)

Return the (translated) name of the given tech_class You must not free the return pointer.

Definition at line 317 of file tech.cpp.

Referenced by helptext_advance().

◆ tech_class_rule_name()

const char* tech_class_rule_name ( const struct tech_class ptclass)

Return the (untranslated) rule name of tech_class You must not free the return pointer.

Definition at line 326 of file tech.cpp.

Referenced by save_techs_ruleset(), and tech_class_by_rule_name().

◆ tech_classes_init()

void tech_classes_init ( )

Initialize tech classes.

Definition at line 291 of file tech.cpp.

Referenced by game_ruleset_init().

◆ tech_flag_helptxt()

const char* tech_flag_helptxt ( enum tech_flag_id  id)

Return the (untranslated) helptxt of the user tech flag.

Definition at line 413 of file tech.cpp.

Referenced by helptext_advance(), save_techs_ruleset(), and send_ruleset_techs().

◆ tech_flag_id_name_cb()

const char* tech_flag_id_name_cb ( enum tech_flag_id  flag)

Tech flag name callback, called from specenum code.

Definition at line 401 of file tech.cpp.

Referenced by save_techs_ruleset(), and send_ruleset_techs().

◆ tech_free()

static void tech_free ( Tech_type_id  tech)
static

De-allocate resources associated with the given tech.

Definition at line 469 of file tech.cpp.

Referenced by techs_free().

◆ techs_free()

void techs_free ( )

De-allocate resources of all techs.

Definition at line 481 of file tech.cpp.

Referenced by game_ruleset_free().

◆ techs_have_fixed_costs()

bool techs_have_fixed_costs ( )

Returns true if the costs for the given technology will stay constant during the game.

False otherwise.

Checking every tech_cost_style with fixed costs seems a waste of system resources, when we can check that it is not the one style without fixed costs.

Definition at line 428 of file tech.cpp.

Referenced by helptext_advance().

◆ techs_init()

void techs_init ( )

Initialize tech structures.

Definition at line 437 of file tech.cpp.

Referenced by game_ruleset_init().

◆ techs_precalc_data()

void techs_precalc_data ( )

Function to precalculate needed data for technologies.

Definition at line 207 of file tech.cpp.

Referenced by load_rulesetdir().

◆ user_tech_flags_free()

void user_tech_flags_free ( )

Frees the memory associated with all user tech flags.

Definition at line 366 of file tech.cpp.

Referenced by game_ruleset_free().

◆ user_tech_flags_init()

void user_tech_flags_init ( )

Initialize user tech flags.

Definition at line 354 of file tech.cpp.

Referenced by game_ruleset_init().

◆ valid_advance()

struct advance* valid_advance ( struct advance padvance)

Returns pointer when the advance "exists" in this game, returns nullptr otherwise.

A tech doesn't exist if it has been flagged as removed by setting its require values to A_NEVER. Note that this function returns nullptr if either of req values is A_NEVER, rather than both, to be on the safe side.

Definition at line 138 of file tech.cpp.

Referenced by advance_req_iter_next(), advance_root_req_iter_next(), load_ruleset_techs(), load_ruleset_units(), lookup_tech_list(), manual_command(), research_get_reachable(), send_ruleset_techs(), tech_log_prefix(), tileset_setup_tech_type(), and valid_advance_by_number().

◆ valid_advance_by_number()

Variable Documentation

◆ advances

◆ tech_classes

struct tech_class tech_classes[MAX_NUM_TECH_CLASSES]

Definition at line 1 of file tech.cpp.

Referenced by tech_class_by_number(), and tech_classes_init().

◆ user_tech_flags