1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
/* Tenes Empanadas Graciela
*
* Copyright (C) 2000 Ricardo Quesada
*
* Author: Ricardo Calixto Quesada <rquesada@core-sdi.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; only version 2 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#include <filesystem>
#include <stdio.h>
#include <string.h>
#include "../common/net.h"
#include "fcintl.h"
#include "protocol.h"
#include "client.h"
namespace teg::client
{
static int aFichas[COUNTRIES_CANT]; /**< array de los countries */
static int aConts[CONT_CANT]; /**< array de los continentes */
static int fichas_tot; /**< cantidad de fichas que hay en el array */
static int wanted_tot; /**< cantidad de fichas pedidas para enviar */
static int wanted_conts; /**< continentes pedidos */
/**
* @fn static TEG_STATUS fichas_check()
* Dice si se esta en condiciones de hacer algo con fichas
*/
TEG_STATUS fichas_check()
{
PLAYER_STATUS e;
e = ESTADO_GET();
if(e==PLAYER_STATUS_FICHAS || e==PLAYER_STATUS_FICHAS2 || e==PLAYER_STATUS_FICHASC) {
return TEG_STATUS_SUCCESS;
} else {
return TEG_STATUS_ERROR;
}
}
TEG_STATUS fichas_add(PCOUNTRY p)
{
if(fichas_check() != TEG_STATUS_SUCCESS) {
textmsg(M_ERR, _("Error, you cant add armies now"));
return TEG_STATUS_UNEXPECTED;
}
if(p->numjug == WHOAMI()) {
if(fichas_tot < wanted_tot) {
fichas_tot++;
p->ejercitos++;
aFichas[p->id]++;
aConts[p->continente]++;
return TEG_STATUS_SUCCESS;
} else {
textmsg(M_ERR, _("Error, you cant put more than %d armies"), wanted_tot);
fichas_enter(p);
return TEG_STATUS_ERROR;
}
} else {
textmsg(M_ERR, _("Error, '%s' isnt one of your countries"), countries_get_name(p->id));
return TEG_STATUS_UNEXPECTED;
}
}
TEG_STATUS fichas_sub(PCOUNTRY p)
{
if(fichas_check() != TEG_STATUS_SUCCESS) {
textmsg(M_ERR, _("Error, you cant sub armies now"));
return TEG_STATUS_UNEXPECTED;
}
if(p->numjug == WHOAMI()) {
if(aFichas[p->id]) {
fichas_tot--;
p->ejercitos--;
aFichas[p->id]--;
aConts[p->continente]--;
fichas_enter(p);
return TEG_STATUS_SUCCESS;
} else {
return TEG_STATUS_UNEXPECTED;
}
} else {
textmsg(M_ERR, _("Error, '%s' isnt one of your countries"), countries_get_name(p->id));
return TEG_STATUS_UNEXPECTED;
}
}
TEG_STATUS fichas_finish(int **ptr)
{
int i, c;
if(fichas_check() != TEG_STATUS_SUCCESS) {
return TEG_STATUS_UNEXPECTED;
}
if(wanted_tot != fichas_tot) {
return TEG_STATUS_ERROR;
}
c = wanted_conts;
for(i=0; i<CONT_CANT; i++) {
if((c & 1) && (aConts[i] < g_conts[i].fichas_x_cont)) {
return TEG_STATUS_ERROR;
}
c >>= 1;
}
*ptr = aFichas;
return TEG_STATUS_SUCCESS;
}
void fichas_init(int cant, int conts)
{
int i;
for(i=0; i<COUNTRIES_CANT; i++) {
aFichas[i]=0;
}
for(i=0; i<CONT_CANT; i++) {
aConts[i]=0;
}
fichas_tot = 0;
wanted_tot = cant;
wanted_conts = conts;
}
void fichas_add_wanted(int i)
{
wanted_tot += i ;
}
void fichas_reset()
{
int i;
for(i=0; i<COUNTRIES_CANT; i++) {
if(aFichas[i]) {
g_countries[i].ejercitos -= aFichas[i];
aFichas[i] = 0;
}
}
for(i=0; i<CONT_CANT; i++) {
aConts[i] = 0;
}
fichas_tot = 0;
}
TEG_STATUS fichas_restore_from_error()
{
ESTADO_SET(PLAYER_STATUS_FICHAS);
fichas_reset();
aux_draw_all_countries();
callbacks::gui_sensi();
return TEG_STATUS_SUCCESS;
}
TEG_STATUS fichas2_restore_from_error()
{
ESTADO_SET(PLAYER_STATUS_FICHAS2);
fichas_reset();
aux_draw_all_countries();
callbacks::gui_sensi();
return TEG_STATUS_SUCCESS;
}
TEG_STATUS fichasc_restore_from_error()
{
ESTADO_SET(PLAYER_STATUS_FICHASC);
fichas_reset();
aux_draw_all_countries();
callbacks::gui_sensi();
return TEG_STATUS_SUCCESS;
}
TEG_STATUS fichas_out()
{
char buf[2000];
char tmp[100];
int *ptr;
int i;
int first_time;
PLAYER_STATUS e;
if(fichas_check() != TEG_STATUS_SUCCESS) {
textmsg(M_ERR, _("Error, its not the time to send armies"));
return TEG_STATUS_ERROR;
}
if(fichas_finish(&ptr) != TEG_STATUS_SUCCESS) {
fichas_reset();
textmsg(M_ERR, _("Error, put the correct number of armies"));
return TEG_STATUS_ERROR;
}
buf[0]=0;
tmp[0]=0;
first_time = 1;
for(i=0; i<COUNTRIES_CANT; i++) {
if(ptr[i]>0) {
if(first_time) {
sprintf(tmp, "%d:%d", i, ptr[i]);
} else {
sprintf(tmp, ",%d:%d", i, ptr[i]);
}
strcat(buf, tmp);
first_time = 0;
}
}
e = ESTADO_GET();
switch(e) {
case PLAYER_STATUS_FICHAS:
net_printf(g_game.fd, TOKEN_FICHAS"=%s\n", buf);
ESTADO_SET(PLAYER_STATUS_POSTFICHAS);
break;
case PLAYER_STATUS_FICHAS2:
net_printf(g_game.fd, TOKEN_FICHAS2"=%s\n", buf);
ESTADO_SET(PLAYER_STATUS_POSTFICHAS2);
break;
case PLAYER_STATUS_FICHASC:
net_printf(g_game.fd, TOKEN_FICHASC"=%s\n", buf);
ESTADO_SET(PLAYER_STATUS_POSTFICHASC);
break;
default:
textmsg(M_ERR, _("Error, its not the moment to send your armies"));
return TEG_STATUS_ERROR;
}
return TEG_STATUS_SUCCESS;
}
TEG_STATUS fichas_enter(PCOUNTRY p)
{
if(fichas_check() != TEG_STATUS_SUCCESS) {
return TEG_STATUS_ERROR;
}
if(p->numjug == WHOAMI()) {
if(fichas_tot >= wanted_tot) {
if(!(p->selected & COUNTRY_SELECT_FICHAS_OUT)) {
p->selected &= ~COUNTRY_SELECT_FICHAS_IN;
p->selected |= COUNTRY_SELECT_FICHAS_OUT;
callbacks::gui_country_select(p->id);
}
} else {
if(!(p->selected & COUNTRY_SELECT_FICHAS_IN)) {
p->selected &= ~COUNTRY_SELECT_FICHAS_OUT;
p->selected |= COUNTRY_SELECT_FICHAS_IN;
callbacks::gui_country_select(p->id);
}
}
}
return TEG_STATUS_SUCCESS;
}
TEG_STATUS fichas_leave(PCOUNTRY p)
{
if(fichas_check() != TEG_STATUS_SUCCESS) {
return TEG_STATUS_ERROR;
}
if(p->numjug == WHOAMI()) {
p->selected &= ~COUNTRY_SELECT_FICHAS_IN;
p->selected &= ~COUNTRY_SELECT_FICHAS_OUT;
callbacks::gui_country_select(p->id);
}
return TEG_STATUS_SUCCESS;
}
void fichas_get_wanted(int *cant, int *conts)
{
*cant = wanted_tot - cont_tot(wanted_conts);
*conts = wanted_conts;
}
}
|