/** ****************************************************************************** @file /common/rm/rmmap.cpp @brief RM pristupujici k mapam @author Vta @version 1.0 ******************************************************************************/ #include "common/rm/rmmap.h" #include "world/init.h" #include "common/compatibility.h" #ifdef WIN32 #include #include // mkdir #endif #ifndef WIN32 #include #include #include #include #endif using namespace World; namespace rm { void TRM_map::loadData(int id) { this->loadMap(id); } int TRM_map::idOfLoadedMap() { return this->idofmap; } int TRM_map::isMapLoaded() { // this->lock(); // this->unlock(); if (this->maploaded==1) return 1; else return 0; } void TRM_map::checkExistingOwner(int ownerid,int mapid) { // overeni, ze vlastnik je i hracem v mape if (ownerid>0) // tzn. neni to neutralni { TMapInfo * minfo=NULL; if ( (this->mapsinfo[1]!=NULL) && ((*this->mapsinfo[1])[mapid]!=NULL) ) { minfo=(*(this->mapsinfo[1]))[mapid]; } else { if ( (this->mapsinfo[0]!=NULL) && ((*this->mapsinfo[0])[mapid]!=NULL) ) { minfo=(*(this->mapsinfo[0]))[mapid]; } else { GLOBALLOGID(PRIORITY_FATAL,"RMmap Map %i is corrupted - non-existing owner %i",mapid,ownerid); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } // problem bud je owner spatne cislo, nebo tam takovy hrac neni, nebo neni zaznam o takove mape - to posledni by nastat nemelo if ( (ownerid>MAX_PLAYERS) || (minfo==NULL) || (minfo->roles[ownerid]==NULL)) { GLOBALLOGID(PRIORITY_FATAL,"RMmap Map %i is corrupted - non-existing owner %i",mapid,ownerid); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } else { if (ownerid!=0) // pak muze byt jen neutralni - tj. 0 { GLOBALLOGID(PRIORITY_FATAL,"RMmap Map %i is corrupted - non-existing owner %i",mapid,ownerid); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } } int TRM_map::existsOwner(int ownerid,int mapid) { // overeni, ze vlastnik je i hracem v mape if (ownerid>0) // tzn. neni to neutralni { TMapInfo * minfo=NULL; if ( (this->mapsinfo[1]!=NULL) && ((*this->mapsinfo[1])[mapid]!=NULL) ) { minfo=(*(this->mapsinfo[1]))[mapid]; } else { if ( (this->mapsinfo[0]!=NULL) && ((*this->mapsinfo[0])[mapid]!=NULL) ) { minfo=(*(this->mapsinfo[0]))[mapid]; } else { return 0; } } // problem bud je owner spatne cislo, nebo tam takovy hrac neni, nebo neni zaznam o takove mape - to posledni by nastat nemelo if ( (ownerid>MAX_PLAYERS) || (minfo==NULL) || (minfo->roles[ownerid]==NULL)) { return 0; } } else { if (ownerid!=0) // pak muze byt jen neutralni - tj. 0 { return 0; } } return 1; } void TRM_map::loadMap(char * filename,int maptype) { this->loadMapsInfo(maptype,0); int i,j; for (i=this->mapsinfo[maptype]->getNext(-1);i!=-1;i=this->mapsinfo[maptype]->getNext(i)) { j=strcmp((*this->mapsinfo[maptype])[i]->file,filename); if (j==0) { this->loadMap(i); break; } } } /// pomocna promenna static char bu_path2[K8_MAX_PATH_LEN]; void TRM_map::loadMap(int id) { this->lock(); TMapInfo * minfo=NULL; if (this->mapsinfo[MAP_TYPE_SAVE_GAME]!=NULL) // zkusim nejdriv savy { if ((*this->mapsinfo[MAP_TYPE_SAVE_GAME])[id]!=NULL) { minfo=(*this->mapsinfo[MAP_TYPE_SAVE_GAME])[id]; if (minfo==NULL) { GLOBALLOGID(PRIORITY_FATAL,"RMMap can not load non-existing map id %i",id); THROW(E_8K_RM,"RMMap can not load non-existing map"); } #ifdef WIN32 strpartpath(bu_path2,"","","",SAVEGAME_DIR,K8_MAX_PATH_LEN,minfo->file); #else snprintf(bu_path2, K8_MAX_PATH_LEN,"%s/.8Kingdoms/savegame/%s", getenv("HOME"), minfo->file); #endif } } if (minfo==NULL) // tj. neni to v Savegame { if (this->mapsinfo[MAP_TYPE_NEW_GAME]!=NULL) // podivam se tedy do novych map { if ((*this->mapsinfo[MAP_TYPE_NEW_GAME])[id]!=NULL) { minfo=(*this->mapsinfo[MAP_TYPE_NEW_GAME])[id]; if (minfo==NULL) { GLOBALLOGID(PRIORITY_FATAL,"RMMap can not load non-existing map id %i",id); THROW(E_8K_RM,"RMMap can not load non-existing map"); } strpartpath(bu_path2,RESOURCES_DIR,"",this->rmconfi->getPack(),MAPS_DIR,K8_MAX_PATH_LEN,minfo->file); } } } if (minfo!=NULL) { this->maploaded=0; // odstranim puvodni mapu this->freeMap(); // mapu nactu xml TXMLdata map; DA * buildings_in_map; // kontrola, ze vsechny jednotky se nachazi v mape DA * units_in_map; // kontrola, ze vsechny jednotky se nachazi v mape int retvalue=map.readFile(bu_path2); // char ttt[10000]; // map.toXML(ttt,10000); // printf(ttt); // printf(minfo->file); if (retvalue!=XML_ERROR_OK) { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMMap can not load the file of the map having id %i: %s",id,minfo->file); THROW(E_8K_RM,"RMMap can not load the file of a map"); } // NACTENI JEDNOTEK int unitsInMapMin=map.getMinId("units",0,"unit",0,NULL); int unitsInMapMax=map.getMaxId("units",0,"unit",0,NULL); int unitsInMap=map.getNumId("units",0,"unit",0,NULL); DA ids; map.getListOfIds(&ids,"units",0,NULL); int bonusesAtUnit; // pocet bonusu dane jednotky if (unitsInMap==-1) // tj. zadne jednotky unitsInMap=0; int j; if (unitsInMap!=0) { this->lunits=new(DA)(unitsInMapMax-unitsInMapMin+1,unitsInMapMin,1); units_in_map=new(DA)(unitsInMapMax-unitsInMapMin+1,unitsInMapMin,1); } else { this->lunits=new(DA)(20,1,1); units_in_map=new(DA)(20,1,1); } int i,k; int temp; // RMuniti na nacitani jednotek TRM_advxml_i * RMuniti=(TRM_advxml_i *)KSendMessage(RQUEUE,MSG_GET_RM_UNIT_I,MOD_RM,MOD_RM,NULL); int wounds; for (i=ids.getNext(-1);i!=-1;i=ids.getNext(i)) { // Unikatni id jednotky ve hre - povinne j=i; (*this->lunits)[j]=(LIVING_UNIT *) KMemAlloc(sizeof(LIVING_UNIT)); // inicializace implicitnimi (nulovymi) hodnotami LIVING_UNIT_Init((*this->lunits)[j]); // Vlastni jmeno jednotky if ((map.getData((*this->lunits)[j]->name,MAX_STRLEN,"units",0,"unit",i,"name",0,NULL)) == XML_ERROR_NO_SUCH_A_PATH) { (*this->lunits)[j]->name[0]=0; } (*this->lunits)[j]->name[MAX_STRLEN-1]=0; // Druh - id v RM - povinne if (((*this->lunits)[j]->type=map.getDataInt("units",0,"unit",i,"type",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about unit %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } // RMuniti->requestDep((*this->lunits)[j]->type); // Hrac ktery ji vlastni - povinne if (((*this->lunits)[j]->player=map.getDataInt("units",0,"unit",i,"player",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about unit %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } this->checkExistingOwner((*this->lunits)[j]->player,id); // overeni, ze takovy hrac existuje // Body pohybu if ((temp=map.getDataInt("units",0,"unit",i,"movement",0,NULL)) >=0 ) { (*this->lunits)[j]->points_of_movement=temp; } // Stav jednotky if ((temp=map.getDataInt("units",0,"unit",i,"state",0,NULL)) <0 ) { (*this->lunits)[j]->state=US_IDLE; // GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about unit %i",id,i); // THROW(E_8K_RM,"RMmap Requested map is corrupted"); } else { switch (temp) { case US_IDLE: case US_BUILDING: case US_HAS_STARTED_BUILDING: case US_HAS_MOVED: case US_HAS_FOUGHT: case US_HAS_FOUGHT_AND_MOVED: case US_EXHAUSTED: { (*this->lunits)[j]->state=(UNIT_STATE)temp; } break; default: { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about unit %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } } // Zivoty - povinne if (((*this->lunits)[j]->lives=map.getDataInt("units",0,"unit",i,"lives",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about unit %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } // Zraneni for (wounds=1;wounds<=MAX_LIVES;wounds++) { if ((temp=map.getDataInt("units",0,"unit",i,"wounds",0,"man",wounds,NULL)) >=0 ) { (*this->lunits)[j]->wounds[wounds-1]=temp; } } // Uroven - povinne if (((*this->lunits)[j]->level=map.getDataInt("units",0,"unit",i,"level",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about unit %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } // Zkusenosti - povinne if (((*this->lunits)[j]->experience=map.getDataInt("units",0,"unit",i,"experiences",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about unit %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } // Pocet utoku v tomto kole if ((temp=map.getDataInt("units",0,"unit",i,"assaults_count",0,NULL)) >=0 ) { (*this->lunits)[j]->assaults_count=temp; } // Bonusy nepovinne bonusesAtUnit=map.getNumId("units",0,"unit",i,"bonuses",0,"bonus",0,NULL); // map.getListOfIds(ids, "units",0,"unit",i,"bonuses",0,"bonus",0,NULL); if (bonusesAtUnit>0) { (*this->lunits)[j]->bonuses.length=bonusesAtUnit; (*this->lunits)[j]->bonuses.data=(UNIT_PROPERTY_BONUS_ID*)KMemAlloc(sizeof(UNIT_PROPERTY_BONUS_ID)*bonusesAtUnit); for (k=1;k<=bonusesAtUnit;k++) { // Prirazeni vsech bonusu, pokud uz nejake jednotka ma if (((*this->lunits)[j]->bonuses.data[k-1]=map.getDataInt("units",0,"unit",i,"bonuses",0,"bonus",k,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about unit %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } } else { (*this->lunits)[j]->bonuses.length=0; (*this->lunits)[j]->bonuses.data=NULL; } // Orientace if(( ((*this->lunits)[j]->orientation=map.getDataInt("units",0,"unit",i,"orientation",0,NULL)) <0 ) ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about unit %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } delete(RMuniti); // NACTENI BUDOV DA ids2; map.getListOfIds(&ids2,"buildings",0,NULL); int buildingsInMap=map.getNumId("buildings",0,"building",0,NULL); int buildingsInMapMin=map.getMinId("buildings",0,"building",0,NULL); int buildingsInMapMax=map.getMaxId("buildings",0,"building",0,NULL); if (buildingsInMap==-1) // tj. zadne budovy { this->lbuildings=new(DA)(20,1); buildings_in_map=new(DA)(20,1); } else { this->lbuildings=new(DA)(buildingsInMapMax-buildingsInMapMin+1,buildingsInMapMin,1); buildings_in_map=new(DA)(buildingsInMapMax-buildingsInMapMin+1,buildingsInMapMin,1); } // RMuniti na nacitani jednotek TRM_building_i * RMbuildingi=(TRM_building_i *)KSendMessage(RQUEUE,MSG_GET_RM_BUILDING_I,MOD_RM,MOD_RM,NULL); for (i=ids2.getNext(-1);i!=-1;i=ids2.getNext(i)) { // Unikatni id budovy ve hre - povinne j=i; (*this->lbuildings)[j]=(LIVING_BUILDING *) KMemAlloc(sizeof(LIVING_BUILDING)); LIVING_BUILDING_Init((*this->lbuildings)[j]); // id v RM - povinne if (((*this->lbuildings)[j]->type=map.getDataInt("buildings",0,"building",i,"type",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about building %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } // RMbuildingi->requestDep((*this->lbuildings)[j]->type); // Vlastni jmeno budovy if ((map.getData((*this->lbuildings)[j]->name,MAX_STRLEN,"buildings",0,"building",i,"name",0,NULL)) == XML_ERROR_NO_SUCH_A_PATH) { (*this->lbuildings)[j]->name[0]=0; } (*this->lbuildings)[j]->name[MAX_STRLEN]=0; // Zivoty - povinne if (((*this->lbuildings)[j]->lives=map.getDataInt("buildings",0,"building",i,"lives",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about building %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } // Hrac ktery ji vlastni - povinne if (((*this->lbuildings)[j]->player=map.getDataInt("buildings",0,"building",i,"player",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about building %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } this->checkExistingOwner((*this->lbuildings)[j]->player,id); // overeni, ze takovy hrac existuje /* zruseno 5.2.2006 PW // Vyrabena jednotka if ((temp=map.getDataInt("buildings",0,"building",i,"producing",0,NULL)) >=0 ) { (*this->lbuildings)[j]->producing=temp; } */ /* zruseno 5.2.2006 PW // Doba vyrabene jednotky if ((temp=map.getDataInt("buildings",0,"building",i,"duration",0,NULL)) >=0 ) { (*this->lbuildings)[j]->production_duration=temp; } */ // Doba stavby (u rozestavene budovy) if ((temp=map.getDataInt("buildings",0,"building",i,"constructionDuration",0,NULL)) >=0 ) { (*this->lbuildings)[j]->construction_duration=temp; } // Orientace if (((*this->lbuildings)[j]->orientation=map.getDataInt("buildings",0,"building",i,"orientation",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about building %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } delete(RMbuildingi); // NACTENI INFORMACI O AKTUALNIM STAVU MAPY this->current_state=(TStateInfo*)KMemAlloc(sizeof(TStateInfo)*1); if ((this->current_state->turn_id=map.getDataInt("currentState",0,"turn",0,NULL)) < 0) { this->current_state->turn_id=0; // GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about current state %i",id); // THROW(E_8K_RM,"RMmap Requested map is corrupted"); } if ((this->current_state->duration=map.getDataInt("currentState",0,"duration",0,NULL)) < 0) { this->current_state->duration=0; // GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about current state %i",id); // THROW(E_8K_RM,"RMmap Requested map is corrupted"); } if ((this->current_state->player_on_turn=map.getDataInt("currentState",0,"onTurn",0,NULL)) == XML_ERROR_NO_SUCH_A_PATH) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about current state %i",id); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } this->checkExistingOwner(this->current_state->player_on_turn,id); // overeni, ze takovy hrac existuje if ((i=map.getDataInt("currentState",0,"weather",0,NULL)) == XML_ERROR_NO_SUCH_A_PATH) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about current state %i",id); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } switch (i) { case WS_SUNNY: case WS_RAIN: case WS_SNOW: { this->current_state->weather=(WEATHER_STATE)i; } break; default: { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about current state %i",id); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } break; } // NACTENI INFORMACI O KRALOVSTVI DA ids4; map.getListOfIds(&ids4,"kingdoms",0,NULL); this->kingdoms=(TKingdomInfo**) KMemAlloc(sizeof(TKingdomInfo*)*(1+MAX_KINGDOMS)); for (i=0;i<=MAX_KINGDOMS;i++) this->kingdoms[i]=NULL; // for (i=0;i<=MAX_KINGDOMS;i++) for (i=ids4.getNext(-1);i!=-1;i=ids4.getNext(i)) { if (i>MAX_KINGDOMS) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the kingdom %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } // role vlastnici kralovstvi if ((j=map.getDataInt("kingdoms",0,"kingdom",i,"role",0,NULL)) != XML_ERROR_NO_SUCH_A_PATH) { this->checkExistingOwner(j,id); // overeni, ze takovy hrac existuje this->kingdoms[i]=(TKingdomInfo *) KMemAlloc(sizeof(TKingdomInfo)); this->kingdoms[i]->roleid=j; this->kingdoms[i]->id=i; this->checkExistingOwner(this->kingdoms[i]->roleid,id); if ((this->kingdoms[i]->centerx=map.getDataInt("kingdoms",0,"kingdom",i,"centerx",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the kingdom %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } if ((this->kingdoms[i]->centery=map.getDataInt("kingdoms",0,"kingdom",i,"centery",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the kingdom %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } else { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the kingdom %i - the owner is missing",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } // NACTENI INFORMACI O MESTECH DA ids5; map.getListOfIds(&ids5,"cities",0,NULL); int citiesInMap=map.getNumId("cities",0,"city",0,NULL); int citiesInMapMin=map.getMinId("cities",0,"city",0,NULL); int citiesInMapMax=map.getMaxId("cities",0,"city",0,NULL); if (citiesInMap==-1) // tj. zadne budovy this->cities=new(DA)(1,1); else this->cities=new(DA)(citiesInMapMax-citiesInMapMin+1,1,1); for (i=ids5.getNext(-1);i!=-1;i=ids5.getNext(i)) { (*this->cities)[i]=(TCityInfo*)KMemAlloc(sizeof(TCityInfo)); map.getData((*this->cities)[i]->name,K8_MAX_NAME_LEN,"cities",0,"city",i,"name",0,NULL); if (((*this->cities)[i]->citysize=map.getDataInt("cities",0,"city",i,"citysize",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the town %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } //spatny rozmer mesta if ( ( (*this->cities)[i]->citysize<1) || ( (*this->cities)[i]->citysize>(MAX_CITY_SIZE) ) ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the town %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } for (j=0;j<(*this->cities)[i]->citysize;j++) { if (((*this->cities)[i]->position[j]=map.getDataInt("cities",0,"city",i,"position",j+1,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the town %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } // vlastnik mesta if (((*this->cities)[i]->owner=map.getDataInt("cities",0,"city",i,"owner",0,NULL)) <0 ) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the town %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } this->checkExistingOwner((*this->cities)[i]->owner,id); } int mapsize=map.getDataInt("header",0,"sizex",0,NULL)*map.getDataInt("header",0,"sizey",0,NULL); // NACTENI HEXU this->histhexs=(HISTORY_HEX ***) KMemAlloc(sizeof(HISTORY_HEX**)*(MAX_KINGDOMS+1)); for (i=0;i<=MAX_KINGDOMS;i++) { if (this->existsOwner(i,id)==1) { this->histhexs[i]=(HISTORY_HEX **) KMemAlloc(sizeof(HISTORY_HEX*)*mapsize); } else { this->histhexs[i]=NULL; } } this->hexs=(HEX**) KMemAlloc(sizeof(HEX*)*mapsize); this->hexnum=mapsize; int occurrenceInHex; int found; TCityInfo * cinfo; DA ids6; for (i=1;i<=mapsize;i++) { // printf("%i ", i); this->hexs[i-1]=(HEX*) KMemAlloc(sizeof(HEX)); HEX_Init(this->hexs[i - 1]); // Teren - povinny if ( (temp=map.getDataInt("map",0,"hex",i,"terrain",0,NULL))==-1) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the hex %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } else { switch (temp) { case TT_PLAIN: // plan { this->hexs[i-1]->terrain=TT_PLAIN; } break; case TT_FOREST: // les { this->hexs[i-1]->terrain=TT_FOREST; } break; case TT_DEEP_FOREST: // hvozd { this->hexs[i-1]->terrain=TT_DEEP_FOREST; } break; case TT_ROCKS: // skaly { this->hexs[i-1]->terrain=TT_ROCKS; } break; case TT_SWAMP: // bazina { this->hexs[i-1]->terrain=TT_SWAMP; } break; case TT_RIVER: // reka { this->hexs[i-1]->terrain=TT_RIVER; } break; case TT_SHALLOW : // brod { this->hexs[i-1]->terrain=TT_SHALLOW; } break; case TT_SEA: // more { this->hexs[i-1]->terrain=TT_SEA; } break; case TT_TOWN: // mesto { this->hexs[i-1]->terrain=TT_TOWN; found=0; for (j=this->cities->getNext(-1);j!=-1;j=this->cities->getNext(j)) { cinfo = (*this->cities)[j]; for (k=0;kcitysize;k++) { if (cinfo->position[k]==(i-1)) { found=1; break; } } } if (found==0) // k mestu na danem hexu neni zaznam { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the hex %i - there should not be any city on this hex",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } break; default: { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the hex %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } break; } } // Vyska - povinna if ( (temp=map.getDataInt("map",0,"hex",i,"elevation",0,NULL)) == XML_ERROR_NO_SUCH_A_PATH) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the hex %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } else { switch (temp) { case ET_LEVEL0: { this->hexs[i-1]->elevation=ET_LEVEL0; } break; case ET_LEVEL1: { this->hexs[i-1]->elevation=ET_LEVEL1; } break; case ET_LEVEL2: { this->hexs[i-1]->elevation=ET_LEVEL2; } break; case ET_LEVEL3: { this->hexs[i-1]->elevation=ET_LEVEL3; } break; case ET_LEVEL4: { this->hexs[i-1]->elevation=ET_LEVEL4; } break; default: { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the hex %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } break; } } for (k=0;k<=MAX_PLAYERS;k++) { ids6[k]=0; } map.getListOfIds(&ids6,"map",0,"hex",i,"history",0,NULL); for (k=0;k<=MAX_PLAYERS;k++) { if (ids6[k]==1) { if (this->histhexs[k]==NULL) // historie hexu pro hrace, ktery neni ve hre { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the history of the hex %i - non-existing role",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } this->histhexs[k][i-1]=(HISTORY_HEX *) KMemAlloc(sizeof(HISTORY_HEX)*1); if ( (this->histhexs[k][i-1]->turn_id=map.getDataInt("map",0,"hex",i,"history",0,"role",k,"round",0,NULL)) <0) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the history of the hex %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } if ( (this->histhexs[k][i-1]->building=map.getDataInt("map",0,"hex",i,"history",0,"role",k,"building_type",0,NULL)) <0) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the history of the hex %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } else { if (this->histhexs[k]!=NULL) // takova role existuje this->histhexs[k][i-1]=NULL; // pak to jeste nevidel } } // Vyskyty specialnich jednotek occurrenceInHex=map.getMaxId("map",0,"hex",i,"occurrences",0,"occurrence",0,NULL); if (occurrenceInHex>0) { this->hexs[i-1]->unit_occurrence.length=occurrenceInHex; this->hexs[i-1]->unit_occurrence.data=(UNIT_TYPE_ID*)KMemAlloc(sizeof(UNIT_TYPE_ID)*(occurrenceInHex)); for (k=0;khexs[i-1]->unit_occurrence.data[k]=map.getDataInt("map",0,"hex",i,"occurrences",0,"occurrence",k+1,NULL)) == XML_ERROR_NO_SUCH_A_PATH) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the hex %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } } else { this->hexs[i-1]->unit_occurrence.length=0; this->hexs[i-1]->unit_occurrence.data=NULL; } // Jednotka na hexu if ( (temp=map.getDataInt("map",0,"hex",i,"unit",0,NULL)) <=0) { // zjistim si id ktere jsem ji priradil pri ukladani this->hexs[i-1]->unit=0; // zadna jednotka tam neni } else { this->hexs[i-1]->unit=temp; if ((*this->lunits)[this->hexs[i-1]->unit]==NULL) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the hex %i - non-exiting unit",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } (*units_in_map)[temp]=1; } // Budova na hexu if ( (temp=map.getDataInt("map",0,"hex",i,"building",0,NULL)) <=0) { // zjistim si id ktere jsem ji priradil pri ukladani this->hexs[i-1]->building=0; // zadna jednotka tam neni } else { this->hexs[i-1]->building=temp; if ((*this->lbuildings)[this->hexs[i-1]->building]==NULL) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the hex %i - non-existing building",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } (*buildings_in_map)[temp]=1; } // Vlastnik hexu /* Odstraneni polozky HEX::player 21.2.2006 PW if ( (temp=map.getDataInt("map",0,"hex",i,"owner",0,NULL)) == XML_ERROR_NO_SUCH_A_PATH) { this->hexs[i-1]->player=0; } else { this->hexs[i-1]->player=temp; this->checkExistingOwner(this->hexs[i-1]->player,id); } */ // Kralovstvi hexu if ( (this->hexs[i-1]->kingdom=map.getDataInt("map",0,"hex",i,"kingdom",0,NULL)) <=0) { this->hexs[i-1]->kingdom=0; // je to nici uzemi } if (this->hexs[i-1]->kingdom!=0) { if ( (this->hexs[i-1]->kingdom>0) && (this->hexs[i-1]->kingdom<(MAX_KINGDOMS+1)) ) { if (this->kingdoms[this->hexs[i-1]->kingdom]==NULL) { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the hex %i - non-existing kingdom %i",id,i,this->hexs[i-1]->kingdom); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } else { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is corrupted record about the hex %i - non-existing kingdom %i",id,i,this->hexs[i-1]->kingdom); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } } // NACTENI AI this->aiplan=(TAIPlan*)KMemAlloc (sizeof(TAIPlan)*1); for (i=0;i<=MAX_PLAYERS;i++) { if ( (j=map.getData(NULL,0,"map",0,"ai",0,"plan",i,NULL)) >=0 ) { this->aiplan->plan[i]=(char*)KMemAlloc(sizeof(char)*j)+1; map.getData(this->aiplan->plan[i],j,"map",0,"ai",0,"plan",i,NULL); } else { this->aiplan->plan[i]=NULL; } } for (i=this->lunits->getNext(-1);i!=-1;i=this->lunits->getNext(i)) { if ((*units_in_map)[i]==0) // prebytecna jednotka v souboru, ktera neni umistena v mape { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is unplaced unit id %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } for (i=this->lbuildings->getNext(-1);i!=-1;i=this->lbuildings->getNext(i)) { if ((*buildings_in_map)[i]==0) // prebytecna jednotka v souboru, ktera neni umistena v mape { GLOBALLOGID(PRIORITY_FATAL,"RMmap In map %i there is unplaced building id %i",id,i); THROW(E_8K_RM,"RMmap Requested map is corrupted"); } } this->idofmap=id; this->maploaded=1; delete (units_in_map); delete (buildings_in_map); } else // (id<=this->mapsinfo[maptype]->getMaxId()) { GLOBALLOGID(PRIORITY_FATAL,"RMmap Non-existing map having id %i",id); THROW(E_8K_RM,"RMmap Non-existing map"); } this->unlock(); } int TRM_map::getMapsMaxId(int maptype) { this->lock(); int i=-1; if (maptypemapsinfo[maptype]!=NULL) i=this->mapsinfo[maptype]->getMaxId(); this->unlock(); return i; } int TRM_map::getMapsCount(int maptype) { this->lock(); int i; int count=0; for (i=this->mapsinfo[maptype]->getNext(-1);i!=-1;i=this->mapsinfo[maptype]->getNext(i)) { if ((*this->mapsinfo[maptype])[i]!=NULL) count++; } this->unlock(); return count; } void TRM_map::getMapsInfo(DA ** info,int maptype) { this->lock(); if ((maptype>=0) && (maptypemapsinfo[maptype]; else (*info)=NULL; this->unlock(); } void TRM_map::getMapInfo(TMapInfo ** map,int id) { this->lock(); if (id>=0) { if ((this->mapsinfo[0]!=NULL) || (this->mapsinfo[1]!=NULL)) // pokud alespon jedno pole existuje { if ((this->mapsinfo[1]!=NULL) && (*this->mapsinfo[1])[id]!=NULL) (*map)=(*this->mapsinfo[1])[id]; else if ((this->mapsinfo[0]!=NULL) && (*this->mapsinfo[0])[id]!=NULL) (*map)=(*this->mapsinfo[0])[id]; else (*map)=NULL; // aby si zbytecne nebral NULL z tempu DA<> } } else { (*map)=NULL; } this->unlock(); } void TRM_map::setKingdoms(TKingdomInfo ** kingdoms) { this->lock(); if (this->kingdoms==NULL) { this->kingdoms=kingdoms; } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap Can not return record about kingdoms"); THROW(E_8K_RM,"RMmap Can not return record about kingdoms"); } this->unlock(); } void TRM_map::getKingdoms(TKingdomInfo *** kingdoms) { this->lock(); if (kingdoms!=NULL) (*kingdoms)=this->kingdoms; this->kingdoms=NULL; this->unlock(); } void TRM_map::setCurrentState(TStateInfo * state) { this->lock(); if (this->current_state==NULL) { this->current_state=state; } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap Can not return record about current state"); THROW(E_8K_RM,"RMmap Can not return record about current state"); } this->unlock(); } void TRM_map::getCurrentState(TStateInfo ** state) { this->lock(); if (state!=NULL) (*state)=this->current_state; this->current_state=NULL; this->unlock(); } void TRM_map::setHistoryHexes(HISTORY_HEX *** hmap) { this->lock(); if (this->histhexs==NULL) { this->histhexs=hmap; } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap Can not return record about history hexes"); THROW(E_8K_RM,"RMmap Can not return record about history hexes"); } this->unlock(); } void TRM_map::setAIPlan(TAIPlan * plan) { this->lock(); if (this->aiplan==NULL) { this->aiplan=plan; } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap Can not return record about AI plan"); THROW(E_8K_RM,"RMmap Can not return record about AI plan"); } this->unlock(); } void TRM_map::getAIPlan(TAIPlan ** plan) { this->lock(); if (plan!=NULL) (*plan)=this->aiplan; this->aiplan=NULL; this->unlock(); } void TRM_map::getHistoryHexes(HISTORY_HEX **** hmap) { this->lock(); if (hmap!=NULL) (*hmap)=this->histhexs; this->histhexs=NULL; this->unlock(); } World::HEX * TRM_map::getHex(int id) { this->lock(); HEX * hex = this->hexs[id]; this->unlock(); return hex; } int TRM_map::getHexes(World::HEX *** map) { this->lock(); if (map!=NULL) (*map) = this->hexs; GLOBALLOGID(PRIORITY_DATA_WERE_TAKEN, "RMmap GET Hexes()"); int ret=this->hexnum; this->hexs=NULL; // odstarnim z pamatovani this->unlock(); return ret; } void TRM_map::setHexes(World::HEX ** map) { this->lock(); this->hexs=map; // zas zapamatuji GLOBALLOGID(PRIORITY_DATA_WERE_RETURNED, "RMmap SET Hexes()"); // this->hexnum=num; this->unlock(); } void TRM_map::setLivingUnits(DA * units) { this->lock(); if (this->lunits==NULL) { GLOBALLOGID(PRIORITY_DATA_WERE_RETURNED, "RMmap SET LUnits()"); this->lunits=units; } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap Can not return record about units"); THROW(E_8K_RM,"RMmap Can not return record about units"); } this->unlock(); } void TRM_map::setLivingBuildings(DA * buildings) { this->lock(); if (this->lbuildings==NULL) { GLOBALLOGID(PRIORITY_DATA_WERE_RETURNED, "RMmap SET LBuildings()"); this->lbuildings=buildings; } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap Can not return record about buildings"); THROW(E_8K_RM,"RMmap Can not return record about buildings"); } this->unlock(); } void TRM_map::setCities(DA * cities) { this->lock(); if (this->cities==NULL) { GLOBALLOGID(PRIORITY_DATA_WERE_RETURNED, "RMmap SET LCities()"); this->cities=cities; } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap Can not return record about towns"); THROW(E_8K_RM,"RMmap Can not return record about towns"); } this->unlock(); } void TRM_map::getLivingUnits(DA ** units) { this->lock(); if (this->lunits!=NULL) { GLOBALLOGID(PRIORITY_DATA_WERE_TAKEN, "RMmap GET LUnits()"); if (units!=NULL) (*units) = this->lunits; } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap Units have not been loaded yet"); THROW(E_8K_RM,"RMmap Units have not been loaded yet"); } this->lunits=NULL; this->unlock(); } void TRM_map::getLivingBuildings(DA ** buildings) { this->lock(); if (this->lbuildings!=NULL) { GLOBALLOGID(PRIORITY_DATA_WERE_TAKEN, "RMmap GET LBuildings()"); if (buildings!=NULL) (*buildings) = this->lbuildings; } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap Buildings have not been loaded yet"); THROW(E_8K_RM,"RMmap Buildings have not been loaded yet"); } this->lbuildings=NULL; this->unlock(); } void TRM_map::getCities(DA ** cities) { this->lock(); if (this->cities!=NULL) { GLOBALLOGID(PRIORITY_DATA_WERE_TAKEN, "RMmap GET LCities()"); if (cities!=NULL) (*cities) = this->cities; } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap Towns have not been loaded yet"); THROW(E_8K_RM,"RMmap Towns have not been loaded yet"); } this->cities=NULL; this->unlock(); } void TRM_map::getLivingUnit(World::LIVING_UNIT ** unit,int id) { this->lock(); *unit = (*(this->lunits))[id]; // vratim this->unlock(); } void TRM_map::getLivingBuilding(World::LIVING_BUILDING ** building,int id) { this->lock(); *building = (*(this->lbuildings))[id]; // vratim this->unlock(); } /* void TRM_map::freeData() { this->lock(); this->freeMap(); this->unlock(); } */ void TRM_map::freeMap() { this->lock(); int i,k; // hexy if (this->hexs!=NULL) { for (i=0;ihexnum;i++) { if (this->hexs[i]!=NULL) // smazu kazdy hex { if (this->hexs[i]->unit_occurrence.data!=NULL) KMemFree(this->hexs[i]->unit_occurrence.data); KMemFree(this->hexs[i]); } } KMemFree(this->hexs); this->hexs=NULL; } // jednotky if (this->lunits!=NULL) { for (i=this->lunits->getNext(-1);i!=-1;i=this->lunits->getNext(i)) { if ((*this->lunits)[i]->bonuses.data!=NULL) // pro kazdou jednotku smazu jeji bonusy { KMemFree((*this->lunits)[i]->bonuses.data); } KMemFree((*this->lunits)[i]); } delete(this->lunits); this->lunits=NULL; } // budovy if (this->lbuildings!=NULL) { for (i=this->lbuildings->getNext(-1);i!=-1;i=this->lbuildings->getNext(i)) { KMemFree((*this->lbuildings)[i]); } delete(this->lbuildings); this->lbuildings=NULL; } if (this->current_state!=NULL) { KMemFree(this->current_state); this->current_state=NULL; } // kralovstvi if (this->kingdoms!=NULL) { for (i=0;i<=MAX_KINGDOMS;i++) { if (this->kingdoms[i]!=NULL) { KMemFree(this->kingdoms[i]); this->kingdoms[i]=NULL; } } KMemFree(this->kingdoms); this->kingdoms=NULL; } // historicka mapa if (this->histhexs!=NULL) { for (k=0;k<=MAX_KINGDOMS;k++) { if (this->histhexs[k]!=NULL) { for (i=0;ihexnum;i++) { if (this->histhexs[k][i]!=NULL) // smazu kazdy hex { KMemFree(this->histhexs[k][i]); } } KMemFree(this->histhexs[k]); this->histhexs[k]=NULL; } } KMemFree(this->histhexs); this->histhexs=NULL; } // mesta if (this->cities!=NULL) { for (i=this->cities->getNext(-1);i!=-1;i=this->cities->getNext(i)) { KMemFree((*this->cities)[i]); } delete(this->cities); this->cities=NULL; } this->unlock(); // ai if (this->aiplan!=NULL) { for (i=0;i<=MAX_PLAYERS;i++) { if (this->aiplan->plan[i]!=NULL) { KMemFree(this->aiplan->plan[i]); this->aiplan->plan[i]=NULL; } } KMemFree(this->aiplan); this->aiplan=NULL; } } void TRM_map::forgetMapsInfo(int maptype) { int j; int i,ii; if (maptypemapsinfo[maptype]!=NULL) { for (j=this->mapsinfo[maptype]->getNext(-1);j!=-1;j=this->mapsinfo[maptype]->getNext(j)) { for (i=0;i!=(MAX_PLAYERS+1);i++) { if ((*this->mapsinfo[maptype])[j]->roles[i]!=NULL) { for (ii=0;ii!=(MAX_PLAYERS+1);ii++) { if ((*this->mapsinfo[maptype])[j]->roles[i]->relations[ii]!=NULL) { KMemFree((*this->mapsinfo[maptype])[j]->roles[i]->relations[ii]); (*this->mapsinfo[maptype])[j]->roles[i]->relations[ii]=NULL; } } KMemFree((*this->mapsinfo[maptype])[j]->roles[i]); (*this->mapsinfo[maptype])[j]->roles[i]=NULL; } } KMemFree((*this->mapsinfo[maptype])[j]); (*this->mapsinfo[maptype])[j]=NULL; } // this->mapsinfo[maptype]->reset(); delete(this->mapsinfo[maptype]); this->mapsinfo[maptype]=NULL; } } } int TRM_map::addMap(TMapInfo * info,int maptype) { this->lock(); info->id=-1; // vzdy se bude hledat this->maploaded=2; // jen tak pro formalitu, mapa se rusi, tj. neni tedka dostupna // vytvoreni prazne mapy this->freeMap(); if (white_chars_only(info->name)==1) // prazdne jmeno byt nemuze { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap can not add a map with empty name"); THROW(E_8K_RM,"RMmap can not add a map with empty name"); } char *path=(char*)KMemAlloc(100*sizeof(char)); size_t pathsize=100; if (maptype==MAP_TYPE_NEW_GAME) strpath(&path,RESOURCES_DIR,"",this->rmconfi->getPack(),MAPS_DIR,pathsize,info->file); else if (maptype==MAP_TYPE_SAVE_GAME) { #ifdef WIN32 strpath(&path,"","","",SAVEGAME_DIR,pathsize,info->file); #else snprintf(path,pathsize, "%s/.8Kingdoms/savegame/%s", getenv("HOME"), info->file); #endif } int i,ii; for (i=this->mapsinfo[maptype]->getNext(-1);i!=-1;i=this->mapsinfo[maptype]->getNext(i)) // podivam se, jestli neexistuje jiz mapa se stejnym souborem { if (strcmp(info->file,(*this->mapsinfo[maptype])[i]->file)==0) { GLOBALLOGID(PRIORITY_FATAL,"RMmap can not add a map with a file %s",info->file); THROW(E_8K_RM,"RMmap can not add a map with such a file name"); } } int maxindex=-1;; if (info->id==-1) // vzdy TRUE, protoze nastavuji info->id na -1 sam { // vlozim na prvni misto, kde jsou obe pole volne, aby byl index jednoznacny if (this->mapsinfo[0]!=NULL) { if (this->mapsinfo[1]!=NULL) { if (this->mapsinfo[0]->getMaxId()mapsinfo[1]->getMaxId()) maxindex=this->mapsinfo[1]->getMaxId(); else maxindex=this->mapsinfo[0]->getMaxId(); } else { maxindex=this->mapsinfo[0]->getMaxId(); } } else { if (this->mapsinfo[1]!=NULL) { maxindex=this->mapsinfo[1]->getMaxId(); } else { maxindex=-1; } } maxindex++; } else { maxindex=info->id; } if (this->mapsinfo[maptype]==NULL) { this->mapsinfo[maptype]=new DA (20,maxindex); } if (maxindex<0) { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap can not add a map with id %i < 0",maxindex); THROW(E_8K_RM,"RMmap can not add a map with id less than 1"); } info->id=maxindex; (*this->mapsinfo[maptype])[maxindex]=(TMapInfo*)KMemAlloc(sizeof(TMapInfo)); (*this->mapsinfo[maptype])[maxindex]->sizex=info->sizex; (*this->mapsinfo[maptype])[maxindex]->sizey=info->sizey; // (*this->mapsinfo[maptype])[maxindex]->players=info->players; strcpy((*this->mapsinfo[maptype])[maxindex]->file,info->file); strcpy((*this->mapsinfo[maptype])[maxindex]->name,info->name); strcpy((*this->mapsinfo[maptype])[maxindex]->description,info->description); if ((*this->mapsinfo[maptype])[maxindex]->description[0]==0) { (*this->mapsinfo[maptype])[maxindex]->description[0]=' '; (*this->mapsinfo[maptype])[maxindex]->description[0]=0; } int count=0; (*this->mapsinfo[maptype])[maxindex]->roles[0]=NULL; for (i=0;i!=(MAX_PLAYERS+1);i++) { if (info->roles[i]!=NULL) { count++; (*this->mapsinfo[maptype])[maxindex]->roles[i]=(TRoleInfo*)KMemAlloc(sizeof(TRoleInfo)); (*this->mapsinfo[maptype])[maxindex]->roles[i]->id=i; strcpy((*this->mapsinfo[maptype])[maxindex]->roles[i]->name,info->roles[i]->name); (*this->mapsinfo[maptype])[maxindex]->roles[i]->money=info->roles[i]->money; (*this->mapsinfo[maptype])[maxindex]->roles[i]->state=info->roles[i]->state; /// pocet zabitych jednotek (*this->mapsinfo[maptype])[maxindex]->roles[i]->stats.units_killed=info->roles[i]->stats.units_killed; (*this->mapsinfo[maptype])[maxindex]->roles[i]->stats.units_lost=info->roles[i]->stats.units_lost; (*this->mapsinfo[maptype])[maxindex]->roles[i]->stats.units_created=info->roles[i]->stats.units_created; (*this->mapsinfo[maptype])[maxindex]->roles[i]->stats.buildings_built=info->roles[i]->stats.buildings_built; (*this->mapsinfo[maptype])[maxindex]->roles[i]->stats.buildings_captured=info->roles[i]->stats.buildings_captured; (*this->mapsinfo[maptype])[maxindex]->roles[i]->stats.buildings_lost=info->roles[i]->stats.buildings_lost; (*this->mapsinfo[maptype])[maxindex]->roles[i]->stats.buildings_destroyed=info->roles[i]->stats.buildings_destroyed; (*this->mapsinfo[maptype])[maxindex]->roles[i]->stats.towns_captured=info->roles[i]->stats.towns_captured; (*this->mapsinfo[maptype])[maxindex]->roles[i]->stats.towns_lost=info->roles[i]->stats.towns_lost; (*this->mapsinfo[maptype])[maxindex]->roles[i]->stats.kingdoms_captured=info->roles[i]->stats.kingdoms_captured; (*this->mapsinfo[maptype])[maxindex]->roles[i]->stats.kingdoms_lost=info->roles[i]->stats.kingdoms_lost; (*this->mapsinfo[maptype])[maxindex]->roles[i]->stats.money_gained=info->roles[i]->stats.money_gained; for (ii=0;ii!=(MAX_PLAYERS+1);ii++) { if (info->roles[i]->relations[ii]!=NULL) { (*this->mapsinfo[maptype])[maxindex]->roles[i]->relations[ii]=(ai_ns::diplomacy_ns::TDipRelation*)KMemAlloc(sizeof(ai_ns::diplomacy_ns::TDipRelation)); (*this->mapsinfo[maptype])[maxindex]->roles[i]->relations[ii]->rs=info->roles[i]->relations[ii]->rs; (*this->mapsinfo[maptype])[maxindex]->roles[i]->relations[ii]->offeredrs=info->roles[i]->relations[ii]->offeredrs; (*this->mapsinfo[maptype])[maxindex]->roles[i]->relations[ii]->relationship_properties.offer_seen_by_enemy=info->roles[i]->relations[ii]->relationship_properties.offer_seen_by_enemy; (*this->mapsinfo[maptype])[maxindex]->roles[i]->relations[ii]->relationship_properties.belief=info->roles[i]->relations[ii]->relationship_properties.belief; (*this->mapsinfo[maptype])[maxindex]->roles[i]->relations[ii]->relationship_properties.guess_belief=info->roles[i]->relations[ii]->relationship_properties.guess_belief; // (*(*this->mapsinfo[maptype])[maxindex]->roles[i]->relations[ii])=*(info->roles[i]->relations[ii]); } else { (*this->mapsinfo[maptype])[maxindex]->roles[i]->relations[ii]=NULL; } } } else (*this->mapsinfo[maptype])[maxindex]->roles[i]=NULL; } (*this->mapsinfo[maptype])[maxindex]->players=count; KMemFree(path); this->hexs=(HEX**) KMemAlloc(sizeof(HEX*)*info->sizex*info->sizey); // nova velikost mapy this->hexnum=info->sizex*info->sizey; for (i=0;isizex*info->sizey;i++) { this->hexs[i]=(HEX*) KMemAlloc(sizeof(HEX)); this->hexs[i]->terrain=TT_PLAIN; this->hexs[i]->elevation=ET_LEVEL1; this->hexs[i]->unit=0; this->hexs[i]->building=0; this->hexs[i]->kingdom=0; this->hexs[i]->unit_occurrence.length=0; this->hexs[i]->unit_occurrence.data=NULL; } this->lunits=new (DA)(20,1); // od jednicky - hodnota==0 znamena nic,budou se pridavat prvni jednotky this->lbuildings=new (DA)(20,1); this->cities=new (DA)(20,1); this->current_state=(TStateInfo*)KMemAlloc(sizeof(TStateInfo)*1); this->current_state->weather=WS_SUNNY; this->current_state->player_on_turn=1; this->current_state->duration=0; this->current_state->turn_id=0; this->kingdoms=(TKingdomInfo**) KMemAlloc(sizeof(TKingdomInfo*)*(MAX_KINGDOMS+1)); this->histhexs=(HISTORY_HEX ***) KMemAlloc(sizeof(HISTORY_HEX**)*(MAX_KINGDOMS+1)); for (i=0;i<=MAX_KINGDOMS;i++) { this->histhexs[i]=NULL; this->kingdoms[i]=NULL; } this->idofmap=info->id; // id nactene mapy - potrebuji uz ted predat, pouzije se v saveMap() this->saveMap(maptype,info->file); // nelze mit v pameti jiny obsah nez je na disku this->maploaded=1; // mapa je pripravena az ted this->unlock(); return this->idofmap; } void TRM_map::fillMap(TXMLdata * map) { this->lock(); int mapsize=this->hexnum; int i,k; // AI if (this->aiplan!=NULL) { for (i=0;i<=MAX_PLAYERS;i++) { if (this->aiplan->plan[i]!=NULL) { map->setData(this->aiplan->plan[i],"ai",0,"plan",i,NULL); } } } // CURRENT_STATE map->setDataInt(this->current_state->turn_id,"currentState",0,"turn",0,NULL); map->setDataInt(this->current_state->player_on_turn,"currentState",0,"onTurn",0,NULL); map->setDataInt(this->current_state->duration,"currentState",0,"duration",0,NULL); map->setDataInt(this->current_state->weather,"currentState",0,"weather",0,NULL); // KRALOVSTVI for (i=0;i<=MAX_KINGDOMS;i++) { if (this->kingdoms[i]!=NULL) { map->setDataInt(this->kingdoms[i]->roleid,"kingdoms",0,"kingdom",i,"role",0,NULL); map->setDataInt(this->kingdoms[i]->centerx,"kingdoms",0,"kingdom",i,"centerx",0,NULL); map->setDataInt(this->kingdoms[i]->centery,"kingdoms",0,"kingdom",i,"centery",0,NULL); } } // MESTA for (i=this->cities->getNext(-1);i!=-1;i=this->cities->getNext(i)) // +1 aby se zacinalo u indexu 1 a ne 0, ktery se do mapy nepise (aby to vypadalo dobre) { map->setData((*this->cities)[i]->name,"cities",0,"city",i,"name",0,NULL); map->setDataInt((*this->cities)[i]->citysize,"cities",0,"city",i,"citysize",0,NULL); map->setDataInt((*this->cities)[i]->owner,"cities",0,"city",i,"owner",0,NULL); for (k=0;k<(*this->cities)[i]->citysize;k++) { map->setDataInt((*this->cities)[i]->position[k],"cities",0,"city",i,"position",k+1,NULL); } } // HEXY for (i=1;i<=mapsize;i++) { for (k=0;k<=MAX_KINGDOMS;k++) { if (this->histhexs[k]!=NULL) { if (this->histhexs[k][i-1]!=NULL) // k-ty hrac uz hex i-1 videl! { map->setDataInt(this->histhexs[k][i-1]->turn_id,"map",0,"hex",i,"history",0,"role",k,"round",0,NULL); map->setDataInt(this->histhexs[k][i-1]->building,"map",0,"hex",i,"history",0,"role",k,"building_type",0,NULL); } } } // Unit occurrence if (this->hexs[i-1]->unit_occurrence.data!=0) { for (k=0;khexs[i-1]->unit_occurrence.length;k++) { map->setDataInt(this->hexs[i-1]->unit_occurrence.data[k],"map",0,"hex",i,"occurrences",0,"occurrence",k+1,NULL); } } // Teren - povinny map->setDataInt(this->hexs[i-1]->terrain,"map",0,"hex",i,"terrain",0,NULL); // Vyska - povinna map->setDataInt(this->hexs[i-1]->elevation,"map",0,"hex",i,"elevation",0,NULL); // Jednotka na hexu if (this->hexs[i-1]->unit!=0) map->setDataInt(this->hexs[i-1]->unit,"map",0,"hex",i,"unit",0,NULL); // Budova na hexu if (this->hexs[i-1]->building!=0) map->setDataInt(this->hexs[i-1]->building,"map",0,"hex",i,"building",0,NULL); /* Odstraneni polozky HEX::player 21.2.2006 PW // Vlastnik hexu if (this->hexs[i-1]->player!=0) map->setDataInt(this->hexs[i-1]->player,"map",0,"hex",i,"owner",0,NULL); */ // Kralovstvi if (this->hexs[i-1]->kingdom!=0) map->setDataInt(this->hexs[i-1]->kingdom,"map",0,"hex",i,"kingdom",0,NULL); } // JEDNOTKY int wounds; int j; for (i=this->lunits->getNext(-1);i!=-1;i=this->lunits->getNext(i)) { j=i; map->setDataInt((*this->lunits)[j]->type,"units",0,"unit",i,"type",0,NULL); map->setDataInt((*this->lunits)[j]->player,"units",0,"unit",i,"player",0,NULL); map->setDataInt((*this->lunits)[j]->points_of_movement,"units",0,"unit",i,"movement",0,NULL); map->setDataInt((*this->lunits)[j]->lives,"units",0,"unit",i,"lives",0,NULL); if ((*this->lunits)[j]->state!=US_IDLE) map->setDataInt((*this->lunits)[j]->state,"units",0,"unit",i,"state",0,NULL); if ((*this->lunits)[j]->name[0]!=0) map->setData((*this->lunits)[j]->name,"units",0,"unit",i,"name",0,NULL); for (wounds=1;wounds<=MAX_LIVES;wounds++) { if ((*this->lunits)[j]->wounds[wounds-1]!=0) map->setDataInt((*this->lunits)[j]->wounds[wounds-1],"units",0,"unit",i,"wounds",0,"man",wounds,NULL); } map->setDataInt((*this->lunits)[j]->level,"units",0,"unit",i,"level",0,NULL); map->setDataInt((*this->lunits)[j]->experience,"units",0,"unit",i,"experiences",0,NULL); if ((*this->lunits)[j]->assaults_count!=0) map->setDataInt((*this->lunits)[j]->assaults_count,"units",0,"unit",i,"assaults_count",0,NULL); int bns; if ((*this->lunits)[j]->bonuses.data!=NULL) { for (bns=0;bns<(*this->lunits)[j]->bonuses.length;bns++) { map->setDataInt((*this->lunits)[j]->bonuses.data[bns],"units",0,"unit",i,"bonuses",0,"bonus",bns+1,NULL); } } map->setDataInt((*this->lunits)[j]->orientation,"units",0,"unit",i,"orientation",0,NULL); } for (i=this->lbuildings->getNext(-1);i!=-1;i=this->lbuildings->getNext(i)) { // Vlastni jmeno budovy /* if ((j=map.getData((*this->lbuildings)[j]->player,10,"buildings",0,"building",i,"owner",0,NULL)) == XML_ERROR_NO_SUCH_A_PATH) */ j=i; map->setDataInt((*this->lbuildings)[j]->type,"buildings",0,"building",i,"type",0,NULL); if ((*this->lbuildings)[j]->name[0]!=0) map->setData((*this->lbuildings)[j]->name,"buildings",0,"building",i,"name",0,NULL); map->setDataInt((*this->lbuildings)[j]->lives,"buildings",0,"building",i,"lives",0,NULL); map->setDataInt((*this->lbuildings)[j]->player,"buildings",0,"building",i,"player",0,NULL); if ((*this->lbuildings)[j]->construction_duration!=0) map->setDataInt((*this->lbuildings)[j]->construction_duration,"buildings",0,"building",i,"constructionDuration",0,NULL); map->setDataInt((*this->lbuildings)[j]->orientation,"buildings",0,"building",i,"orientation",0,NULL); } this->unlock(); } /// pomocna promenna static char bu_path[K8_MAX_PATH_LEN]; void TRM_map::saveMap(int maptype,char * newname) { this->lock(); int newtype=-1; // slouzi k urceni puvodni informaci (tj. mapy kterou ukladam) // kdyz se rozehraje nova mapa a pak se da ulozit jako save, vola se tato metoda // s maptype==SAVE_GAME, ale informace jsou v NEW_GAME... proto slouzi newtype, // kde bude informace o spravnem (puvodnim) poli // pokud se mapa pridava (tj. maploaded==0) toto rozdeleni neni treba if (this->maploaded!=0) { if ( (this->mapsinfo[1]!=NULL) && ((*this->mapsinfo[1])[this->idofmap]!=NULL) ) { newtype=1; } else { if ( (this->mapsinfo[0]!=NULL) && ((*this->mapsinfo[0])[this->idofmap]!=NULL) ) { newtype=0; } else { GLOBALLOGID(PRIORITY_FATAL,"RMmap No map is loaded"); THROW(E_8K_RM,"RMmap No map is loaded"); } } } else { newtype=maptype; } if (this->idofmap>=0) // abych ukladal, jen kdyz je nacteno { TXMLdata newmap(1,1); // ZAKLADNI INFORMACE newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->sizex,"header",0,"sizex",0,NULL); // a zapisi ostatni atributy do indexu newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->sizey,"header",0,"sizey",0,NULL); newmap.setData((*this->mapsinfo[newtype])[this->idofmap]->name,"header",0,"name",0,NULL); newmap.setData((*this->mapsinfo[newtype])[this->idofmap]->description,"header",0,"description",0,NULL); // ROLE int ii,i; for (i=1;i!=(MAX_PLAYERS+1);i++) { if ((*this->mapsinfo[newtype])[this->idofmap]->roles[i]!=NULL) { (*this->mapsinfo[newtype])[this->idofmap]->roles[i]->id=i; newmap.setData((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->name,"header",0,"roles",0,"role",i,"name",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->money,"header",0,"roles",0,"role",i,"money",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->state,"header",0,"roles",0,"role",i,"state",0,NULL); // statistika newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->stats.units_killed,"header",0,"roles",0,"role",i,"statistics",0,"unitsKilled",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->stats.units_lost,"header",0,"roles",0,"role",i,"statistics",0,"unitsLost",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->stats.units_created,"header",0,"roles",0,"role",i,"statistics",0,"unitsCreated",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->stats.buildings_built,"header",0,"roles",0,"role",i,"statistics",0,"buildingsBuilt",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->stats.buildings_captured,"header",0,"roles",0,"role",i,"statistics",0,"buildingsCaptured",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->stats.buildings_lost,"header",0,"roles",0,"role",i,"statistics",0,"buildingsLost",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->stats.buildings_destroyed,"header",0,"roles",0,"role",i,"statistics",0,"buildingsDestroyed",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->stats.towns_captured,"header",0,"roles",0,"role",i,"statistics",0,"townsCaptured",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->stats.towns_lost,"header",0,"roles",0,"role",i,"statistics",0,"townsLost",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->stats.kingdoms_captured,"header",0,"roles",0,"role",i,"statistics",0,"kingdomsCaptured",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->stats.kingdoms_lost,"header",0,"roles",0,"role",i,"statistics",0,"kingdomsLost",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->stats.money_gained,"header",0,"roles",0,"role",i,"statistics",0,"moneyGained",0,NULL); for (ii=0;ii!=(MAX_PLAYERS+1);ii++) if ((*this->mapsinfo[newtype])[this->idofmap]->roles[i]!=NULL) if ((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->relations[ii]!=NULL) { newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->relations[ii]->rs,"header",0,"roles",0,"role",i,"relations",0,"role",ii,"state",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->relations[ii]->offeredrs,"header",0,"roles",0,"role",i,"relations",0,"role",ii,"offered",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->relations[ii]->relationship_properties.offer_seen_by_enemy,"header",0,"roles",0,"role",i,"relations",0,"role",ii,"delivered",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->relations[ii]->relationship_properties.belief,"header",0,"roles",0,"role",i,"relations",0,"role",ii,"belief",0,NULL); newmap.setDataInt((*this->mapsinfo[newtype])[this->idofmap]->roles[i]->relations[ii]->relationship_properties.guess_belief,"header",0,"roles",0,"role",i,"relations",0,"role",ii,"guessBelief",0,NULL); } } } this->fillMap(&newmap); if (this->hexs!=NULL) { TMapInfo * minfo=(*this->mapsinfo[newtype])[this->idofmap]; if (maptype==MAP_TYPE_SAVE_GAME) { if (newname[0]!=0) // je to pradny retezec - stejne jmeno { #ifdef WIN32 strpartpath(bu_path,"","","",SAVEGAME_DIR,K8_MAX_PATH_LEN,newname); #else snprintf(bu_path, K8_MAX_PATH_LEN,"%s/.8Kingdoms/savegame/%s", getenv("HOME"), newname); #endif } else { #ifdef WIN32 strpartpath(bu_path,"","","",SAVEGAME_DIR,K8_MAX_PATH_LEN,minfo->file); #else snprintf(bu_path, K8_MAX_PATH_LEN,"%s/.8Kingdoms/savegame/%s", getenv("HOME"), minfo->file); #endif } } else if (maptype==MAP_TYPE_NEW_GAME) { if (newname[0]!=0) // je to pradny retezec strpartpath(bu_path,RESOURCES_DIR,"",this->rmconfi->getPack(),MAPS_DIR,K8_MAX_PATH_LEN,newname); else strpartpath(bu_path,RESOURCES_DIR,"",this->rmconfi->getPack(),MAPS_DIR,K8_MAX_PATH_LEN,minfo->file); } if (newmap.saveToFile(bu_path)!=XML_ERROR_OK) { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap can not write to the file %s, the map was not saved",bu_path); THROW(E_8K_RM,"RMmap can not write to a file, the map is not saved"); } // uchovam si prave zapisovane jmeno char fileofmap[K8_MAX_FILE_NAME_LEN]; if (newname[0]!=0) strcpy(fileofmap,newname); else strcpy(fileofmap,minfo->file); // nactu informace o adresari, kde mohl pribyt soubor - to jen zajisti, ze porad ukazuji // na stejnou mapu - bud na tu ze ktere jsem to ukladal nebo na tu novou // ze ktere jsem ukladal napr. kdyz z nove hry delam poprve save (doslo k "presunu do jineho adrsare") // na tu novou - pokud jsem ukladal jen save ze savu (tj. v ramci stejneho adresare) this->loadMapsInfo(maptype,1); // ja mohu mit porad ID mapy v tom puvodnim adresari - proto to vyhledam v novem adresari this->idofmap=-1; int i; for (i=this->mapsinfo[maptype]->getNext(-1);i!=-1;i=this->mapsinfo[maptype]->getNext(i)) { if (strcmp(fileofmap,(*this->mapsinfo[maptype])[i]->file)==0) // nasel jsem tu mapu, ktera byla nactena { this->idofmap=i; break; } } if (this->idofmap==-1) // nekdo napr. smazal mapu, ktera byla nactena { GLOBALLOGID(PRIORITY_FATAL,"RMmap The map being currently used was removed"); THROW(E_8K_RM,"RMmap The map being currently used was removed"); } } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap can not save any map without hexes"); THROW(E_8K_RM,"RMmap can not save any map without hexes"); } } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap can not save empty map"); THROW(E_8K_RM,"RMmap can not save empty map"); } this->unlock(); } void TRM_map::selectMap(int id) { this->lock(); this->maploaded=0; this->freeMap(); this->idofmap=id; this->maploaded=3; this->unlock(); } /// pomocna promenna static char bu_path4[K8_MAX_PATH_LEN]; void TRM_map::delMap(int id) { this->lock(); this->freeMap(); int res; TMapInfo * minfo=NULL; // index je jednoznacny, index id ma nejvyse jedna mapa int maptype; if (this->mapsinfo[1]!=NULL) // zkusim nejdriv savy { if ((*this->mapsinfo[1])[id]!=NULL) { minfo=(*this->mapsinfo[1])[id]; (*this->mapsinfo[1])[id]=NULL; // this->mapsinfo[1]->remove(id); // odstranim z pole maptype=MAP_TYPE_SAVE_GAME; } } if (minfo==NULL) // tj. neni to v Savegame { if (this->mapsinfo[0]!=NULL) // podivam se tedy do novych map { if ((*this->mapsinfo[0])[id]!=NULL) { minfo=(*this->mapsinfo[0])[id]; // this->mapsinfo[0]->remove(id); // odstranim z pole (*this->mapsinfo[0])[id]=NULL; maptype=MAP_TYPE_NEW_GAME; } } } if (minfo==NULL) // tj. takova mapa neni { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap can not remove file %s",minfo->file); } else { if (minfo!=NULL) { #ifdef WIN32 strpartpath(bu_path4,"","","",SAVEGAME_DIR,K8_MAX_PATH_LEN,minfo->file); #else snprintf(bu_path4, K8_MAX_PATH_LEN,"%s/.8Kingdoms/savegame/%s", getenv("HOME"),minfo->file); #endif res=unlink(bu_path4); } if (res!=0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap can not remove file %s",minfo->file); } int i; for (i=0;i!=(MAX_PLAYERS+1);i++) { if (minfo->roles[i]!=NULL) KMemFree(minfo->roles[i]); } KMemFree(minfo); // this->loadMapsInfo(maptype,1); - neni treba.. odebere se v prostredku.. } this->unlock(); } /* void TRM_map::removeMap(int id) { if (idmapsinfo[maptype]->getMaxId()) { KMemFree((*this->mapsinfo[maptype])[id]); (*this->mapsinfo[maptype])[id]=(*this->mapsinfo[maptype])[this->mapsinfo[maptype]->getMaxId()]; (*this->mapsinfo[maptype])[this->mapsinfo[maptype]->getMaxId()]=NULL; this->mapsinfo[maptype]->push(NULL); } else { if (id==this->mapsinfo[maptype]->getMaxId()) { KMemFree((*this->mapsinfo[maptype])[id]); (*this->mapsinfo[maptype])[id]=NULL; this->mapsinfo[maptype]->push(NULL); } } } */ /// Funkce na setrizeni map podle jmena jejich souboru void my_sort(DA * mi, int maptype) { int i,j; int k,l; TMapInfo * x=NULL; TMapInfo * y=NULL; for (i=mi->getNext(-1);i!=-1;i=mi->getNext(i)) { for (j=mi->getNext(-1);j!=-1;j=mi->getNext(j)) { if (i!=j) { if (((maptype==1) && (stricmp((*mi)[j]->file,(*mi)[i]->file)>0)) || ((maptype==0) && (stricmp((*mi)[j]->name,(*mi)[i]->name)>0))) { x=(*mi)[j]; y=(*mi)[i]; k=x->id; l=y->id; (*mi)[i]=x; (*mi)[i]->id=l; (*mi)[j]=y; (*mi)[j]->id=k; } } } } } /// pomocna promenna static char bu_path3[K8_MAX_PATH_LEN]; void TRM_map::loadMapsInfo(int maptype,int refresh) { TXMLdata * map; this->lock(); if ( (this->mapsinfo[maptype]!=NULL) && (refresh!=1) ) { this->unlock(); return; } int oldtype=-1; char fileofmap[K8_MAX_FILE_NAME_LEN]; TMapInfo * minfo=NULL; if (this->maploaded!=0) // je neco nactene... muze nastat problem { if ( (this->mapsinfo[1]!=NULL) && ((*this->mapsinfo[1])[this->idofmap]!=NULL) ) { oldtype=1; minfo=(*(this->mapsinfo[1]))[this->idofmap]; } else { if ( (this->mapsinfo[0]!=NULL) && ((*this->mapsinfo[0])[this->idofmap]!=NULL) ) { oldtype=0; minfo=(*(this->mapsinfo[0]))[this->idofmap]; } else { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap has loaded a map without the general information"); THROW(E_8K_RM,"RMmap has loaded a map without the general information"); } } } if (oldtype==maptype) // dojde k precislovani - problem nastava - odkaz this->idofmap muze zacina po precislovani ukazovat na spatnou mapu { strcpy(fileofmap,minfo->file); } // vytvorim pokud jeste dany typ nebyl nacten int from=0; if (refresh==0) { if (this->mapsinfo[(maptype+1)%2]!=NULL) from=this->mapsinfo[(maptype+1)%2]->getMaxId()+1; } else { this->forgetMapsInfo((maptype+1)%2); } int mapscount=from; this->forgetMapsInfo(maptype); if (this->mapsinfo[maptype]==NULL) { this->mapsinfo[maptype]=new DA (20,from); } // smazu dosavadni informace /* for (i=this->mapsinfo[maptype]->getShift();i<=this->mapsinfo[maptype]->getMaxId();i++) // podivam se, jestli neexistuje jiz mapa se stejnym souborem { if ((*this->mapsinfo[maptype])[i]!=NULL) { KMemFree((*this->mapsinfo[maptype])[i]); (*this->mapsinfo[maptype])[i]=NULL; } } this->mapsinfo[maptype]->reset();*/ // necham si vylistovat adresar s mapama try { #ifdef WIN32 if (maptype==MAP_TYPE_NEW_GAME) { strpartpath(bu_path3,RESOURCES_DIR,"/",this->rmconfi->getPack(),MAPS_DIR,K8_MAX_PATH_LEN,"*.xml"); } else if (maptype==MAP_TYPE_SAVE_GAME) { strpartpath(bu_path3,"","","",SAVEGAME_DIR,K8_MAX_PATH_LEN,"*.xml"); // sprintf(bu_path3, "%s/.8Kingdoms/savegame/*.xml", getenv("HOME")); } #else if (maptype==MAP_TYPE_NEW_GAME) { strpartpath(bu_path3,RESOURCES_DIR,"/",this->rmconfi->getPack(),MAPS_DIR,K8_MAX_PATH_LEN,""); } else if (maptype==MAP_TYPE_SAVE_GAME) { snprintf(bu_path3, K8_MAX_PATH_LEN,"%s/.8Kingdoms/savegame/", getenv("HOME")); // strpartpath(bu_path3,"","","",SAVEGAME_DIR,K8_MAX_PATH_LEN,""); } #endif } catch (E_8K_RM) { this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"Corrupeted files.xml"); THROW(E_8K_RM,"Corrupted files.xml"); } #ifdef WIN32 _finddata_t dta; long idhandle=(long)_findfirst(bu_path3, &dta); if(idhandle==-1) { if (maptype==MAP_TYPE_SAVE_GAME) { GLOBALLOGID(PRIORITY_CREATING_DIRECTORY, "Attemp to create savegame directory"); _mkdir(SAVEGAME_DIR); } this->unlock(); return; // THROW(E_8K_RM,"Nelze otevrit adresar s mapami"); } #else DIR *dir=opendir(bu_path3); if (dir==NULL) { GLOBALLOGID(PRIORITY_CREATING_DIRECTORY, "Creating savegame directory"); mkdir(bu_path3,0755); this->unlock(); return; // GLOBALLOGID(PRIORITY_FATAL,"Nelze otevrit adresar s mapami"); // THROW(E_8K_RM,"Nelze otevrit adresar s mapami"); } struct dirent *de; de=readdir(dir); #endif int correctmap; int res; char * filename; int i,ii,temp; do { #ifdef WIN32 if ((dta.name[0]!='.') && (dta.size>0)) // pokud je to mozna mapa, koncovku ohlida findfirst { if (maptype==MAP_TYPE_NEW_GAME) strpartpath(bu_path3,RESOURCES_DIR,"",this->rmconfi->getPack(),MAPS_DIR,K8_MAX_PATH_LEN,dta.name); else if (maptype==MAP_TYPE_SAVE_GAME) strpartpath(bu_path3,"","","",SAVEGAME_DIR,K8_MAX_PATH_LEN,dta.name); filename=dta.name; #else int d_namelen = strlen(de->d_name);//reglen nefunguje if ((de!=NULL) && (d_namelen > 4) && (!strnicmp(de->d_name + d_namelen - 4,".xml", 4)) ) // pokud to ma jmeno souboru aspon 5 znaku (.xml ktera ma 4 znaky) a pokud to konci prave na .xml { if (maptype==MAP_TYPE_NEW_GAME) strpartpath(bu_path3,RESOURCES_DIR,"",this->rmconfi->getPack(),MAPS_DIR,K8_MAX_PATH_LEN,de->d_name); else if (maptype==MAP_TYPE_SAVE_GAME) snprintf(bu_path3, K8_MAX_PATH_LEN,"%s/.8Kingdoms/savegame/%s", getenv("HOME"), de->d_name); //strpartpath(bu_path3,"","","",SAVEGAME_DIR,K8_MAX_PATH_LEN,de->d_name); filename=de->d_name; #endif if ((*this->mapsinfo[maptype])[mapscount]==NULL) // toto mohlo byt nesplneno, pokud je v adresari nejaka spatna mapa { (*this->mapsinfo[maptype])[mapscount]=(TMapInfo*)KMemAlloc(sizeof(TMapInfo)); int i; (*this->mapsinfo[maptype])[mapscount]->id=mapscount; (*this->mapsinfo[maptype])[mapscount]->roles[0]=NULL; // sice se nepouziva, ale aby tam nebylo smeti for (i=1;i!=(MAX_PLAYERS+1);i++) { (*this->mapsinfo[maptype])[mapscount]->roles[i]=NULL; } // (*this->mapsinfo[maptype])[mapscount]->roles=NULL; } /* if ((*this->mapsinfo[maptype])[mapscount]->roles==NULL) { (*this->mapsinfo[maptype])[mapscount]->roles=new (DA)(9); } */ map=new TXMLdata; res=map->readFile(bu_path3,"header"); // nacti jen header // wprintf(path); // printf(" "); if (res==XML_ERROR_OK) { if ( (((*this->mapsinfo[maptype])[mapscount]->sizex=map->getDataInt("header",0,"sizex",0,NULL))<=0) || (((*this->mapsinfo[maptype])[mapscount]->sizey=map->getDataInt("header",0,"sizey",0,NULL))<=0) || (map->getData((*this->mapsinfo[maptype])[mapscount]->name,MAP_NAME_LEN,"header",0,"name",0,NULL)==XML_ERROR_NO_SUCH_A_PATH) || ((*this->mapsinfo[maptype])[mapscount]->name[0]==0) || ((*this->mapsinfo[maptype])[mapscount]->sizex>MAX_MAP_WIDTH) || ((*this->mapsinfo[maptype])[mapscount]->sizey>MAX_MAP_HEIGHT) // (((*this->mapsinfo[maptype])[mapscount]->players=map->getNumId("header",0,"roles",0,"role",0))==XML_ERROR_NO_SUCH_A_PATH) // (((*this->mapsinfo[maptype])[mapscount]->players=map->getDataInt("header",0,"players",0,NULL))==XML_ERROR_NO_SUCH_A_PATH) ) { KMemFree((*this->mapsinfo[maptype])[mapscount]); (*this->mapsinfo[maptype])[mapscount]=NULL; GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); } else { map->getData((*this->mapsinfo[maptype])[mapscount]->description,MAP_DESC_LEN,"header",0,"description",0,NULL); strcpy((*this->mapsinfo[maptype])[mapscount]->file,filename); DAids; map->getListOfIds(&ids,"header",0,"roles",0,NULL); int count=0; // pocet hracu correctmap=1; for (i=ids.getNext(-1);i!=-1;i=ids.getNext(i)) { if (correctmap==0) // pokud se nekde objevila chyba zkonci break; count++; (*this->mapsinfo[maptype])[mapscount]->roles[i]=(TRoleInfo*)KMemAlloc(sizeof(TRoleInfo)); (*this->mapsinfo[maptype])[mapscount]->roles[i]->id=i; // vztahy k ostatnim vynulovat for (ii=0;ii!=(MAX_PLAYERS+1);ii++) (*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]=NULL; if ( map->getData((*this->mapsinfo[maptype])[mapscount]->roles[i]->name,K8_MAX_NAME_LEN,"header",0,"roles",0,"role",i,"name",0,NULL)==XML_ERROR_NO_SUCH_A_PATH) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } // penize mohou byt zaporne (*this->mapsinfo[maptype])[mapscount]->roles[i]->money=map->getDataInt("header",0,"roles",0,"role",i,"money",0,NULL); /* if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->money=map->getDataInt("header",0,"roles",0,"role",i,"money",0,NULL))<0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus }*/ if ( (temp=map->getDataInt("header",0,"roles",0,"role",i,"state",0,NULL))<0) { /* GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus */ (*this->mapsinfo[maptype])[mapscount]->roles[i]->state=PS_ACTIVE; } else { switch (temp) { case PS_DEFEATED: case PS_ACTIVE: { (*this->mapsinfo[maptype])[mapscount]->roles[i]->state=(PLAYER_STATE)temp; } break; default: { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } } } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->stats.units_killed=map->getDataInt("header",0,"roles",0,"role",i,"statistics",0,"unitsKilled",0,NULL))<0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->stats.units_lost=map->getDataInt("header",0,"roles",0,"role",i,"statistics",0,"unitsLost",0,NULL))<0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->stats.units_created=map->getDataInt("header",0,"roles",0,"role",i,"statistics",0,"unitsCreated",0,NULL))<0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->stats.buildings_built=map->getDataInt("header",0,"roles",0,"role",i,"statistics",0,"buildingsBuilt",0,NULL))<0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->stats.buildings_captured=map->getDataInt("header",0,"roles",0,"role",i,"statistics",0,"buildingsCaptured",0,NULL))<0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->stats.buildings_lost=map->getDataInt("header",0,"roles",0,"role",i,"statistics",0,"buildingsLost",0,NULL))<0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->stats.buildings_destroyed=map->getDataInt("header",0,"roles",0,"role",i,"statistics",0,"buildingsDestroyed",0,NULL))<0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->stats.towns_captured=map->getDataInt("header",0,"roles",0,"role",i,"statistics",0,"townsCaptured",0,NULL))<0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->stats.towns_lost=map->getDataInt("header",0,"roles",0,"role",i,"statistics",0,"townsLost",0,NULL))<0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->stats.kingdoms_captured=map->getDataInt("header",0,"roles",0,"role",i,"statistics",0,"kingdomsCaptured",0,NULL))<0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->stats.kingdoms_lost=map->getDataInt("header",0,"roles",0,"role",i,"statistics",0,"kingdomsLost",0,NULL))<0) { GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus } // money_gained muze nabyvat vsechn int hodnot (*this->mapsinfo[maptype])[mapscount]->roles[i]->stats.money_gained=map->getDataInt("header",0,"roles",0,"role",i,"statistics",0,"moneyGained",0,NULL); for (ii=ids.getNext(-1);ii!=-1;ii=ids.getNext(ii)) // pres vsechny role { // count++; if (i!=ii) // vzath role sama se sebou neni treba { (*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]=(ai_ns::diplomacy_ns::TDipRelation*)KMemAlloc(sizeof(ai_ns::diplomacy_ns::TDipRelation)); if ( (temp=map->getDataInt("header",0,"roles",0,"role",i,"relations",0,"role",ii,"state",0,NULL))==XML_ERROR_NO_SUCH_A_PATH) { /* GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus */ (*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]->rs = ai_ns::diplomacy_ns::RELATIONSHIP_WAR; } else { switch (temp) { case ai_ns::diplomacy_ns::RELATIONSHIP_WAR: case ai_ns::diplomacy_ns::RELATIONSHIP_ENEMY: case ai_ns::diplomacy_ns::RELATIONSHIP_TRUCE: case ai_ns::diplomacy_ns::RELATIONSHIP_ALLY: (*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]->rs = (ai_ns::diplomacy_ns::TRelationship)temp; break; default: GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; } } if ( (temp=map->getDataInt("header",0,"roles",0,"role",i,"relations",0,"role",ii,"offered",0,NULL))==XML_ERROR_NO_SUCH_A_PATH) { /* GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus */ (*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]->offeredrs = ai_ns::diplomacy_ns::RELATIONSHIP_WAR; } else { switch (temp) { case ai_ns::diplomacy_ns::RELATIONSHIP_WAR: case ai_ns::diplomacy_ns::RELATIONSHIP_ENEMY: case ai_ns::diplomacy_ns::RELATIONSHIP_TRUCE: case ai_ns::diplomacy_ns::RELATIONSHIP_ALLY: (*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]->offeredrs = (ai_ns::diplomacy_ns::TRelationship)temp; break; default: GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; } } if ( (temp=map->getDataInt("header",0,"roles",0,"role",i,"relations",0,"role",ii,"delivered",0,NULL))<0) { /* GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus */ (*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]->relationship_properties.offer_seen_by_enemy=0; } else { if (temp>=1) { (*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]->relationship_properties.offer_seen_by_enemy=1; } else { (*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]->relationship_properties.offer_seen_by_enemy=0; } } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]->relationship_properties.belief=map->getDataInt("header",0,"roles",0,"role",i,"relations",0,"role",ii,"belief",0,NULL))<0) { /* GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus */ (*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]->relationship_properties.belief=0; } if ( ((*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]->relationship_properties.guess_belief=map->getDataInt("header",0,"roles",0,"role",i,"relations",0,"role",ii,"guessBelief",0,NULL))<0) { /* GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); mapscount--; // bude to zahy zvetseno correctmap=0; break; // prerusim cyklus */ (*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]->relationship_properties.guess_belief=0; } } } } if (correctmap==1) { (*this->mapsinfo[maptype])[mapscount]->players=count; mapscount++; // posunu na dalsi volne misto } else // vymazat informace { mapscount++; // abych smazal toto if ((*this->mapsinfo[maptype])[mapscount]!=NULL) { for (i=0;i!=(MAX_PLAYERS+1);i++) { if ((*this->mapsinfo[maptype])[mapscount]->roles[i]!=NULL) { for (ii=0;ii!=(MAX_PLAYERS+1);ii++) { if ((*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]!=NULL) { KMemFree((*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]); (*this->mapsinfo[maptype])[mapscount]->roles[i]->relations[ii]=NULL; } } KMemFree((*this->mapsinfo[maptype])[mapscount]->roles[i]); (*this->mapsinfo[maptype])[mapscount]->roles[i]=NULL; } } } KMemFree((*this->mapsinfo[maptype])[mapscount]); (*this->mapsinfo[maptype])[mapscount]=NULL; } } } else { KMemFree((*this->mapsinfo[maptype])[mapscount]); (*this->mapsinfo[maptype])[mapscount]=NULL; GLOBALLOGID(PRIORITY_WRONG_MAP, "RMmap %s is not a valid map",bu_path3); } // printf("\n"); delete map; } } #ifdef WIN32 while(_findnext( idhandle, &dta)!=-1); #else while ((de=readdir(dir))!=NULL); // po konci cyklu jeste zavrit adresar closedir(dir); #endif my_sort(this->mapsinfo[maptype],maptype); if (oldtype==maptype) // uz doslo k precislovani, napravim, aby index ukazoval na spravnou mapu { this->idofmap=-1; int i; for (i=this->mapsinfo[maptype]->getNext(-1);i!=-1;i=this->mapsinfo[maptype]->getNext(i)) { if (strcmp(fileofmap,(*this->mapsinfo[maptype])[i]->file)==0) // nasel jsem tu mapu, ktera byla nactena { this->idofmap=i; break; } } if (this->idofmap==-1) // nekdo napr. smazal mapu, ktera byla nactena { this->freeMap(); this->idofmap=0; // vynuluju this->unlock(); GLOBALLOGID(PRIORITY_FATAL,"RMmap the map being currently used was removed"); THROW(E_8K_RM,"RMmap the map being currently used was removed"); } } this->unlock(); } TRM_map::TRM_map(TRM_conf_i * rmc) // konstruktor nema smyl zamykat... { // this->kingdoms=(TKingdomInfo**) KMemAlloc(sizeof(TKingdomInfo*)*(1+MAX_KINGDOMS)); this->current_state=NULL; this->kingdoms=NULL; this->histhexs=NULL; this->mapsinfo[0]=NULL; // this->mapsinfo[0]=new DA ; // this->mapsinfo[1]=new DA ; this->mapsinfo[1]=NULL; this->hexs=NULL; this->hexnum=0; this->lbuildings=NULL; this->lunits=NULL; this->rmconfi=rmc; this->idofmap=-1; this->maploaded=0; this->cities=NULL; this->aiplan=NULL; GLOBALLOGID(PRIORITY_CONFIRM ,"RMmap was created"); } TRM_map::~TRM_map() { int k; int j; int i,ii; for (k=0;kmapsinfo[k]!=NULL) { for (j=this->mapsinfo[k]->getNext(-1);j!=-1;j=this->mapsinfo[k]->getNext(j)) { if ((*this->mapsinfo[k])[j]->roles!=NULL) { for (i=0;i!=(MAX_PLAYERS+1);i++) { if ((*this->mapsinfo[k])[j]->roles[i]!=NULL) { for (ii=0;ii!=(MAX_PLAYERS+1);ii++) { if ((*this->mapsinfo[k])[j]->roles[i]->relations[ii]!=NULL) { KMemFree((*this->mapsinfo[k])[j]->roles[i]->relations[ii]); } } KMemFree((*this->mapsinfo[k])[j]->roles[i]); } } // delete((*this->mapsinfo[maptype])[j]->roles); } KMemFree((*this->mapsinfo[k])[j]); } delete this->mapsinfo[k]; } } delete this->rmconfi; /* for (int j=this->maps->getNext(-1);j!=-1;j=this->maps->getNext(j)) { // if ((*(this->maps))[j]->mapname!=NULL) // KMemFree((*(this->maps))[j]->mapname); delete((*(this->maps))[j]); } delete this->maps;*/ this->freeMap(); // KMemFree(this->kingdoms); GLOBALLOGID(PRIORITY_CONFIRM ,"RMmap was destroyed"); } }