182 enum { |
182 enum { |
183 CMD_SERVER = 0x1, ///< the command can only be initiated by the server |
183 CMD_SERVER = 0x1, ///< the command can only be initiated by the server |
184 CMD_OFFLINE = 0x2, ///< the command cannot be executed in a multiplayer game; single-player only |
184 CMD_OFFLINE = 0x2, ///< the command cannot be executed in a multiplayer game; single-player only |
185 }; |
185 }; |
186 |
186 |
187 typedef int32 CommandProc(TileIndex tile, uint32 flags, uint32 p1, uint32 p2); |
187 typedef CommandCost CommandProc(TileIndex tile, uint32 flags, uint32 p1, uint32 p2); |
188 |
188 |
189 struct Command { |
189 struct Command { |
190 CommandProc *proc; |
190 CommandProc *proc; |
191 byte flags; |
191 byte flags; |
192 }; |
192 }; |
197 /** |
197 /** |
198 * Check the return value of a DoCommand*() function |
198 * Check the return value of a DoCommand*() function |
199 * @param res the resulting value from the command to be checked |
199 * @param res the resulting value from the command to be checked |
200 * @return Return true if the command failed, false otherwise |
200 * @return Return true if the command failed, false otherwise |
201 */ |
201 */ |
202 static inline bool CmdFailed(int32 res) |
202 static inline bool CmdFailed(CommandCost res) |
203 { |
203 { |
204 /* lower 16bits are the StringID of the possible error */ |
204 /* lower 16bits are the StringID of the possible error */ |
205 return res <= (CMD_ERROR | INVALID_STRING_ID); |
205 return res <= (CMD_ERROR | INVALID_STRING_ID); |
206 } |
206 } |
207 |
207 |
|
208 static inline bool CmdSucceeded(CommandCost res) { return !CmdFailed(res); } |
|
209 |
208 /* command.cpp */ |
210 /* command.cpp */ |
209 typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2); |
211 typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2); |
210 int32 DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc); |
212 CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc); |
211 bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd); |
213 bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd); |
212 |
214 |
213 #ifdef ENABLE_NETWORK |
215 #ifdef ENABLE_NETWORK |
214 |
216 |
215 void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback); |
217 void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback); |