Freeciv21
Develop your civilization from humble roots to a global empire
tech.h File Reference
#include "bitvector.h"
#include "shared.h"
#include "fc_types.h"
#include "name_translation.h"
#include "requirements.h"
#include "specenum_gen.h"
+ Include dependency graph for tech.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tech_class
 
struct  advance
 

Macros

#define A_NONE   0
 
#define A_FIRST   1
 
#define A_LAST   (MAX_NUM_ADVANCES + 1)
 
#define A_FUTURE   (A_LAST + 1)
 
#define A_ARRAY_SIZE   (A_FUTURE + 1)
 
#define A_UNSET   (A_LAST + 2)
 
#define A_UNKNOWN   (A_LAST + 3)
 
#define A_NEVER   (nullptr)
 
#define SPECENUM_NAME   tech_flag_id
 
#define SPECENUM_VALUE0   TF_BONUS_TECH
 
#define SPECENUM_VALUE0NAME   N_("Bonus_Tech")
 
#define SPECENUM_VALUE1   TF_BRIDGE
 
#define SPECENUM_VALUE1NAME   N_("Bridge")
 
#define SPECENUM_VALUE2   TF_BUILD_AIRBORNE
 
#define SPECENUM_VALUE2NAME   N_("Build_Airborne")
 
#define SPECENUM_VALUE3   TF_CLAIM_OCEAN
 
#define SPECENUM_VALUE3NAME   N_("Claim_Ocean")
 
#define SPECENUM_VALUE4   TF_CLAIM_OCEAN_LIMITED
 
#define SPECENUM_VALUE4NAME   N_("Claim_Ocean_Limited")
 
#define SPECENUM_VALUE5   TECH_USER_1
 
#define SPECENUM_VALUE6   TECH_USER_2
 
#define SPECENUM_VALUE7   TECH_USER_3
 
#define SPECENUM_VALUE8   TECH_USER_4
 
#define SPECENUM_VALUE9   TECH_USER_5
 
#define SPECENUM_VALUE10   TECH_USER_6
 
#define SPECENUM_VALUE11   TECH_USER_7
 
#define SPECENUM_VALUE12   TECH_USER_LAST
 
#define SPECENUM_COUNT   TF_COUNT
 
#define SPECENUM_BITVECTOR   bv_tech_flags
 
#define SPECENUM_NAMEOVERRIDE
 
#define MAX_NUM_USER_TECH_FLAGS   (TECH_USER_LAST - TECH_USER_1 + 1)
 
#define tech_class_index(_ptclass_)   (_ptclass_)->idx
 
#define tech_class_iterate(_p)
 
#define tech_class_iterate_end
 
#define tech_class_re_active_iterate(_p)
 
#define tech_class_re_active_iterate_end
 
#define advance_index_iterate(_start, _index)
 
#define advance_index_iterate_end
 
#define advance_iterate(_start, _p)
 
#define advance_iterate_end
 
#define advance_re_active_iterate(_p)
 
#define advance_re_active_iterate_end
 
#define advance_req_iterate(_goal, _padvance)
 
#define advance_req_iterate_end   generic_iterate_end
 
#define advance_root_req_iterate(_goal, _padvance)
 
#define advance_root_req_iterate_end   generic_iterate_end
 

Enumerations

enum  tech_req { AR_ONE = 0 , AR_TWO = 1 , AR_ROOT = 2 , AR_SIZE }
 

Functions

 BV_DEFINE (bv_techs, A_LAST)
 
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...
 
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 atype)
 Returns pointer when the advance "exists" in this game, returns nullptr otherwise. More...
 
struct advanceadvance_by_rule_name (const char *name)
 Does a linear search of advances[].name.vernacular Returns nullptr when none match. More...
 
struct advanceadvance_by_translated_name (const char *name)
 Does a linear search of advances[].name.translated Returns nullptr when none match. More...
 
const char * advance_rule_name (const struct advance *padvance)
 Return the (untranslated) rule name of the advance/technology. More...
 
const char * advance_name_translation (const struct advance *padvance)
 Return the (translated) name of the given 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_helptxt (enum tech_flag_id id)
 Return the (untranslated) helptxt of the user tech flag. 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...
 
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...
 
bool techs_have_fixed_costs ()
 Returns true if the costs for the given technology will stay constant during the game. More...
 
bool is_future_tech (Tech_type_id tech)
 Is the given tech a future tech. More...
 
void techs_init ()
 Initialize tech structures. More...
 
void techs_free ()
 De-allocate resources of all techs. More...
 
void techs_precalc_data ()
 Function to precalculate needed data for technologies. More...
 
const struct advanceadvance_array_last ()
 Return the last item of advances/technologies. More...
 
size_t advance_req_iter_sizeof ()
 Return the size of the advance requirements iterator. 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...
 
