Freeciv21
Develop your civilization from humble roots to a global empire
spaceship.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
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 // utility
14 #include "bitvector.h"
15 #include "support.h" // bool type
16 
17 // common
18 #include "fc_types.h"
19 
20 /**********************************************************************
21 First, some ascii art showing the spaceship and relevant parts,
22 including numbering of parts:
23  2 4 6 8 10 12 14 16 18 20 22 24 26 28
24  | | | | | | | | | | | | | |
25  :::-:::-:::-:::-:::-:::-:::-:::-:::-:::-:::-:::-:::-:::- s=structural
26  2_:::-:::-:::-:::-:::-:::-:::-:::-:::-:::-:::-:::-:::-:::- C=component
27  :::-:::-:::-:::-:::-:::-:::-:::-:::-:::-/C12/ C13 \:::- M=module
28  4_!!!-!!!-!!!-!!!-!!!-!!!-!!!-!!!-!!!-!!!-\F6/\ P6 /!!!-
29  :::-:::-\++++++/:::-:::-\++++++/:::-[s ][s ][s ]:::-:::- P=Propulsion
30  6_:::-:::-# M8 #:::-:::-# M2 #:::-[24][26][28]:::-:::- F=Fuel
31  :::-:::-# S2 #:::-:::-# S0 #:::-[s ]/C8>/ C9 \:::-
32  8_!!!-!!!-/++++++\!!!-!!!-/++++++\!!!-[22]\F4/\ P4 /!!!- H=Habitation
33  :::-:::-[s ][s ][s ][s ][s ][s ][s ][s ]/C4>/ C5 \:::- L=Life Support
34 10_:::-:::-[30][20][18][16][14][10][ 6][ 4]\F2/\ P2 /:::- S=Solar Panels
35  :::-/======\/======\/======\/======\[s ][s ][s ]:::-:::-
36 12_!!!-# M10 ## M6 ## M4 ## M0 #[ 2][ 8][12]!!!-!!!-
37  :::-# L3 ## H2 ## L1 ## H0 #[s ]/C0\/ C1 \:::-
38 14_:::-\======/\======/\======/\======/[ 0]\F0/\ P0 /:::-
39  :::-/======\/======\/======\/======\[s ]/C2\/ C3 \:::-
40 16_!!!-# M9 ## M7 ## M3 ## M1 #[ 1]\F1/\ P1 /!!!-
41  :::-# H3 ## L2 ## H1 ## L0 #[s ][s ][s ]:::-:::-
42 18_:::-\======/\======/\======/\======/[ 3][ 9][13]:::-:::-
43  :::-:::-[s ][s ][s ][s ][s ][s ][s ][s ]/C6\/ C7 \:::-
44 20_!!!-!!!-[31][21][19][17][15][11][ 7][ 5]\F3/\ P3 /!!!-
45  :::-:::-\++++++/:::-:::-\++++++/:::-[s ]/C10/ C11 \:::-
46 22_:::-:::-# M11 #:::-:::-# M5 #:::-[23]\F5/\ P5 /:::-
47  :::-:::-# S3 #:::-:::-# S1 #:::-[s ][s ][s ]:::-:::-
48 24_!!!-!!!-/++++++\!!!-!!!-/++++++\!!!-[25][27][29]!!!-!!!-
49  :::-:::-:::-:::-:::-:::-:::-:::-:::-:::-/C14/ C15 \:::-
50 26_:::-:::-:::-:::-:::-:::-:::-:::-:::-:::-\F7/\ P7 /:::-
51  :::-:::-:::-:::-:::-:::-:::-:::-:::-:::-:::-:::-:::-:::-
52 28_!!!-!!!-!!!-!!!-!!!-!!!-!!!-!!!-!!!-!!!-!!!-!!!-!!!-!!!-
53 
54 Now, how things work:
55 
56 Modules and Components: player (if the client is smart enough)
57 can choose which sort of each to build, but not where they are
58 built. That is, first module built can be choice of H,L,S,
59 but whichever it is, it is H0, L0 or S0. If you build 4 F and
60 0 P, they will be F0,F1,F2,F3.
61 
62 Structural are different: the first s must be s0, but after that
63 you can in principle build any s which is adjacent (4 ways) to
64 another s (but in practice the client may make the choice for you).
65 Because you have to start with s0, this means each s actually
66 depends on one single other s, so we just note that required s
67 below, and don't have to calculate adjacency.
68 
69 Likewise, whether a component or module is "connected" to the
70 structure depends in each case on just a single structural.
71 (Actually, F2 and F3 are exceptions, which have a choice
72 of two (non-dependent) structs to depend on; we choose just
73 the one which must be there for P2 and P3).
74 
75 **********************************************************************/
76 
82 };
83 
84 #define NUM_SS_STRUCTURALS 32 // Used in the network protocol.
85 #define NUM_SS_COMPONENTS 16
86 #define NUM_SS_MODULES 12
87 
88 // Used in the network protocol.
89 BV_DEFINE(bv_spaceship_structure, NUM_SS_STRUCTURALS);
90 
92  // how many of each part built, including any "unplaced":
95  int modules;
96  // which structurals placed: (array of booleans)
97  bv_spaceship_structure structure;
98  // which components and modules placed: (may or may not be connected)
99  int fuel;
104  // other stuff:
105  enum spaceship_state state;
107  // derived quantities:
109  int mass;
110  double support_rate;
111  double energy_rate;
112  double success_rate;
113  double travel_time;
114 };
115 
117  int x, y; // position of tile centre
118  int required; // required for struct connection
119 };
120 
123 extern const struct sship_part_info modules_info[NUM_SS_MODULES];
124 
125 void spaceship_init(struct player_spaceship *ship);
126 int num_spaceship_structurals_placed(const struct player_spaceship *ship);
127 
130  int num;
131 };
132 
133 bool next_spaceship_component(struct player *pplayer,
134  struct player_spaceship *ship,
135  struct spaceship_component *fill);
spaceship_place_type
Definition: fc_types.h:1097
#define NUM_SS_MODULES
Definition: spaceship.h:86
int num_spaceship_structurals_placed(const struct player_spaceship *ship)
Count the number of structurals placed; that is, in ship->structure[].
Definition: spaceship.cpp:62
bool next_spaceship_component(struct player *pplayer, struct player_spaceship *ship, struct spaceship_component *fill)
Find (default) place for next spaceship component.
Definition: spaceship.cpp:79
#define NUM_SS_COMPONENTS
Definition: spaceship.h:85
void spaceship_init(struct player_spaceship *ship)
Initialize spaceship struct; could also be used to "cancel" a spaceship (eg, if/when capital-capture ...
Definition: spaceship.cpp:45
const struct sship_part_info structurals_info[NUM_SS_STRUCTURALS]
Definition: spaceship.cpp:18
const struct sship_part_info modules_info[NUM_SS_MODULES]
Definition: spaceship.cpp:36
BV_DEFINE(bv_spaceship_structure, NUM_SS_STRUCTURALS)
const struct sship_part_info components_info[NUM_SS_COMPONENTS]
Definition: spaceship.cpp:28
#define NUM_SS_STRUCTURALS
Definition: spaceship.h:84
spaceship_state
Definition: spaceship.h:77
@ SSHIP_ARRIVED
Definition: spaceship.h:81
@ SSHIP_STARTED
Definition: spaceship.h:79
@ SSHIP_LAUNCHED
Definition: spaceship.h:80
@ SSHIP_NONE
Definition: spaceship.h:78
double energy_rate
Definition: spaceship.h:111
bv_spaceship_structure structure
Definition: spaceship.h:97
double success_rate
Definition: spaceship.h:112
double support_rate
Definition: spaceship.h:110
double travel_time
Definition: spaceship.h:113
enum spaceship_state state
Definition: spaceship.h:105
Definition: player.h:231
enum spaceship_place_type type
Definition: spaceship.h:129