Debian Codegraph @

engine/ui/button_checks.cpp

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name button_checks.cpp - The button checks. */
11 //
12 // (c) Copyright 1999-2006 by Lutz Sammer, Vladi Belperchinov-Shabanski
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; only version 2 of the License.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 // 02111-1307, USA.
27 //
28
29 //@{
30
31 /*----------------------------------------------------------------------------
32 -- Includes
33 ----------------------------------------------------------------------------*/
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include "stratagus.h"
40 #include "unittype.h"
41 #include "upgrade.h"
42 #include "interface.h"
43 #include "network.h"
44 #include "player.h"
45
46 /*----------------------------------------------------------------------------
47 -- Functions
48 ----------------------------------------------------------------------------*/
49
50 /**
51 ** ButtonCheck for button enabled, always true.
52 ** This needed to overwrite the internal tests.
53 **
54 ** @param unit Pointer to unit for button.
55 ** @param button Pointer to button to check/enable.
56 **
57 ** @return True if enabled.
58 */
59 bool ButtonCheckTrue(const CUnit *unit, const ButtonAction *button)
60 {
61 return true;
62 }
63
64 /**
65 ** Check for button enabled, always false.
66 ** This needed to overwrite the internal tests.
67 **
68 ** @param unit Pointer to unit for button.
69 ** @param button Pointer to button to check/enable.
70 **
71 ** @return True if enabled.
72 */
73 bool ButtonCheckFalse(const CUnit *unit, const ButtonAction *button)
74 {
75 return false;
76 }
77
78 /**
79 ** Check for button enabled, if any unit is available.
80 **
81 ** @param unit Pointer to unit for button.
82 ** @param button Pointer to button to check/enable.
83 **
84 ** @return True if enabled.
85 */
86 bool ButtonCheckUnitsOr(const CUnit *unit, const ButtonAction *button)
87 {
88 char *buf;
89 CPlayer *player;
90
91 player = unit->Player;
92 buf = new_strdup(button->AllowStr.c_str());
93 for (const char *s = strtok(buf, ","); s; s = strtok(NULL, ",")) {
94 if (player->HaveUnitTypeByIdent(s)) {
95 delete[] buf;
96 return true;
97 }
98 }
99 delete[] buf;
100 return false;
101 }
102
103 /**
104 ** Check for button enabled, if all units are available.
105 **
106 ** @param unit Pointer to unit for button.
107 ** @param button Pointer to button to check/enable.
108 **
109 ** @return True if enabled.
110 */
111 bool ButtonCheckUnitsAnd(const CUnit *unit, const ButtonAction *button)
112 {
113 char *buf;
114 CPlayer *player;
115
116 player = unit->Player;
117 buf = new_strdup(button->AllowStr.c_str());
118 for (const char *s = strtok(buf, ","); s; s = strtok(NULL, ",")) {
119 if (!player->HaveUnitTypeByIdent(s)) {
120 delete[] buf;
121 return false;
122 }
123 }
124 delete[] buf;
125 return true;
126 }
127
128 /**
129 ** Check if network play is enabled.
130 **
131 ** @param unit Pointer to unit for button.
132 ** @param button Pointer to button to check/enable.
133 **
134 ** @return True if enabled.
135 **
136 ** @note: this check could also be moved into intialisation.
137 */
138 bool ButtonCheckNetwork(const CUnit *unit, const ButtonAction *button)
139 {
140 return IsNetworkGame();
141 }
142
143 /**
144 ** Check if network play is disabled.
145 **
146 ** @param unit Pointer to unit for button.
147 ** @param button Pointer to button to check/enable.
148 **
149 ** @return True if disabled.
150 **
151 ** @note: this check could also be moved into intialisation.
152 */
153 bool ButtonCheckNoNetwork(const CUnit *unit, const ButtonAction *button)
154 {
155 return !IsNetworkGame();
156 }
157
158 /**
159 ** Check for button enabled, if the unit isn't working.
160 ** Working is training.
161 **
162 ** @param unit Pointer to unit for button.
163 ** @param button Pointer to button to check/enable.
164 **
165 ** @return True if enabled.
166 */
167 bool ButtonCheckNoWork(const CUnit *unit, const ButtonAction *button)
168 {
169 return unit->Orders[0]->Action != UnitActionTrain;
170 }
171
172 /**
173 ** Check if all requirements for an attack are met.
174 **
175 ** @param unit Pointer to unit for button.
176 ** @param button Pointer to button to check/enable.
177 **
178 ** @return True if enabled.
179 */
180 bool ButtonCheckAttack(const CUnit *unit, const ButtonAction *button)
181 {
182 return unit->Type->CanAttack;
183 }
184
185 //@}