struct iteratoradvance_root_req_iter_init (struct advance_root_req_iter *it, const struct advance *goal)
 Initialize a root requirements iterator. More...
 

Macro Definition Documentation

◆ A_ARRAY_SIZE

#define A_ARRAY_SIZE   (A_FUTURE + 1)

Definition at line 40 of file tech.h.

◆ A_FIRST

#define A_FIRST   1

Definition at line 37 of file tech.h.

◆ A_FUTURE

#define A_FUTURE   (A_LAST + 1)

Definition at line 39 of file tech.h.

◆ A_LAST

#define A_LAST   (MAX_NUM_ADVANCES + 1)

Definition at line 38 of file tech.h.

◆ A_NEVER

#define A_NEVER   (nullptr)

Definition at line 44 of file tech.h.

◆ A_NONE

#define A_NONE   0

Definition at line 36 of file tech.h.

◆ A_UNKNOWN

#define A_UNKNOWN   (A_LAST + 3)

Definition at line 42 of file tech.h.

◆ A_UNSET

#define A_UNSET   (A_LAST + 2)

Definition at line 41 of file tech.h.

◆ advance_index_iterate

#define advance_index_iterate (   _start,
  _index 
)
Value:
{ \
Tech_type_id _index = (_start); \
for (; _index < advance_count(); _index++) {
Tech_type_id advance_count()
Return the number of advances/technologies.
Definition: tech.cpp:68

Definition at line 221 of file tech.h.

◆ advance_index_iterate_end

#define advance_index_iterate_end
Value:
} \
}

Definition at line 226 of file tech.h.

◆ advance_iterate

#define advance_iterate (   _start,
  _p 
)
Value:
{ \
struct advance *_p = advance_by_number(_start); \
if (nullptr != _p) { \
for (; _p <= advance_array_last(); _p++) {
Definition: tech.h:113
struct advance * advance_by_number(const Tech_type_id atype)
Return the advance for the given advance index.
Definition: tech.cpp:94
const struct advance * advance_array_last()
Return the last item of advances/technologies.
Definition: tech.cpp:57

Definition at line 232 of file tech.h.

◆ advance_iterate_end

#define advance_iterate_end
Value:
} \
} \
}

Definition at line 238 of file tech.h.

◆ advance_re_active_iterate

#define advance_re_active_iterate (   _p)
Value:
{ \
if (_p->require[AR_ONE] != A_NEVER) {
#define A_NEVER
Definition: tech.h:44
@ AR_ONE
Definition: tech.h:104
#define advance_iterate(_start, _p)
Definition: tech.h:232
#define A_FIRST
Definition: tech.h:37

Definition at line 243 of file tech.h.

◆ advance_re_active_iterate_end

#define advance_re_active_iterate_end
Value:
} \
} \
advance_iterate_end;

Definition at line 248 of file tech.h.

◆ advance_req_iterate

