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
|
/* 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.
*/
/* checks that the secret missions are accomplished */
#include <assert.h>
#include <string.h>
#include "server.h"
#include "missions.h"
namespace teg::server
{
TEG_STATUS mission_chequear(PSPLAYER pJ)
{
int i;
int countries[CONT_CANT];
assert(pJ);
if(pJ->mission == -1) {
if(mission_asignar(pJ) != TEG_STATUS_SUCCESS) {
return TEG_STATUS_ERROR;
}
}
memset(countries, 0, sizeof(countries));
player_listar_countries(pJ, countries);
/* 1st part. Check that the player has the correct number of countries */
if(g_game.cmission && pJ->mission != MISSION_CONQWORLD) {
if(pJ->tot_countries >= g_missions[MISSION_COMMON].tot_countries) {
pJ->mission = MISSION_COMMON;
goto gano;
}
};
/* 2da parte. Chequear countries por contienente */
for(i=0; i<CONT_CANT; i++) {
if(countries[i] < g_missions[pJ->mission].continents[i]) {
goto no_gano;
}
}
/* TODO: 3ra parte. Chequear si vencio a los otros playeres */
/* TODO: 4ta parte. Chequear si tiene los countries limitrofes que se piden */
if((i=g_missions[pJ->mission].frontiering_countries)) {
int j, k, i_tmp;
int salir=0;
for(j=0; j<COUNTRIES_CANT && salir==0; j++) {
if(g_countries[j].numjug != pJ->numjug) {
continue;
}
i_tmp=0;
for(k=0; k<COUNTRIES_CANT; k++) {
if(g_countries[k].numjug != pJ->numjug) {
continue;
}
if(countries_eslimitrofe(j, k)) {
if(++i_tmp >= i) {
/* mission cumplido, salir */
salir=1;
break;
}
}
}
}
if(j>=COUNTRIES_CANT) {
goto no_gano;
}
}
/* tiene todo, entonces gano! */
gano:
return TEG_STATUS_GAMEOVER;
no_gano:
return TEG_STATUS_ERROR;
}
TEG_STATUS mission_asignar(PSPLAYER pJ)
{
int i, obj;
assert(pJ);
/* tiene ya un mission asignado ? */
if(pJ->mission != -1) {
return TEG_STATUS_SUCCESS;
}
/* Si se juega sin missions, es a conquistar el mundo */
if(!g_game.mission) {
pJ->mission = MISSION_CONQWORLD; /* mission de conquistar al mundo */
return TEG_STATUS_SUCCESS;
}
obj = random_between(0, missions_cant()-1);
i = obj;
for(; i < missions_cant() ; i++) {
if(g_missions[i].player_number == -1) {
g_missions[i].player_number = pJ->numjug;
pJ->mission = i;
return TEG_STATUS_SUCCESS;
}
}
for(i=0; i < obj ; i++) {
if(g_missions[i].player_number == -1) {
g_missions[i].player_number = pJ->numjug;
pJ->mission = i;
return TEG_STATUS_SUCCESS;
}
}
return TEG_STATUS_ERROR;
}
void mission_init()
{
int i;
for(i=0; i<missions_cant(); i++) {
g_missions[i].player_number = -1;
}
g_missions[MISSION_CONQWORLD].player_number = 0;
g_missions[MISSION_COMMON].player_number = 0;
}
TEG_STATUS mission_set(bool a)
{
if(JUEGO_EMPEZADO) {
return TEG_STATUS_ERROR;
}
if(a!=0) {
a=1;
}
g_game.mission = a;
return TEG_STATUS_SUCCESS;
}
TEG_STATUS mission_common_mission(bool a)
{
if(JUEGO_EMPEZADO) {
return TEG_STATUS_ERROR;
}
if(a!=0) {
a=1;
}
g_game.cmission= a;
return TEG_STATUS_SUCCESS;
}
}
|