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
|
/* 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.
*/
/**
* @file tarjeta.c
* funciones para manejar a las tarjetas
*/
#include "tarjeta.h"
#include <stdbool.h>
#include <stddef.h>
#include "country.h"
bool card_belongs_to_player(int player, int country)
{
return countrynumber_is_valid(country)
&& g_countries[country].tarjeta.numjug == player;
}
bool can_trade_cards(TARJTIPO a, TARJTIPO b, TARJTIPO c)
{
TARJTIPO const result = static_cast<TARJTIPO>(a | b | c);
return (result & TARJ_COMODIN) // at least one joker
|| (result == TARJ_GALEON)
|| (result == TARJ_CANION)
|| (result == TARJ_GLOBO)
|| (result == (TARJ_GALEON | TARJ_CANION | TARJ_GLOBO));
}
/**
* @fn BOOLEAN tarjeta_puedocanje( int numjug, int t1, int t2, int t3 )
* Dice si es correcto el canje con las tarjetas t1,t2 y t3
*/
bool tarjeta_puedocanje(int numjug, int t1, int t2, int t3)
{
/* chequear que las tarjetas sean del jugador */
if(!(card_belongs_to_player(numjug, t1)&&
card_belongs_to_player(numjug, t2) &&
card_belongs_to_player(numjug, t3))) {
return false;
}
return can_trade_cards(g_countries[t1].tarjeta.tarjeta,
g_countries[t2].tarjeta.tarjeta,
g_countries[t3].tarjeta.tarjeta);
}
void tarjeta_init(void)
{
}
/**
* @fn void tarjeta_usar( PTARJETA pT )
*/
void tarjeta_usar(PTARJETA pT)
{
pT->usada = true;
}
/**
* @fn void tarjeta_desusar( PTARJETA pT )
*/
void tarjeta_desusar(PTARJETA pT)
{
pT->usada = false;
}
/**
* @fn void tarjeta_inittarj( PTARJETA t )
*/
void tarjeta_inittarj(PTARJETA t)
{
t->usada = false;
t->numjug = -1;
}
/**
* @fn void tarjeta_poner( PTARJETA t )
*/
void tarjeta_poner(PTARJETA t)
{
tarjeta_inittarj(t);
}
/**
* @fn void tarjeta_sacar( PTARJETA t, int numjug )
*/
void tarjeta_sacar(PTARJETA t, int numjug)
{
t->numjug = numjug;
}
/**
* @fn int tarjeta_es_libre( int i )
* funcion auxiliar de token_tarjeta
* @param i Pais que contiene a la tarjeta
* @return TRUE si la tarjeta esta libre
*/
bool tarjeta_es_libre(int i)
{
return(g_countries[i].tarjeta.numjug == -1);
}
/**
* @fn BOOLEAN tarjeta_es_usada( PTARJETA pT )
*/
bool tarjeta_es_usada(PTARJETA pT)
{
return (pT->usada == true);
}
|