From a89b4e2c5965f1b9cbcc2a94e4b8d4968df92fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Thu, 7 Feb 2008 18:45:22 +0000 Subject: [PATCH] * [feature] giving starting hero * [feature] VCMI will try to use files from /Data folder instead of those from h3bitmap.lod * [feature] picked artifacts are added to hero's backpack --- CAdvmapInterface.cpp | 14 +++ CCallback.cpp | 26 ++++++ CCallback.h | 2 +- CLua.cpp | 5 ++ CMT.cpp | 13 ++- SDL_Extensions.cpp | 11 ++- hch/CObjectHandler.cpp | 5 ++ hch/CObjectHandler.h | 1 + hch/CTownHandler.cpp | 5 +- map.h | 28 +++--- mapHandler.cpp | 190 ++++++++++++++++++++++++----------------- mapHandler.h | 2 +- 12 files changed, 195 insertions(+), 107 deletions(-) diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 5d2af34a5..226e0bacc 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -281,6 +281,20 @@ void CTerrainRect::clickLeft(tribool down) { //move CPath sended(*currentPath); //temporary path - engine will operate on it mres = LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID,&sended,1,0); + if(!mres) + { + delete currentPath; + currentPath = NULL; + int i=0; + for(;iadventureInt->heroList.items.size();i++) + { + if(LOCPLINT->adventureInt->heroList.items[i].first->subID == ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID) + { + LOCPLINT->adventureInt->heroList.items[i].second = NULL; + break; + } + } + } } else { diff --git a/CCallback.cpp b/CCallback.cpp index b10971cef..946a6ab30 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -609,6 +609,32 @@ void CScriptCallback::stopHeroVisitCastle(CGObjectInstance * ob, int heroID) else return; } +void CScriptCallback::giveHeroArtifact(int artid, int hid, int position) //pos==-1 - first free slot in backpack +{ + CGHeroInstance* h = gs->getHero(hid,0); + if(position<0) + { + for(int i=0;iartifacts.size();i++) + { + if(!h->artifacts[i]) + { + h->artifacts[i] = &CGI->arth->artifacts[artid]; + return; + } + } + h->artifacts.push_back(&CGI->arth->artifacts[artid]); + return; + } + else + { + if(h->artifWorn[position]) //slot is occupied + { + giveHeroArtifact(h->artifWorn[position]->id,hid,-1); + } + h->artifWorn[position] = &CGI->arth->artifacts[artid]; + } +} + void CLuaCallback::registerFuncs(lua_State * L) { lua_newtable(L); diff --git a/CCallback.h b/CCallback.h index 47dce5ab0..9b238a67c 100644 --- a/CCallback.h +++ b/CCallback.h @@ -111,7 +111,7 @@ public: void showCompInfo(int player, SComponent * comp); void heroVisitCastle(CGObjectInstance * ob, int heroID); void stopHeroVisitCastle(CGObjectInstance * ob, int heroID); - + void giveHeroArtifact(int artid, int hid, int position); //pos==-1 - first free slot in backpack //friends friend void initGameState(CGameInfo * cgi); diff --git a/CLua.cpp b/CLua.cpp index a692e8e56..8ff3c6c55 100644 --- a/CLua.cpp +++ b/CLua.cpp @@ -478,6 +478,11 @@ void CPickable::onHeroVisit(CGObjectInstance *os, int heroID) { switch(os->ID) { + case 5: + { + cb->giveHeroArtifact(os->subID,heroID,-1); //TODO: na pozycje + break; + } case 79: { //TODO: handle guards (when battles are finished) diff --git a/CMT.cpp b/CMT.cpp index 5a541cbcd..e7d0813a9 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -120,7 +120,7 @@ void initGameState(CGameInfo * cgi) //*vhi=*(cgi->heroh->heroInstances[i]); CGHeroInstance * vhi = (cgi->heroh->heroInstances[i]); vhi->subID = vhi->type->ID; - if (!vhi->level) + if (vhi->level<1) { vhi->exp=40+rand()%50; vhi->level = 1; @@ -760,6 +760,17 @@ int _tmain(int argc, _TCHAR* argv[]) initTable[ss] = mapstr[ss]; } std::cout<<"done."<scenarioOps.playerInfos.size();pru++) + { + if(cgi->scenarioOps.playerInfos[pru].castle<0) + cgi->scenarioOps.playerInfos[pru].castle = rand()%F_NUMBER; + if(cgi->scenarioOps.playerInfos[pru].hero<0) + cgi->scenarioOps.playerInfos[pru].hero= cgi->scenarioOps.playerInfos[pru].castle*HEROES_PER_TYPE*2+(rand()%(HEROES_PER_TYPE*2));//cgi->scenarioOps.playerInfos[pru].hero = cgi-> + } + + + #define CHOOSE #ifdef CHOOSE CAmbarCendamo * ac = new CAmbarCendamo(initTable); //4gryf diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index 09f067058..d88d5296f 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -261,12 +261,12 @@ SDL_Surface * CSDL_Ext::hFlip(SDL_Surface * toRot) for(int j=0; jh; ++j) { { - Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j -1) * toRot->pitch + i * toRot->format->BytesPerPixel-2; - int k=2; + Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j -1) * toRot->pitch + i * toRot->format->BytesPerPixel; + //int k=2; #if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2], k); + CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2]); #else - CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0], k); + CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0]); #endif } } @@ -452,6 +452,9 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src) case 100: shadow.unused = 100+64; break; + case 125: + shadow.unused = 125+64; + break; case 128: shadow.unused = 128+64; break; diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 671cb603e..58dcf5dca 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -259,6 +259,11 @@ CGObjectInstance::~CGObjectInstance() // delete state; //state=NULL; } +CGHeroInstance::CGHeroInstance() +{ + level = exp = -1; + moveDir=4; +} CGHeroInstance::~CGHeroInstance() { diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 3c2f88919..f883a5b6a 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -367,6 +367,7 @@ public: bool canWalkOnSea() const; int getCurrentLuck() const; int getCurrentMorale() const; + CGHeroInstance(); virtual ~CGHeroInstance(); }; diff --git a/hch/CTownHandler.cpp b/hch/CTownHandler.cpp index 9151b74dd..e6accdd70 100644 --- a/hch/CTownHandler.cpp +++ b/hch/CTownHandler.cpp @@ -19,11 +19,12 @@ void CTownHandler::loadNames() ins.str(CGI->bitmaph->getTextFile("TOWNTYPE.TXT")); names.str(CGI->bitmaph->getTextFile("TOWNNAME.TXT")); int si=0; + char bufname[50]; while (!ins.eof()) { CTown town; - ins >> town.name; - char bufname[50]; + ins.getline(bufname,50); + town.name = std::string(bufname); for (int i=0; i heroesNames; bool hasMainTown; bool generateHeroAtMainTown; - Location posOfMainTown; + int3 posOfMainTown; int team; bool generateHero; }; struct LossCondition { ElossCon typeOfLossCon; - union - { - Location castlePos; - Location heroPos; - int timeLimit; // in days - }; + int3 castlePos; + int3 heroPos; + int timeLimit; // in days }; struct CspecificVictoryConidtions { @@ -121,26 +113,26 @@ struct VicCon2 : public CspecificVictoryConidtions // accumulate resources }; struct VicCon3 : public CspecificVictoryConidtions // upgrade specific town { - Location posOfCity; + int3 posOfCity; int councilNeededLevel; //0 - town; 1 - city; 2 - capitol int fortNeededLevel;// 0 - fort; 1 - citadel; 2 - castle }; struct VicCon4 : public CspecificVictoryConidtions // build grail structure { bool anyLocation; - Location whereBuildGrail; + int3 whereBuildGrail; }; struct VicCon5 : public CspecificVictoryConidtions // defeat a specific hero { - Location locationOfHero; + int3 locationOfHero; }; struct VicCon6 : public CspecificVictoryConidtions // capture a specific town { - Location locationOfTown; + int3 locationOfTown; }; struct VicCon7 : public CspecificVictoryConidtions // defeat a specific monster { - Location locationOfMonster; + int3 locationOfMonster; }; /*struct VicCon8 : public CspecificVictoryConidtions // flag all creature dwellings { @@ -151,7 +143,7 @@ struct VicCon9 : public CspecificVictoryConidtions // flag all mines struct VicCona : public CspecificVictoryConidtions //transport specific artifact { int artifactID; - Location destinationPlace; + int3 destinationPlace; }; struct Rumor { diff --git a/mapHandler.cpp b/mapHandler.cpp index 58f7a3c99..efdea3584 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -197,7 +197,7 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur) t->defInfo->handler = CGI->spriteh->giveDef(t->defInfo->name); alphaTransformDef(t->defInfo); } - CGI->townh->townInstances.push_back(t); + //CGI->townh->townInstances.push_back(t); return; } //we have to replace normal random object @@ -218,6 +218,8 @@ void CMapHandler::randomizeObjects() for(int no=0; noobjh->objInstances.size(); ++no) { randomizeObject(CGI->objh->objInstances[no]); + if(CGI->objh->objInstances[no]->ID==26) + CGI->objh->objInstances[no]->defInfo->handler=NULL; } } void CMapHandler::prepareFOWDefs() @@ -611,54 +613,66 @@ void CMapHandler::initObjectRects() continue; } CDefHandler * curd = CGI->objh->objInstances[f]->defInfo->handler; - for(int fx=0; fxourImages[0].bitmap->w>>5; ++fx) //curd->ourImages[0].bitmap->w/32 + if(curd) { - for(int fy=0; fyourImages[0].bitmap->h>>5; ++fy) //curd->ourImages[0].bitmap->h/32 + for(int fx=0; fxourImages[0].bitmap->w>>5; ++fx) //curd->ourImages[0].bitmap->w/32 { - SDL_Rect cr; - cr.w = 32; - cr.h = 32; - cr.x = fx<<5; //fx*32 - cr.y = fy<<5; //fy*32 - std::pair>>> toAdd = std::make_pair(CGI->objh->objInstances[f], std::make_pair(cr, std::vector>())); - ///initializing places that will be coloured by blitting (flag colour / player colour positions) - if(toAdd.first->defInfo->isVisitable()) + for(int fy=0; fyourImages[0].bitmap->h>>5; ++fy) //curd->ourImages[0].bitmap->h/32 { - toAdd.second.second.resize(toAdd.first->defInfo->handler->ourImages.size()); - for(int no = 0; nodefInfo->handler->ourImages.size(); ++no) + SDL_Rect cr; + cr.w = 32; + cr.h = 32; + cr.x = fx<<5; //fx*32 + cr.y = fy<<5; //fy*32 + std::pair>>> toAdd = std::make_pair(CGI->objh->objInstances[f], std::make_pair(cr, std::vector>())); + ///initializing places that will be coloured by blitting (flag colour / player colour positions) + if(toAdd.first->defInfo->isVisitable()) { - bool breakNow = true; - for(int dx=0; dx<32; ++dx) + SDL_Rect cr; + cr.w = 32; + cr.h = 32; + cr.x = fx*32; + cr.y = fy*32; + std::pair > > > toAdd = std::make_pair(CGI->objh->objInstances[f], std::make_pair(cr, std::vector>())); + ///initializing places that will be coloured by blitting (flag colour / player colour positions) + if(toAdd.first->defInfo->isVisitable() && toAdd.first->defInfo->handler->ourImages[0].bitmap->format->BitsPerPixel!=8) { - for(int dy=0; dy<32; ++dy) + toAdd.second.second.resize(toAdd.first->defInfo->handler->ourImages.size()); + for(int no = 0; nodefInfo->handler->ourImages.size(); ++no) { - SDL_Surface * curs = toAdd.first->defInfo->handler->ourImages[no].bitmap; - Uint32* point = (Uint32*)( (Uint8*)curs->pixels + curs->pitch * (fy*32+dy) + curs->format->BytesPerPixel*(fx*32+dx)); - Uint8 r, g, b, a; - SDL_GetRGBA(*point, curs->format, &r, &g, &b, &a); - if(r==255 && g==255 && b==0) + bool breakNow = true; + for(int dx=0; dx<32; ++dx) { - toAdd.second.second[no].push_back(int3((fx*32+dx), (fy*32+dy), 0)); - breakNow = false; + for(int dy=0; dy<32; ++dy) + { + SDL_Surface * curs = toAdd.first->defInfo->handler->ourImages[no].bitmap; + Uint32* point = (Uint32*)( (Uint8*)curs->pixels + curs->pitch * (fy*32+dy) + curs->format->BytesPerPixel*(fx*32+dx)); + Uint8 r, g, b, a; + SDL_GetRGBA(*point, curs->format, &r, &g, &b, &a); + if(r==255 && g==255 && b==0) + { + toAdd.second.second[no].push_back(int3((fx*32+dx), (fy*32+dy), 0)); + breakNow = false; + } + } } + if(breakNow) + break; } } - if(breakNow) - break; } - } - if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32] - //[CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32] - //[CGI->objh->objInstances[f]->pos.z]; - ttiles[CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][CGI->objh->objInstances[f]->pos.z].objects.push_back(toAdd); - } - - } // for(int fy=0; fyourImages[0].bitmap->h/32; ++fy) - } //for(int fx=0; fxourImages[0].bitmap->w/32; ++fx) + if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32] + //[CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32] + //[CGI->objh->objInstances[f]->pos.z]; + ttiles[CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][CGI->objh->objInstances[f]->pos.z].objects.push_back(toAdd); + } + } // for(int fy=0; fyourImages[0].bitmap->h/32; ++fy) + } //for(int fx=0; fxourImages[0].bitmap->w/32; ++fx) + }//if curd } // for(int f=0; fobjh->objInstances.size(); ++f) for(int ix=0; ixmap.players[i].generateHeroAtMainTown && reader->map.players[i].hasMainTown) + { + int3 hpos = reader->map.players[i].posOfMainTown; + hpos.x+=1; hpos.y+=1; + int j; + for(j=0;jscenarioOps.playerInfos.size();j++) + if(CGI->scenarioOps.playerInfos[j].color==i) + break; + if(j==CGI->scenarioOps.playerInfos.size()) + continue; + CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,CGI->scenarioOps.playerInfos[j].hero,hpos,i); + nnn->defInfo->handler = CGI->heroh->flags1[0]; + CGI->heroh->heroInstances.push_back(nnn); + CGI->objh->objInstances.push_back(nnn); + } + } + initObjectRects(); std::cout<<"\tMaking object rects: "<info)->myInstance->type==NULL) + if(themp->type==NULL) continue; - std::vector & iv = ((CHeroObjInfo*)themp->info)->myInstance->type->heroClass->moveAnim->ourImages; + std::vector & iv = themp->type->heroClass->moveAnim->ourImages; switch(themp->moveDir) { case 1: @@ -960,9 +994,9 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, int imgVal = 8; SDL_Surface * tb; - if(((CHeroObjInfo*)themp->info)->myInstance->type==NULL) + if(themp->type==NULL) continue; - std::vector & iv = ((CHeroObjInfo*)themp->info)->myInstance->type->heroClass->moveAnim->ourImages; + std::vector & iv = themp->type->heroClass->moveAnim->ourImages; switch(themp->moveDir) { case 1: @@ -1589,65 +1623,61 @@ std::vector < CGObjectInstance * > CMapHandler::getVisitableObjs(int3 pos) return ret; } -CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos) +CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos, int owner) { CGObjectInstance * nobj; switch(id) { - case 43: //hero - nobj = new CGHeroInstance; - break; + case 34: //hero + { + CGHeroInstance * nobj; + nobj = new CGHeroInstance(); + nobj->pos = pos; + nobj->tempOwner = owner; + nobj->defInfo = new CGDefInfo(); + nobj->defInfo->id = 34; + nobj->defInfo->subid = subid; + nobj->type = CGI->heroh->heroes[subid]; + for(int i=0;i<6;i++) + { + nobj->defInfo->blockMap[i]=1; + nobj->defInfo->visitMap[i]=0; + } + nobj->ID = id; + nobj->subID = subid; + nobj->defInfo->handler=NULL; + nobj->defInfo->blockMap[5] = 0x7f; + nobj->defInfo->visitMap[5] = 0x80; + nobj->artifWorn.resize(20); + nobj->artifacts.resize(20); + nobj->artifWorn[16] = &CGI->arth->artifacts[3]; + return nobj; + } case 98: //town nobj = new CGTownInstance; break; default: //rest of objects nobj = new CGObjectInstance; + nobj->defInfo = CGI->dobjinfo->gobjs[id][subid]; break; } nobj->ID = id; nobj->subID = subid; - nobj->defInfo = CGI->dobjinfo->gobjs[id][subid]; if(!nobj->defInfo) std::cout <<"No def declaration for " <dobjinfo->objs.size(); ++f) - { - if(CGI->dobjinfo->objs[f].type==id && CGI->dobjinfo->objs[f].subtype == subid) - { - defObjInfoNumber = f; - break; - } - } - nobj->defInfo->name = CGI->dobjinfo->objs[defObjInfoNumber].defName; - for(int g=0; g<6; ++g) - nobj->defInfo->blockMap[g] = CGI->dobjinfo->objs[defObjInfoNumber].blockMap[g]; - for(int g=0; g<6; ++g) - nobj->defInfo->visitMap[g] = CGI->dobjinfo->objs[nobj->defObjInfoNumber].visitMap[g]; - nobj->defInfo->printPriority = CGI->dobjinfo->objs[nobj->defObjInfoNumber].priority;*/ nobj->pos = pos; //nobj->state = NULL;//new CLuaObjectScript(); - nobj->tempOwner = 254; + nobj->tempOwner = owner; nobj->info = NULL; nobj->defInfo->id = id; nobj->defInfo->subid = subid; //assigning defhandler - - std::string ourName = getDefName(id, subid); - std::transform(ourName.begin(), ourName.end(), ourName.begin(), (int(*)(int))toupper); - nobj->defInfo->name = ourName; - - if(loadedDefs[ourName] == NULL) - { - nobj->defInfo->handler = CGI->spriteh->giveDef(ourName); - loadedDefs[ourName] = nobj->defInfo->handler; - } - else - { - nobj->defInfo->handler = loadedDefs[ourName]; - } - + if(nobj->ID==34 || nobj->ID==98) + return nobj; + nobj->defInfo = CGI->dobjinfo->gobjs[id][subid]; + if(!nobj->defInfo->handler) + nobj->defInfo->handler = CGI->spriteh->giveDef(nobj->defInfo->name); return nobj; } diff --git a/mapHandler.h b/mapHandler.h index a361fc0e9..e2adb51e6 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -84,7 +84,7 @@ public: int getCost(int3 & a, int3 & b, const CGHeroInstance * hero); std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position - CGObjectInstance * createObject(int id, int subid, int3 pos); //creates a new object with a certain id and subid + CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid std::string getDefName(int id, int subid); //returns name of def for object with given id and subid bool printObject(CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map bool hideObject(CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)