#define advance_req_iterate (   _goal,
  _padvance 
)
Value:
generic_iterate(struct advance_req_iter, const struct advance *, \
#define generic_iterate(TYPE_it, TYPE_a, NAME_a, FUNC_size, FUNC_init,...)
Definition: iterator.h:73
struct iterator * advance_req_iter_init(struct advance_req_iter *it, const struct advance *goal)
Initialize an advance requirements iterator.
Definition: tech.cpp:547
size_t advance_req_iter_sizeof()
Return the size of the advance requirements iterator.
Definition: tech.cpp:496

Definition at line 262 of file tech.h.

◆ advance_req_iterate_end

#define advance_req_iterate_end   generic_iterate_end

Definition at line 266 of file tech.h.

◆ advance_root_req_iterate

#define advance_root_req_iterate (   _goal,
  _padvance 
)
Value:
generic_iterate(struct advance_root_req_iter, const struct advance *, \
struct iterator * advance_root_req_iter_init(struct advance_root_req_iter *it, const struct advance *goal)
Initialize a root requirements iterator.
Definition: tech.cpp:647
size_t advance_root_req_iter_sizeof()
Return the size of the advance root requirements iterator.
Definition: tech.cpp:567

Definition at line 277 of file tech.h.

◆ advance_root_req_iterate_end

#define advance_root_req_iterate_end   generic_iterate_end

Definition at line 281 of file tech.h.

◆ MAX_NUM_USER_TECH_FLAGS

#define MAX_NUM_USER_TECH_FLAGS   (TECH_USER_LAST - TECH_USER_1 + 1)

Definition at line 102 of file tech.h.

◆ SPECENUM_BITVECTOR

#define SPECENUM_BITVECTOR   bv_tech_flags

Definition at line 98 of file tech.h.

◆ SPECENUM_COUNT

#define SPECENUM_COUNT   TF_COUNT

Definition at line 97 of file tech.h.

◆ SPECENUM_NAME

#define SPECENUM_NAME   tech_flag_id

Definition at line 69 of file tech.h.

◆ SPECENUM_NAMEOVERRIDE

#define SPECENUM_NAMEOVERRIDE

Definition at line 99 of file tech.h.

◆ SPECENUM_VALUE0

#define SPECENUM_VALUE0   TF_BONUS_TECH

Definition at line 71 of file tech.h.

◆ SPECENUM_VALUE0NAME

#define SPECENUM_VALUE0NAME   N_("Bonus_Tech")

Definition at line 74 of file tech.h.

◆ SPECENUM_VALUE1

#define SPECENUM_VALUE1   TF_BRIDGE

Definition at line 76 of file tech.h.

◆ SPECENUM_VALUE10

#define SPECENUM_VALUE10   TECH_USER_6

Definition at line 93 of file tech.h.

◆ SPECENUM_VALUE11

#define SPECENUM_VALUE11   TECH_USER_7

Definition at line 94 of file tech.h.

◆ SPECENUM_VALUE12

#define SPECENUM_VALUE12   TECH_USER_LAST

Definition at line 95 of file tech.h.

◆ SPECENUM_VALUE1NAME

#define SPECENUM_VALUE1NAME   N_("Bridge")

Definition at line 77 of file tech.h.

◆ SPECENUM_VALUE2

#define SPECENUM_VALUE2   TF_BUILD_AIRBORNE

Definition at line 79 of file tech.h.

◆ SPECENUM_VALUE2NAME

#define SPECENUM_VALUE2NAME   N_("Build_Airborne")

Definition at line 80 of file tech.h.

◆ SPECENUM_VALUE3

#define SPECENUM_VALUE3   TF_CLAIM_OCEAN

Definition at line 82 of file tech.h.

◆ SPECENUM_VALUE3NAME

#define SPECENUM_VALUE3NAME   N_("Claim_Ocean")

Definition at line 83 of file tech.h.

◆ SPECENUM_VALUE4

#define SPECENUM_VALUE4   TF_CLAIM_OCEAN_LIMITED

Definition at line 86 of file tech.h.

◆ SPECENUM_VALUE4NAME

#define SPECENUM_VALUE4NAME   N_("Claim_Ocean_Limited")

Definition at line 87 of file tech.h.

◆ SPECENUM_VALUE5

#define SPECENUM_VALUE5   TECH_USER_1

Definition at line 88 of file tech.h.

◆ SPECENUM_VALUE6

#define SPECENUM_VALUE6   TECH_USER_2

Definition at line 89 of file tech.h.

◆ SPECENUM_VALUE7

#define SPECENUM_VALUE7   TECH_USER_3

Definition at line 90 of file tech.h.

◆ SPECENUM_VALUE8

#define SPECENUM_VALUE8   TECH_USER_4

Definition at line 91 of file tech.h.

◆ SPECENUM_VALUE9

#define SPECENUM_VALUE9   TECH_USER_5

Definition at line 92 of file tech.h.

◆ tech_class_index

#define tech_class_index (   _ptclass_)    (_ptclass_)->idx

Definition at line 167 of file tech.h.

◆ tech_class_iterate

#define tech_class_iterate (   _p)
Value:
{ \
int _i_##_p; \
for (_i_##_p = 0; _i_##_p < game.control.num_tech_classes; _i_##_p++) { \
struct tech_class *_p = tech_class_by_number(_i_##_p);
struct civ_game game
Definition: game.cpp:47
struct packet_ruleset_control control
Definition: game.h:74
struct tech_class * tech_class_by_number(const int idx)
Return the tech_class for the given index.
Definition: tech.cpp:304

Definition at line 172 of file tech.h.

◆ tech_class_iterate_end

#define tech_class_iterate_end
Value:
} \
}

Definition at line 178 of file tech.h.

◆ tech_class_re_active_iterate

#define tech_class_re_active_iterate (   _p)
Value:
{ \
if (!_p->ruledit_disabled) {
#define tech_class_iterate(_p)
Definition: tech.h:172

Definition at line 182 of file tech.h.

◆ tech_class_re_active_iterate_end

#define tech_class_re_active_iterate_end
Value:
} \
} \
tech_class_iterate_end;

Definition at line 187 of file tech.h.

Enumeration Type Documentation

◆ tech_req

enum tech_req
Enumerator
AR_ONE 
AR_TWO 
AR_ROOT 
AR_SIZE 

Definition at line 104 of file tech.h.

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_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_sizeof()

size_t advance_req_iter_sizeof ( )

Return the size of the advance requirements iterator.

Definition at line 496 of file tech.cpp.

◆ 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_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_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_rule_name()

◆ BV_DEFINE()

BV_DEFINE ( bv_techs  ,
A_LAST   
)

◆ 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().

◆ 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()