00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00030
00031
00032
00033
00034
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038
00039 #include "stratagus.h"
00040 #include "unittype.h"
00041 #include "upgrade.h"
00042 #include "interface.h"
00043 #include "network.h"
00044 #include "player.h"
00045
00046
00047
00048
00049
00059 bool ButtonCheckTrue(const CUnit *unit, const ButtonAction *button)
00060 {
00061 return true;
00062 }
00063
00073 bool ButtonCheckFalse(const CUnit *unit, const ButtonAction *button)
00074 {
00075 return false;
00076 }
00077
00086 bool ButtonCheckUnitsOr(const CUnit *unit, const ButtonAction *button)
00087 {
00088 char *buf;
00089 CPlayer *player;
00090
00091 player = unit->Player;
00092 buf = new_strdup(button->AllowStr.c_str());
00093 for (const char *s = strtok(buf, ","); s; s = strtok(NULL, ",")) {
00094 if (player->HaveUnitTypeByIdent(s)) {
00095 delete[] buf;
00096 return true;
00097 }
00098 }
00099 delete[] buf;
00100 return false;
00101 }
00102
00111 bool ButtonCheckUnitsAnd(const CUnit *unit, const ButtonAction *button)
00112 {
00113 char *buf;
00114 CPlayer *player;
00115
00116 player = unit->Player;
00117 buf = new_strdup(button->AllowStr.c_str());
00118 for (const char *s = strtok(buf, ","); s; s = strtok(NULL, ",")) {
00119 if (!player->HaveUnitTypeByIdent(s)) {
00120 delete[] buf;
00121 return false;
00122 }
00123 }
00124 delete[] buf;
00125 return true;
00126 }
00127
00138 bool ButtonCheckNetwork(const CUnit *unit, const ButtonAction *button)
00139 {
00140 return IsNetworkGame();
00141 }
00142
00153 bool ButtonCheckNoNetwork(const CUnit *unit, const ButtonAction *button)
00154 {
00155 return !IsNetworkGame();
00156 }
00157
00167 bool ButtonCheckNoWork(const CUnit *unit, const ButtonAction *button)
00168 {
00169 return unit->Orders[0]->Action != UnitActionTrain;
00170 }
00171
00180 bool ButtonCheckAttack(const CUnit *unit, const ButtonAction *button)
00181 {
00182 return unit->Type->CanAttack;
00183 }
00184