Freeciv21
Develop your civilization from humble roots to a global empire
team.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can redistribute it
4  and/or modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation, either version 3 of the
6  License, or (at your option) any later version. You should have received
7  a copy of the GNU General Public License along with Freeciv21. If not,
8  see https://www.gnu.org/licenses/.
9 **************************************************************************/
10 
11 #pragma once
12 
13 #include "fc_types.h"
14 
15 #include "tech.h"
16 
17 #define MAX_NUM_TEAM_SLOTS MAX_NUM_PLAYER_SLOTS
18 
19 // Opaque types.
20 struct team;
21 struct team_slot;
22 
23 // General team slot accessor functions.
24 void team_slots_init();
26 void team_slots_free();
27 int team_slot_count();
28 
29 struct team_slot *team_slot_first();
30 struct team_slot *team_slot_next(struct team_slot *tslot);
31 
32 // Team slot accessor functions.
33 int team_slot_index(const struct team_slot *tslot);
34 struct team *team_slot_get_team(const struct team_slot *tslot);
35 bool team_slot_is_used(const struct team_slot *tslot);
36 struct team_slot *team_slot_by_number(int team_id);
37 struct team_slot *team_slot_by_rule_name(const char *team_name);
38 const char *team_slot_rule_name(const struct team_slot *tslot);
39 const char *team_slot_name_translation(const struct team_slot *tslot);
40 const char *team_slot_defined_name(const struct team_slot *tslot);
41 void team_slot_set_defined_name(struct team_slot *tslot,
42  const char *team_name);
43 
44 // Team accessor functions.
45 struct team *team_new(struct team_slot *tslot);
46 void team_destroy(struct team *pteam);
47 int team_count();
48 int team_index(const struct team *pteam);
49 int team_number(const struct team *pteam);
50 struct team *team_by_number(const int team_id);
51 const char *team_rule_name(const struct team *pteam);
52 const char *team_name_translation(const struct team *pteam);
53 int team_pretty_name(const struct team *pteam, QString &buf);
54 
55 const struct player_list *team_members(const struct team *pteam);
56 
57 // Ancillary routines
58 void team_add_player(struct player *pplayer, struct team *pteam);
59 void team_remove_player(struct player *pplayer);
60 
61 // iterate over all team slots
62 #define team_slots_iterate(_tslot) \
63  if (team_slots_initialised()) { \
64  struct team_slot *_tslot = team_slot_first(); \
65  for (; nullptr != _tslot; _tslot = team_slot_next(_tslot)) {
66 #define team_slots_iterate_end \
67  } \
68  }
69 
70 // iterate over all teams, which are used at the moment
71 #define teams_iterate(_pteam) \
72  team_slots_iterate(_tslot) \
73  { \
74  struct team *_pteam = team_slot_get_team(_tslot); \
75  if (_pteam != nullptr) {
76 #define teams_iterate_end \
77  } \
78  } \
79  team_slots_iterate_end;
Definition: player.h:231
Definition: team.cpp:35
int team_index(const struct team *pteam)
Return the team index.
Definition: team.cpp:359
struct team * team_by_number(const int team_id)
Return struct team pointer for the given team index.
Definition: team.cpp:373
struct team_slot * team_slot_next(struct team_slot *tslot)
Returns the next team slot.
Definition: team.cpp:111
const char * team_name_translation(const struct team *pteam)
Returns the name (translated) of the team.
Definition: team.cpp:393
const char * team_rule_name(const struct team *pteam)
Returns the name (untranslated) of the team.
Definition: team.cpp:383
void team_add_player(struct player *pplayer, struct team *pteam)
Set a player to a team.
Definition: team.cpp:438
struct team_slot * team_slot_first()
Returns the first team slot.
Definition: team.cpp:106
const char * team_slot_defined_name(const struct team_slot *tslot)
Returns the name defined in the ruleset for this slot.
Definition: team.cpp:261
int team_count()
Return the current number of teams.
Definition: team.cpp:354
struct team * team_slot_get_team(const struct team_slot *tslot)
Returns the team corresponding to the slot.
Definition: team.cpp:132
int team_pretty_name(const struct team *pteam, QString &buf)
Set in 'buf' the name of the team 'pteam' in a format like "team <team_name>".
Definition: team.cpp:405
const char * team_slot_name_translation(const struct team_slot *tslot)
Returns the name (translated) of the slot.
Definition: team.cpp:237
int team_number(const struct team *pteam)
Return the team index/number/id.
Definition: team.cpp:364
void team_destroy(struct team *pteam)
Destroys a team.
Definition: team.cpp:333
void team_slots_init()
Initialise all team slots.
Definition: team.cpp:48
const char * team_slot_rule_name(const struct team_slot *tslot)
Returns the name (untranslated) of the slot.
Definition: team.cpp:217
bool team_slots_initialised()
Returns TRUE if the team slots have been initialized.
Definition: team.cpp:72
const struct player_list * team_members(const struct team *pteam)
Returns the member list of the team.
Definition: team.cpp:427
void team_slots_free()
Remove all team slots.
Definition: team.cpp:77
int team_slot_index(const struct team_slot *tslot)
Returns the index of the team slots.
Definition: team.cpp:120
struct team * team_new(struct team_slot *tslot)
Creates a new team for the slot.
Definition: team.cpp:294
void team_remove_player(struct player *pplayer)
Remove the player from the team.
Definition: team.cpp:471
int team_slot_count()
Returns the total number of team slots (including used slots).
Definition: team.cpp:101
struct team_slot * team_slot_by_rule_name(const char *team_name)
Does a linear search for a (defined) team name.
Definition: team.cpp:171
struct team_slot * team_slot_by_number(int team_id)
Return the possibly unused and uninitialized team slot.
Definition: team.cpp:157
bool team_slot_is_used(const struct team_slot *tslot)
Returns TRUE is this slot is "used" i.e.
Definition: team.cpp:144
void team_slot_set_defined_name(struct team_slot *tslot, const char *team_name)
Set the name defined in the ruleset for this slot.
Definition: team.cpp:272