diff --git a/AI/EmptyAI/CEmptyAI.cpp b/AI/EmptyAI/CEmptyAI.cpp index 2c874bdc9..2a8eab8f0 100644 --- a/AI/EmptyAI/CEmptyAI.cpp +++ b/AI/EmptyAI/CEmptyAI.cpp @@ -4,8 +4,8 @@ void CEmptyAI::init(CCallback * CB) { cb = CB; human=false; - playerID=-1; - serialID=-1; + playerID=cb->getMyColor(); + serialID=cb->getMySerial(); std::cout << "EmptyAI initialized." << std::endl; } void CEmptyAI::yourTurn() diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 5d0e55274..4e105e5c2 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -1299,6 +1299,7 @@ void CAdvMapInt::show() townList.activate(); townList.draw(); terrain.activate(); + update(); resdatabar.draw(); @@ -1376,7 +1377,11 @@ void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * c { for (int i=0;iobjsToBlit.size();i++) { - if (LOCPLINT->objsToBlit[i]->owner==client) + //TODO: pewnie da sie to zrobic lepiej, ale nie chce mi sie. Wolajacy obiekt powinien informowac kogo spodziewa sie odwolac (null jesli down) + CSimpleWindow * pom = dynamic_cast(LOCPLINT->objsToBlit[i]); + if (!pom) + continue; + if (pom->owner==client) { LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+(i)); } diff --git a/CCallback.cpp b/CCallback.cpp index 4cef039ec..0e4c7806c 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -125,6 +125,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) if (!blockvis) { curd.successful = true; + hero->pos = curd.dst; int heroSight = hero->getSightDistance(); int xbeg = stpos.x - heroSight - 2; @@ -154,7 +155,6 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) } } - hero->pos = curd.dst; int nn=0; //number of interfece of currently browsed player for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing { @@ -174,7 +174,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) vis[iii]->state->onHeroVisit(vis[iii],curd.ho->subID); } } - else + else //interaction with blocking object (like resources) { curd.successful = false; CGI->playerint[gs->players[hero->getOwner()].serial]->heroMoved(curd); @@ -194,7 +194,6 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) } else return true; //move ended - no more movement points - //hero->pos = curd.dst; } return true; } @@ -245,7 +244,7 @@ const CGHeroInstance * CCallback::getHeroInfo(int player, int val, bool mode) // int CCallback::getResourceAmount(int type) { - return gs->players[gs->currentPlayer].resources[type]; + return gs->players[player].resources[type]; } int CCallback::getDate(int mode) @@ -347,6 +346,14 @@ bool CCallback::isVisible(int3 pos) return isVisible(pos,player); } +int CCallback::getMyColor() +{ + return player; +} +int CCallback::getMySerial() +{ + return gs->players[player].serial; +} int3 CScriptCallback::getPos(CGObjectInstance * ob) diff --git a/CCallback.h b/CCallback.h index 1be0da37d..5b8776433 100644 --- a/CCallback.h +++ b/CCallback.h @@ -48,6 +48,8 @@ public: std::vector < std::string > getObjDescriptions(int3 pos); //returns descriptions of objects at pos in order from the lowest to the highest std::vector < const CGHeroInstance *> * getHeroesInfo(bool onlyOur=true); bool isVisible(int3 pos); + int getMyColor(); + int getMySerial(); //friends friend int _tmain(int argc, _TCHAR* argv[]); diff --git a/CMessage.cpp b/CMessage.cpp index 21a754ac9..75df9165a 100644 --- a/CMessage.cpp +++ b/CMessage.cpp @@ -200,7 +200,47 @@ std::pair CMessage::getMaxSizes(std::vector > } return ret; } +SDL_Surface * CMessage::blitTextOnSur(std::vector > * txtg, int & curh, SDL_Surface * ret) +{ + for (int i=0; isize();i++) + { + int lw=0; + for (int j=0;j<(*txtg)[i].size();j++) + lw+=(*txtg)[i][j]->w; //lw - laczna szerokosc linii + int pw = ret->w/2; + pw -= lw/2; //poczatek tekstu (x) + int tw = pw; + for (int j=0;j<(*txtg)[i].size();j++) //blit text + { + blitAt((*txtg)[i][j],tw,curh+i*19,ret); + tw+=(*txtg)[i][j]->w; + SDL_FreeSurface((*txtg)[i][j]); + } + } + return ret; +} +SDL_Surface * CMessage::blitCompsOnSur(std::vector & comps, int maxw, int inter, int & curh, SDL_Surface * ret) +{ + std::vector * brdtext; + if (comps.size()) + brdtext = breakText(comps[0]->subtitle,12,true,true); + else + brdtext = NULL; + curh += 30; + comps[0]->pos.x = (ret->w/2) - ((comps[0]->getImg()->w)/2); + comps[0]->pos.y = curh; + blitAt(comps[0]->getImg(),comps[0]->pos.x,comps[0]->pos.y,ret); + curh += comps[0]->getImg()->h + 5; //obrazek + przerwa + for (int i=0; isize();i++) //descr. + { + SDL_Surface * tesu = TTF_RenderText_Blended(GEOR13,(*brdtext)[i].c_str(),zwykly); + blitAt(tesu,((comps[0]->getImg()->w - tesu->w)/2)+comps[0]->pos.x,curh,ret); + curh+=tesu->h; + SDL_FreeSurface(tesu); + } + return ret; +} std::vector > * CMessage::drawText(std::vector * brtext) { std::vector > * txtg = new std::vector >(); @@ -276,14 +316,7 @@ CInfoWindow * CMessage::genIWindow(std::string text, int player, int charperline //TODO: support for more than one component CInfoWindow * ret = new CInfoWindow(); ret->components = comps; - //for (int i=0;i std::vector * brtext = breakText(text,charperline,true,true); - std::vector * brdtext; - if (comps.size()) - brdtext = breakText(comps[0]->subtitle,12,true,true); - else - brdtext = NULL; std::vector > * txtg = drawText(brtext); std::pair txts = getMaxSizes(txtg); txts.second = txts.second @@ -295,50 +328,19 @@ CInfoWindow * CMessage::genIWindow(std::string text, int player, int charperline + 30 //space to first component + comps[0]->getImg()->h + 5 //img <-> subtitle - + brdtext->size() * 10; //subtitle //!!!!!!!!!!!!!!!!!!!! + + 20; //subtitle //!!!!!!!!!!!!!!!!!!!! ret->bitmap = drawBox1(txts.first+70,txts.second+70,0); ret->pos.h=ret->bitmap->h; ret->pos.w=ret->bitmap->w; int curh = 30; //gorny margines - for (int i=0; isize();i++) - { - int lw=0; - for (int j=0;j<(*txtg)[i].size();j++) - lw+=(*txtg)[i][j]->w; - int pw = ret->bitmap->w/2; - //int pw = Tmar, ph = Lmar; - pw -= lw/2; - - int tw = pw; - for (int j=0;j<(*txtg)[i].size();j++) //blit text - { - //std::stringstream n; - //n <<"temp_"<bitmap,n.str().c_str()); - blitAt((*txtg)[i][j],tw,curh+i*19,ret->bitmap); - tw+=(*txtg)[i][j]->w; - SDL_FreeSurface((*txtg)[i][j]); - } - } + blitTextOnSur(txtg,curh,ret->bitmap); curh += (19 * txtg->size()); //wys. tekstu if (comps.size()) { - curh += 30; - comps[0]->pos.x = (ret->bitmap->w/2) - ((comps[0]->getImg()->w)/2); - comps[0]->pos.y = curh; - blitAt(comps[0]->getImg(),comps[0]->pos.x,comps[0]->pos.y,ret->bitmap); - curh += comps[0]->getImg()->h + 5; //obrazek + przerwa - for (int i=0; isize();i++) //descr. - { - SDL_Surface * tesu = TTF_RenderText_Blended(GEOR13,(*brdtext)[i].c_str(),zwykly); - blitAt(tesu,((comps[0]->getImg()->w - tesu->w)/2)+comps[0]->pos.x,curh,ret->bitmap); - curh+=tesu->h; - SDL_FreeSurface(tesu); - } + blitCompsOnSur(comps,200,0,curh,ret->bitmap); } - curh += 20; //to buttton ret->okb.posr.x = (ret->bitmap->w/2) - (ret->okb.imgs[0][0]->w/2); diff --git a/CMessage.h b/CMessage.h index 8246d2894..708c000bf 100644 --- a/CMessage.h +++ b/CMessage.h @@ -24,6 +24,8 @@ public: static std::pair getMaxSizes(std::vector > * txtg); static std::vector > * drawText(std::vector * brtext); + static SDL_Surface * blitTextOnSur(std::vector > * txtg, int & curh, SDL_Surface * ret); + static SDL_Surface * blitCompsOnSur(std::vector & comps, int maxw, int inter, int & curh, SDL_Surface * ret); static CInfoWindow * genIWindow(std::string text, int player, int charperline, std::vector & comps); static CSimpleWindow * genWindow(std::string text, int player, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly, diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 72f6c7627..9ae993ce2 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -107,6 +107,12 @@ void SComponent::deactivate() { ClickableR::deactivate(); } +void CSimpleWindow::show(SDL_Surface * to) +{ + if(!to) + to=ekran; + blitAt(bitmap,pos.x,pos.y,to); +} CSimpleWindow::~CSimpleWindow() { if (bitmap) @@ -154,16 +160,16 @@ template void CSCButton::deactivate() ClickableL::deactivate(); } -template void CSCButton::show() +template void CSCButton::show(SDL_Surface * to) { - if (delg) + if (delg) //we blit on our owner's bitmap { blitAt(imgs[curimg][state],posr.x,posr.y,delg->bitmap); updateRect(&genRect(pos.h,pos.w,posr.x,posr.y),delg->bitmap); } else { - CButtonBase::show(); + CButtonBase::show(to); } } CButtonBase::CButtonBase() @@ -175,17 +181,19 @@ CButtonBase::CButtonBase() ourObj=NULL; state=0; } -void CButtonBase::show() +void CButtonBase::show(SDL_Surface * to) { + if(!to) + to=ekran; if (abs) { - blitAt(imgs[curimg][state],pos.x,pos.y); - updateRect(&pos); + blitAt(imgs[curimg][state],pos.x,pos.y,to); + updateRect(&pos,to); } else { - blitAt(imgs[curimg][state],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y); - updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y)); + blitAt(imgs[curimg][state],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to); + updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y),to); } } @@ -362,7 +370,7 @@ void CPlayerInterface::yourTurn() adventureInt->updateMinimap=false; } for(int i=0;ibitmap,objsToBlit[i]->pos.x,objsToBlit[i]->pos.y); + objsToBlit[i]->show(); SDL_Delay(5); //give time for other apps SDL_framerateDelay(mainFPSmng); } @@ -427,7 +435,6 @@ int getDir(int3 src, int3 dst) } void CPlayerInterface::heroMoved(const HeroMoveDetails & details) { - adventureInt->minimap.draw(); //initializing objects and performing first step of move CGHeroInstance * ho = details.ho; //object representing this hero int3 hp = details.src; @@ -994,6 +1001,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) ho->isStanding = true; //move finished CGI->mh->recalculateHideVisPosUnderObj(details.ho, true); + adventureInt->minimap.draw(); adventureInt->heroList.draw(); } void CPlayerInterface::heroKilled(const CGHeroInstance*) @@ -1268,7 +1276,7 @@ void CPlayerInterface::showInfoDialog(std::string text, std::vector temp->components[i]->pos.y += temp->pos.y; } } -void CPlayerInterface::removeObjToBlit(CSimpleWindow* obj) +void CPlayerInterface::removeObjToBlit(IShowable* obj) { objsToBlit.erase (std::find(objsToBlit.begin(),objsToBlit.end(),obj)); diff --git a/CPlayerInterface.h b/CPlayerInterface.h index 8cb8df2fb..b3a15c43d 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -11,21 +11,36 @@ struct HeroMoveDetails; class CDefEssential; class CGHeroInstance; class CAdvMapInt; + +class IShowable +{ +public: + virtual void show(SDL_Surface * to = NULL)=0; +}; + +class IActivable +{ +public: + virtual void activate()=0; + virtual void deactivate()=0; +}; + class CIntObject //interface object { public: SDL_Rect pos; int ID; }; -class CSimpleWindow : public virtual CIntObject +class CSimpleWindow : public virtual CIntObject, public IShowable { public: SDL_Surface * bitmap; CIntObject * owner; + virtual void show(SDL_Surface * to = NULL); CSimpleWindow():bitmap(NULL),owner(NULL){}; virtual ~CSimpleWindow(); }; -class CButtonBase : public virtual CIntObject //basic buttton class +class CButtonBase : public virtual CIntObject, public IShowable, public IActivable //basic buttton class { public: int type; //advmapbutton=2 @@ -35,7 +50,7 @@ public: int state; std::vector< std::vector > imgs; int curimg; - virtual void show() ; + virtual void show(SDL_Surface * to = NULL); virtual void activate()=0; virtual void deactivate()=0; CButtonBase(); @@ -94,7 +109,7 @@ public: void clickLeft (tribool down); void activate(); void deactivate(); - void show(); + void show(SDL_Surface * to = NULL); }; class CInfoWindow : public CSimpleWindow //text + comp. + ok button @@ -146,7 +161,7 @@ public: std::vector hoverable; std::vector keyinterested; std::vector motioninterested; - std::vector objsToBlit; + std::vector objsToBlit; SDL_Surface * hInfo; std::vector > slotsPos; @@ -166,7 +181,7 @@ public: void init(CCallback * CB); int3 repairScreenPos(int3 pos); void showInfoDialog(std::string text, std::vector & components); - void removeObjToBlit(CSimpleWindow* obj); + void removeObjToBlit(IShowable* obj); CPlayerInterface(int Player, int serial); }; \ No newline at end of file