diff --git a/AdventureMapButton.h b/AdventureMapButton.h index 8b4510e82..129f8ba94 100644 --- a/AdventureMapButton.h +++ b/AdventureMapButton.h @@ -419,7 +419,7 @@ void CSlider::sliderClicked() template void CSlider::mouseMoved (SDL_MouseMotionEvent & sEvent) { - float v = sEvent.x - pos.x - 16; + float v = sEvent.x - pos.x - 24; v/= (pos.w - 48); v*=amount; if(v!=value) diff --git a/CCallback.cpp b/CCallback.cpp index c1075d554..c8131ed0b 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -659,10 +659,22 @@ bool CCallback::buildBuilding(const CGTownInstance *town, int buildingID) { CGTownInstance * t = const_cast(town); CBuilding *b = CGI->buildh->buildings[t->subID][buildingID]; - + if(0/*not allowed*/)//TODO: check if we are allowed to build return false; + if(buildingID>36) //upg dwelling + { + if(t->getHordeLevel(0) == (buildingID-37)) + t->builtBuildings.insert(19); + else if(t->getHordeLevel(1) == (buildingID-37)) + t->builtBuildings.insert(25); + } + else if(buildingID >= 30) //bas. dwelling + { + t->strInfo.creatures[buildingID-30] = CGI->creh->creatures[t->town->basicCreatures[buildingID-30]].growth; + } + t->builtBuildings.insert(buildingID); for(int i=0;i<7;i++) gs->players[player].resources[i]-=b->resources[i]; @@ -768,7 +780,24 @@ void CScriptCallback::changePrimSkill(int ID, int which, int val) else if (which==4) { hero->exp+=val; - std::cout << "Bohater o ID " << ID <<" (" <heroh->heroes[ID]->name <<") dostaje "<exp >= CGI->heroh->reqExp(hero->level+1)) //new level + { + hero->level++; + std::cout << hero->name <<" got level "<level<::*g=hero->level>9?&std::pair::second:&std::pair::first; + for(;xtype->heroClass->primChance[x].*g; + if(rprimSkills[x]++; + + //TODO: dac dwie umiejetnosci 2-rzedne to wyboru + + } //TODO - powiadomic interfejsy, sprawdzic czy nie ma awansu itp } } diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index f0b42f9fd..80d3df06d 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -314,16 +314,26 @@ void CCastleInterface::splitF() void CCastleInterface::buildingClicked(int building) { std::cout<<"You've clicked on "<town->hordeLvl[0] + 30; + } + else if(building==24 || building==25) + { + building = town->town->hordeLvl[1] + 30; + } if(building >= 30) { if(building>36) building-=7; std::vector > crs; int amount = (const_cast(town))->strInfo.creatures[building-30]; //trzeba odconstowac, bo inaczej operator [] by sypal :( - crs.push_back(std::make_pair(town->town->basicCreatures[building-30],amount)); if(town->builtBuildings.find(building+7) != town->builtBuildings.end()) //check if there is an upgraded building crs.push_back(std::make_pair(town->town->upgradedCreatures[building-30],amount)); + + crs.push_back(std::make_pair(town->town->basicCreatures[building-30],amount)); + CRecrutationWindow *rw = new CRecrutationWindow(crs,this); rw->activate(); } @@ -488,13 +498,13 @@ void CCastleInterface::deactivate() void CCastleInterface::addBuilding(int bid) { - //TODO: lepiej by bylo tylko dodawac/usuwac co trzeba pamietajac o grupach + //TODO: lepiej by bylo tylko dodawac co trzeba pamietajac o grupach recreateBuildings(); } void CCastleInterface::removeBuilding(int bid) { - //TODO: lepiej by bylo tylko dodawac/usuwac co trzeba pamietajac o grupach + //TODO: lepiej by bylo tylko usuwac co trzeba pamietajac o grupach recreateBuildings(); } diff --git a/CMT.cpp b/CMT.cpp index 7005853da..f434afd01 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -152,26 +152,33 @@ void initGameState(CGameInfo * cgi) vhi->portrait = vhi->type->ID; //initial army - if (!vhi->army.slots.size()) + if (!vhi->army.slots.size()) //standard army { - int pom; - vhi->army.slots[0].first = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType1stack])]); - if((pom = (vhi->type->high1stack-vhi->type->low1stack)) > 0) - vhi->army.slots[0].second = (rand()%pom)+vhi->type->low1stack; - else - vhi->army.slots[0].second = +vhi->type->low1stack; - - vhi->army.slots[1].first = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType2stack])]); - if((pom=(vhi->type->high2stack-vhi->type->low2stack))>0) - vhi->army.slots[1].second = (rand()%pom)+vhi->type->low2stack; - else - vhi->army.slots[1].second = vhi->type->low2stack; - - vhi->army.slots[2].first = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType3stack])]); - if((pom=(vhi->type->high3stack-vhi->type->low3stack))>0) - vhi->army.slots[2].second = (rand()%pom)+vhi->type->low3stack; - else - vhi->army.slots[2].second = vhi->type->low3stack; + int pom, pom2=0; + for(int x=0;x<3;x++) + { + pom = (cgi->creh->nameToID[vhi->type->refTypeStack[x]]); + if(pom>=145 && pom<=149) //war machine + { + pom2++; + switch (pom) + { + case 145: //catapult + vhi->artifWorn[16] = &CGI->arth->artifacts[3]; + break; + default: + pom-=145; + vhi->artifWorn[13+pom] = &CGI->arth->artifacts[4+pom]; + break; + } + continue; + } + vhi->army.slots[x-pom2].first = &(cgi->creh->creatures[pom]); + if((pom = (vhi->type->highStack[x]-vhi->type->lowStack[x])) > 0) + vhi->army.slots[x-pom2].second = (rand()%pom)+vhi->type->lowStack[x]; + else + vhi->army.slots[x-pom2].second = +vhi->type->lowStack[x]; + } } cgi->state->players[vhi->getOwner()].heroes.push_back(vhi); diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 4431d5e7d..d1717f32b 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -2572,6 +2572,7 @@ CSplitWindow::CSplitWindow(int cid, int max, CGarrisonInt *Owner) slider = NULL; gar = Owner; bitmap = CGI->bitmaph->loadBitmap("GPUCRDIV.bmp"); + SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255)); pos.x = screen->w/2 - bitmap->w/2; pos.y = screen->h/2 - bitmap->h/2; pos.w = bitmap->w; @@ -2650,4 +2651,4 @@ void CSplitWindow::show(SDL_Surface * to) void CSplitWindow::keyPressed (SDL_KeyboardEvent & key) { //TODO: zeby sie dalo recznie wpisywac -} \ No newline at end of file +} diff --git a/config/creatures_upgr.txt b/config/creatures_upgr.txt index 045b78cbe..f6619db25 100644 --- a/config/creatures_upgr.txt +++ b/config/creatures_upgr.txt @@ -49,9 +49,9 @@ 6 6 97 7 0 99 7 1 101 -7 2 103 -7 3 105 -7 4 107 +7 2 105 +7 3 107 +7 4 103 7 5 109 7 6 111 8 0 119 diff --git a/config/crerefnam.txt b/config/crerefnam.txt index 52bb70802..338d9a7ba 100644 --- a/config/crerefnam.txt +++ b/config/crerefnam.txt @@ -146,7 +146,7 @@ 144 OgreShaman 145 Catapult 146 Ballista -147 First-AidTent +147 FirstAidTent 148 AmmoCart 149 ArrowTower 150 SupremeArchangel diff --git a/global.h b/global.h index 9b6f19b66..a785e85c5 100644 --- a/global.h +++ b/global.h @@ -50,6 +50,7 @@ const int F_NUMBER = 9; //factions (town types) quantity const int PLAYER_LIMIT = 8; //player limit per map const int HEROES_PER_TYPE=8; //amount of heroes of each type const int SKILL_QUANTITY=28; +const int SKILL_PER_HERO=8; const int ARTIFACTS_QUANTITY=171; const int HEROES_QUANTITY=156; const int RESOURCE_QUANTITY=8; diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index ceaebd25b..6be8f39e8 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -109,23 +109,14 @@ void CHeroHandler::loadHeroes() std::string pom ; CGeneralTextHandler::loadToIt(nher->name,buf,it,4); - CGeneralTextHandler::loadToIt(pom,buf,it,4); - nher->low1stack = atoi(pom.c_str()); - CGeneralTextHandler::loadToIt(pom,buf,it,4); - nher->high1stack = atoi(pom.c_str()); - CGeneralTextHandler::loadToIt(nher->refType1stack,buf,it,4); - - CGeneralTextHandler::loadToIt(pom,buf,it,4); - nher->low2stack = atoi(pom.c_str()); - CGeneralTextHandler::loadToIt(pom,buf,it,4); - nher->high2stack = atoi(pom.c_str()); - CGeneralTextHandler::loadToIt(nher->refType2stack,buf,it,4); - - CGeneralTextHandler::loadToIt(pom,buf,it,4); - nher->low3stack = atoi(pom.c_str()); - CGeneralTextHandler::loadToIt(pom,buf,it,4); - nher->high3stack = atoi(pom.c_str()); - CGeneralTextHandler::loadToIt(nher->refType3stack,buf,it,3); + for(int x=0;x<3;x++) + { + CGeneralTextHandler::loadToIt(pom,buf,it,4); + nher->lowStack[x] = atoi(pom.c_str()); + CGeneralTextHandler::loadToIt(pom,buf,it,4); + nher->highStack[x] = atoi(pom.c_str()); + CGeneralTextHandler::loadToIt(nher->refTypeStack[x],buf,it,(x==2) ? (3) : (4)); + } nher->ID = heroes.size(); heroes.push_back(nher); @@ -253,77 +244,29 @@ void CHeroHandler::loadHeroClasses() hc->initialKnowledge = atoi(buf.substr(befi, i-befi).c_str()); ++i; - befi=i; - for(i; iprimChance.resize(PRIMARY_SKILLS); + for(int x=0;xprimChance[x].first = atoi(buf.substr(befi, i-befi).c_str()); + ++i; } - hc->proAttack[0] = atoi(buf.substr(befi, i-befi).c_str()); - ++i; - - befi=i; - for(i; iprimChance[x].second = atoi(buf.substr(befi, i-befi).c_str()); + ++i; } - hc->proDefence[0] = atoi(buf.substr(befi, i-befi).c_str()); - ++i; - - befi=i; - for(i; iproPower[0] = atoi(buf.substr(befi, i-befi).c_str()); - ++i; - - befi=i; - for(i; iproKnowledge[0] = atoi(buf.substr(befi, i-befi).c_str()); - ++i; - - befi=i; - for(i; iproAttack[1] = atoi(buf.substr(befi, i-befi).c_str()); - ++i; - - befi=i; - for(i; iproDefence[1] = atoi(buf.substr(befi, i-befi).c_str()); - ++i; - - befi=i; - for(i; iproPower[1] = atoi(buf.substr(befi, i-befi).c_str()); - ++i; - - befi=i; - for(i; iproKnowledge[1] = atoi(buf.substr(befi, i-befi).c_str()); - ++i; //CHero kkk = heroes[0]; diff --git a/hch/CHeroHandler.h b/hch/CHeroHandler.h index c0cbaad7d..9cb6b3f8b 100644 --- a/hch/CHeroHandler.h +++ b/hch/CHeroHandler.h @@ -18,8 +18,8 @@ class CHero public: std::string name; int ID; - int low1stack, high1stack, low2stack, high2stack, low3stack, high3stack; //amount of units; described below - std::string refType1stack, refType2stack, refType3stack; //reference names of units appearing in hero's army if he is recruited in tavern + int lowStack[3], highStack[3]; //amount of units; described below + std::string refTypeStack[3]; //reference names of units appearing in hero's army if he is recruited in tavern std::string bonusName, shortBonus, longBonus; //for special abilities std::string biography; //biography, of course bool isAllowed; //true if we can play with this hero (depends on map) @@ -36,10 +36,7 @@ public: std::string name; float aggression; int initialAttack, initialDefence, initialPower, initialKnowledge; - int proAttack[2]; //probability of gaining attack point on levels [0]: 2 - 9; [1]: 10+ (out of 100) - int proDefence[2]; //probability of gaining defence point on levels [0]: 2 - 9; [1]: 10+ (out of 100) - int proPower[2]; //probability of gaining power point on levels [0]: 2 - 9; [1]: 10+ (out of 100) - int proKnowledge[2]; //probability of gaining knowledge point on levels [0]: 2 - 9; [1]: 10+ (out of 100) + std::vector > primChance;//primChance[PRIMARY_SKILL_ID] - first is for levels 2 - 9, second for 10+;;; probability (%) of getting point of primary skill when getting new level std::vector proSec; //probabilities of gaining secondary skills (out of 112), in id order int selectionProbability[9]; //probability of selection in towns std::vector terrCosts; //default costs of going through terrains: dirt, sand, grass, snow, swamp, rough, subterrain, lava, water, rock; -1 means terrain is imapassable diff --git a/hch/CLodHandler.cpp b/hch/CLodHandler.cpp index 257d154ad..f85394d55 100644 --- a/hch/CLodHandler.cpp +++ b/hch/CLodHandler.cpp @@ -252,6 +252,53 @@ SDL_Surface * CPCXConv::getSurface() } return ret; } +SDL_Surface * CPCXConv::getSurfaceZ() +{ + //int i=1; + //int type = pcx[i];i+=2;//0 -- Version 2.5 2 -- Version 2.8, palette included 3 -- Version 2.8, use default palette 5 -- Version 3.0 or better + //int bpp = pcx[3];i++; + //int xmin, ymin, xmax, ymax, w, h; + //xmin = readNormalNr(i,2,pcx);i+=2; + //ymin = readNormalNr(i,2,pcx);i+=2; + //xmax = readNormalNr(i,2,pcx);i+=2; + //ymax = readNormalNr(i,2,pcx);i+=2; + //w = xmax - xmin + 1; h = ymax - ymin + 1; + //i+=4; //DPI is not interesting + //char palette[48]; + //memcpy(palette,pcx+i,48); i+=48; + //int reserved = pcx[i++]; + //int planes = pcx[i++]; + //int bytesPerLine = readNormalNr(i,2,pcx);i+=2; + //i = 128; //to the end of header + //int totalBytes = planes * bytesPerLine; + //int padding = ((bytesPerLine * planes) * (8 / bpp)) - ((xmax - xmin) + 1); + //char * buffer = new char[totalBytes]; + //int index = 0, count, value, total=0; + //do + //{ + // count=0; value=0; + // unsigned char byte = pcx[i++]; + // if((byte & 0xC0) == 0xC0) //two top bits set + // { + // count = byte & 0x3f; + // value = pcx[i++]; + // } + // else + // { + // count = 1; + // value = byte; + // } + // for(total+=count; count && (index < totalBytes); index++) + // { + // buffer[index] = value; + // count--; + // } + //} while(indexrealSize]; + memcpy(pcx,sign,3); + int res = fread((char*)pcx+3, 1, e->realSize-3, f); + fclose(f); + cp.openPCX((char*)pcx,e->realSize); + if((sign[0]==10) && (sign[1]<6) && (sign[2]==1)) //ZSoft PCX + { + return cp.getSurfaceZ(); + } + else //H3 PCX + { + return cp.getSurface(); + } + } + } } fseek(FLOD, e->offset, 0); if (e->size==0) //file is not compressed diff --git a/hch/CLodHandler.h b/hch/CLodHandler.h index 30dd02e4f..10e691bce 100644 --- a/hch/CLodHandler.h +++ b/hch/CLodHandler.h @@ -53,7 +53,8 @@ public: void openPCX(char * PCX, int len); void openPCX(); void convert(); - SDL_Surface * getSurface(); + SDL_Surface * getSurface(); //for standard H3 PCX + SDL_Surface * getSurfaceZ(); //for ZSoft PCX CPCXConv(){pcx=bmp=NULL;pcxs=bmps=0;}; ~CPCXConv(){if (pcxs) delete[] pcx; if(bmps) delete[] bmp;} }; diff --git a/hch/CMusicHandler.cpp b/hch/CMusicHandler.cpp index f771b8871..16a45f0d6 100644 --- a/hch/CMusicHandler.cpp +++ b/hch/CMusicHandler.cpp @@ -5,8 +5,10 @@ void CMusicHandler::initMusics() { if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096)==-1) { - printf("Mix_OpenAudio: %s\n", Mix_GetError()); - exit(2); + printf("Mix_OpenAudio error: %s!!!\n", Mix_GetError()); + //exit(2); + sndh = NULL; + return; } atexit(Mix_CloseAudio); @@ -61,6 +63,7 @@ void CMusicHandler::initMusics() void CMusicHandler::playClick() { + if(!sndh) return; int channel; channel = Mix_PlayChannel(-1, click, 0); if(channel == -1) @@ -71,6 +74,7 @@ void CMusicHandler::playClick() void CMusicHandler::playLodSnd(std::string sndname) { + if(!sndh) return; int size; unsigned char *data; SDL_RWops *ops; diff --git a/mapHandler.cpp b/mapHandler.cpp index fa605a313..6ede774ff 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -209,7 +209,24 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur) { std::pair ran = pickObject(cur); if(ran.first<0 || ran.second<0) //this is not a random object, or we couldn't find anything + { + if(cur->ID==98) //town - set def + { + CGTownInstance *t = dynamic_cast(cur); + if(t->hasCapitol()) + t->defInfo = capitols[t->subID]; + else if(t->hasFort()) + t->defInfo = CGI->dobjinfo->castles[t->subID]; + else + t->defInfo = villages[t->subID]; + if(!t->defInfo->handler) + { + t->defInfo->handler = CGI->spriteh->giveDef(t->defInfo->name); + alphaTransformDef(t->defInfo); + } + } return; + } else if(ran.first==34)//special code for hero { CGHeroInstance *h = dynamic_cast(cur);