1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* more code for creature info window and upgrades (still not finished)

* minor fixes
This commit is contained in:
Michał W. Urbańczyk 2008-05-23 19:50:11 +00:00
parent 00929126d5
commit b00cc9c628
10 changed files with 206 additions and 71 deletions

View File

@ -81,12 +81,14 @@ void AdventureMapButton::clickLeft (tribool down)
if (actOnDown && down)
{
pressedL=state;
callback();
if(!callback.empty())
callback();
}
else if (pressedL && (down==false))
{
pressedL=state;
callback();
if(!callback.empty())
callback();
}
else
{
@ -243,12 +245,9 @@ CSlider::CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int
left.pos.y = slider.pos.y = right.pos.y = pos.y = y;
left.pos.x = pos.x = x;
right.pos.x = x + totalw - 16;
//left.owner = right.owner = slider.owner = this;
//left.function = &CSlider::moveLeft;
//right.function = &CSlider::moveRight;
//slider.function = &CSlider::sliderClicked;
left.callback = boost::bind(&CSlider::moveLeft,this);
right.callback = boost::bind(&CSlider::moveRight,this);
slider.callback = boost::bind(&CSlider::sliderClicked,this);
left.pos.w = left.pos.h = right.pos.w = right.pos.h = slider.pos.w = slider.pos.h = pos.h = 16;
pos.w = totalw;
left.imgs.resize(1); right.imgs.resize(1); slider.imgs.resize(1);

View File

@ -303,6 +303,20 @@ void CCallback::recruitCreatures(const CGObjectInstance *obj, int ID, int amount
}
}
bool CCallback::dismissCreature(const CArmedInstance *obj, int stackPos)
{
return false;
}
bool CCallback::upgradeCreature(const CArmedInstance *obj, int stackPos)
{
return false;
}
UpgradeInfo CCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos)
{
return UpgradeInfo();
}
int CCallback::howManyTowns()
{
return gs->players[gs->currentPlayer].towns.size();

View File

@ -14,6 +14,15 @@ class CSelectableComponent;
struct BattleAction;
typedef struct lua_State lua_State;
//structure gathering info about upgrade possibilites
struct UpgradeInfo
{
int oldID; //creature to be upgraded
std::vector<int> newID; //possible upgrades
std::vector<std::set<std::pair<int,int> > > cost; // cost[upgrade_serial] -> set of pairs<resource_ID,resource_amount>
UpgradeInfo(){oldID = -1;};
};
class ICallback
{
public:
@ -25,6 +34,8 @@ public:
virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses diven hero; true - successfuly, false - not successfuly
virtual bool swapArifacts(const CGHeroInstance * hero1, bool worn1, int pos1, const CGHeroInstance * hero2, bool worn2, int pos2)=0; //swaps artifacts between two given heroes
virtual void recruitCreatures(const CGObjectInstance *obj, int ID, int amount)=0;
virtual bool dismissCreature(const CArmedInstance *obj, int stackPos)=0;
virtual bool upgradeCreature(const CArmedInstance *obj, int stackPos)=0;
//get info
virtual bool verifyPath(CPath * path, bool blockSea)=0;
@ -42,6 +53,7 @@ public:
virtual int getMySerial()=0;
virtual int getHeroSerial(const CGHeroInstance * hero)=0;
virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)=0;
virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)=0;
//battle
virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
@ -83,7 +95,15 @@ public:
bool moveHero(int ID, CPath * path, int idtype, int pathType=0);//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero
//pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
void selectionMade(int selection, int asker);
int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2);
int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2); //first goes to the second
int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val);
bool dismissHero(const CGHeroInstance * hero);
bool swapArifacts(const CGHeroInstance * hero1, bool worn1, int pos1, const CGHeroInstance * hero2, bool worn2, int pos2);
bool buildBuilding(const CGTownInstance *town, int buildingID);
void recruitCreatures(const CGObjectInstance *obj, int ID, int amount);
bool dismissCreature(const CArmedInstance *obj, int stackPos);
bool upgradeCreature(const CArmedInstance *obj, int stackPos);
//get info
@ -103,13 +123,9 @@ public:
int getMyColor();
int getHeroSerial(const CGHeroInstance * hero);
int getMySerial();
int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2);
int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2); //first goes to the second
int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val);
bool dismissHero(const CGHeroInstance * hero);
const CCreatureSet* getGarrison(const CGObjectInstance *obj);
bool swapArifacts(const CGHeroInstance * hero1, bool worn1, int pos1, const CGHeroInstance * hero2, bool worn2, int pos2);
bool buildBuilding(const CGTownInstance *town, int buildingID);
UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos);
//battle
int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
int battleGetObstaclesAtTile(int tile); //returns bitfield

View File

@ -24,6 +24,7 @@
#include "hch\CPreGameTextHandler.h"
#include "CBattleInterface.h"
#include "CLua.h"
#include <cmath>
using namespace CSDL_Ext;
extern TTF_Font * GEOR16;
@ -102,10 +103,30 @@ void CGarrisonSlot::hover (bool on)
LOCPLINT->statusbar->clear();
}
}
const CGObjectInstance * CGarrisonSlot::getObj()
{
return (!upg)?(owner->oup):(owner->odown);
}
void CGarrisonSlot::clickRight (tribool down)
{
//if(down && creature)
//(new CCreInfoWindow(creature->idNumber,0))->activate();
StackState *pom = NULL;
if(down && creature)
{
if(getObj()->ID == 34)
{
pom = new StackState();
const CGHeroInstance *h = static_cast<const CGHeroInstance *>(getObj());
pom->attackBonus = h->primSkills[0];
pom->defenseBonus = h->primSkills[1];
pom->luck = h->getCurrentLuck();
pom->morale = h->getCurrentMorale();
}
(new CCreInfoWindow(creature->idNumber,0,pom,boost::function<void()>(),boost::function<void()>()))
->activate();
}
delete pom;
}
void CGarrisonSlot::clickLeft(tribool down)
{
@ -2906,20 +2927,84 @@ CCreInfoWindow::CCreInfoWindow(int Cid, int Type, StackState *State, boost::func
pos.y = screen->h/2 - bitmap->h/2;
pos.w = bitmap->w;
pos.h = bitmap->h;
blueToPlayersAdv(bitmap,LOCPLINT->playerID);
SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
anim = new CCreatureAnimation(c->animDefName);
anim->setType(1);
printAtMiddle(c->namePl,149,30,GEOR13,zwykly,bitmap);
char pom[25];int hlp=0;
printAtMiddle(c->namePl,149,30,GEOR13,zwykly,bitmap); //creature name
//atttack
printAt(CGI->preth->zelp[435].first,155,48,GEOR13,zwykly,bitmap);
itoa(c->attack,pom,10);
if(State && State->attackBonus)
{
int hlp = log10f(c->attack)+2;
pom[hlp-1] = ' '; pom[hlp] = '(';
itoa(c->attack+State->attackBonus,pom+hlp+1,10);
pom[hlp+2+(int)log10f(State->attackBonus+c->attack)] = ')';
}
printTo(pom,276,61,GEOR13,zwykly,bitmap);
//defense
printAt(CGI->preth->zelp[436].first,155,67,GEOR13,zwykly,bitmap);
itoa(c->defence,pom,10);
if(State && State->defenseBonus)
{
int hlp = log10f(c->defence)+2;
pom[hlp-1] = ' '; pom[hlp] = '(';
itoa(c->defence+State->defenseBonus,pom+hlp+1,10);
pom[hlp+2+(int)log10f(State->defenseBonus+c->defence)] = ')';
}
printTo(pom,276,80,GEOR13,zwykly,bitmap);
//shots
if(c->shots)
printAt(CGI->preth->zelp[437].first,155,86,GEOR13,zwykly,bitmap);
{
printAt(CGI->generaltexth->allTexts[198],155,86,GEOR13,zwykly,bitmap);
itoa(c->shots,pom,10);
printTo(pom,276,99,GEOR13,zwykly,bitmap);
}
//damage
printAt(CGI->generaltexth->allTexts[199],155,105,GEOR13,zwykly,bitmap);
itoa(c->damageMin,pom,10);
hlp=log10f(c->damageMin)+2;
pom[hlp-1]=' '; pom[hlp]='-'; pom[hlp+1]=' ';
itoa(c->damageMax,pom+hlp+2,10);
printTo(pom,276,118,GEOR13,zwykly,bitmap);
//health
printAt(CGI->preth->zelp[439].first,155,124,GEOR13,zwykly,bitmap);
itoa(c->hitPoints,pom,10);
printTo(pom,276,137,GEOR13,zwykly,bitmap);
//remaining health - TODO: show during the battles
//printAt(CGI->preth->zelp[440].first,155,143,GEOR13,zwykly,bitmap);
//speed
printAt(CGI->preth->zelp[441].first,155,162,GEOR13,zwykly,bitmap);
itoa(c->speed,pom,10);
printTo(pom,276,175,GEOR13,zwykly,bitmap);
//luck and morale
blitAt(LOCPLINT->morale42->ourImages[(State)?(State->morale+3):(3)].bitmap,24,189,bitmap);
blitAt(LOCPLINT->luck42->ourImages[(State)?(State->luck+3):(3)].bitmap,77,189,bitmap);
//print abilities text - if r-click popup
if(type)
{
if(Upg)
upgrade = new AdventureMapButton("",CGI->preth->zelp[446].second,Upg,76,237,"IVIEWCR.DEF");
if(Dsm)
dismiss = new AdventureMapButton("",CGI->preth->zelp[445].second,Upg,21,237,"IVIEWCR2.DEF");
}
else
{
printAtWB(c->abilityText,17,231,GEOR13,35,zwykly,bitmap);
}
}
CCreInfoWindow::~CCreInfoWindow()
{
@ -2940,14 +3025,12 @@ void CCreInfoWindow::activate()
void CCreInfoWindow::close()
{
deactivate();
CCastleInterface *c = dynamic_cast<CCastleInterface*>(LOCPLINT->curint);
if(c) c->showAll();
if(type)
LOCPLINT->curint->activate();
delete this;
if(type)
{
LOCPLINT->curint->activate();
CCastleInterface *c = dynamic_cast<CCastleInterface*>(LOCPLINT->curint);
if(c) c->showAll();
}
}
void CCreInfoWindow::clickRight(boost::logic::tribool down)
{

View File

@ -245,6 +245,7 @@ public:
bool active;
virtual void hover (bool on);
const CGObjectInstance * getObj();
void clickRight (boost::logic::tribool down);
void clickLeft(boost::logic::tribool down);
void activate();

View File

@ -93,6 +93,25 @@ void CSDL_Ext::printAtMiddleWB(std::string text, int x, int y, TTF_Font * font,
}
for (int i=0;i<wesu.size();i++)
SDL_FreeSurface(wesu[i]);
delete ws;
}
void CSDL_Ext::printAtWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor, SDL_Surface * dst)
{
std::vector<std::string> * ws = CMessage::breakText(text,charpr);
std::vector<SDL_Surface*> wesu;
wesu.resize(ws->size());
for (int i=0;i<wesu.size();i++)
wesu[i]=TTF_RenderText_Blended(font,(*ws)[i].c_str(),kolor);
int evy = y;
for (int i=0;i<wesu.size();i++)
{
blitAt(wesu[i],x,evy,dst);
evy+=wesu[i]->h;
}
for (int i=0;i<wesu.size();i++)
SDL_FreeSurface(wesu[i]);
delete ws;

View File

@ -41,6 +41,7 @@ namespace CSDL_Ext
void printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
void printAtMiddle(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest
void printAtMiddleWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
void printAtWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest
void update(SDL_Surface * what = screen); //updates whole surface (default - main screen)
void blueToPlayers(SDL_Surface * sur, int player); //simple color substitution

View File

@ -104,6 +104,7 @@
102 CopperGorgon
103 BronzeGorgon
104 DragonFly
104 SerpentFly
105 FireDragonFly
106 Basilisk
107 GreaterBasilisk

View File

@ -231,7 +231,7 @@ void CCreatureHandler::loadCreatures()
if(buf[i]=='\t')
break;
}
ncre.low1 = atoi(buf.substr(befi, i-befi).c_str());
ncre.damageMin = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
@ -240,7 +240,7 @@ void CCreatureHandler::loadCreatures()
if(buf[i]=='\t')
break;
}
ncre.high1 = atoi(buf.substr(befi, i-befi).c_str());
ncre.damageMax = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
@ -267,7 +267,7 @@ void CCreatureHandler::loadCreatures()
if(buf[i]=='\t')
break;
}
ncre.low2 = atoi(buf.substr(befi, i-befi).c_str());
ncre.ammMin = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
@ -276,7 +276,7 @@ void CCreatureHandler::loadCreatures()
if(buf[i]=='\t')
break;
}
ncre.high2 = atoi(buf.substr(befi, i-befi).c_str());
ncre.ammMax = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
@ -604,49 +604,49 @@ void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int
void CCreatureHandler::loadUnitAnimations()
{
std::ifstream inp("config/CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod
inp.seekg(0,std::ios::end); // na koniec
int andame = inp.tellg(); // read length
inp.seekg(0,std::ios::beg); // wracamy na poczatek
char * bufor = new char[andame]; // allocate memory
inp.read((char*)bufor, andame); // read map file to buffer
inp.close();
std::string buf = std::string(bufor);
delete [andame] bufor;
//std::ifstream inp("config/CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod
//inp.seekg(0,std::ios::end); // na koniec
//int andame = inp.tellg(); // read length
//inp.seekg(0,std::ios::beg); // wracamy na poczatek
//char * bufor = new char[andame]; // allocate memory
//inp.read((char*)bufor, andame); // read map file to buffer
//inp.close();
//std::string buf = std::string(bufor);
//delete [andame] bufor;
int i = 0; //buf iterator
int hmcr = 0;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
for(int s=0; s<creatures.size(); ++s)
{
int befi=i;
std::string rub;
for(i; i<andame; ++i)
{
if(buf[i]==' ')
break;
}
rub = buf.substr(befi, i-befi);
++i;
//int i = 0; //buf iterator
//int hmcr = 0;
//for(i; i<andame; ++i) //omitting rubbish
//{
// if(buf[i]=='\r')
// break;
//}
//i+=2;
//for(int s=0; s<creatures.size(); ++s)
//{
// int befi=i;
// std::string rub;
// for(i; i<andame; ++i)
// {
// if(buf[i]==' ')
// break;
// }
// rub = buf.substr(befi, i-befi);
// ++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
break;
}
std::string defName = buf.substr(befi, i-befi);
if(defName != std::string("x"))
creatures[s].battleAnimation = CGameInfo::mainObj->spriteh->giveDef(defName);
else
creatures[s].battleAnimation = NULL;
i+=2;
}
// befi=i;
// for(i; i<andame; ++i)
// {
// if(buf[i]=='\r')
// break;
// }
// std::string defName = buf.substr(befi, i-befi);
// if(defName != std::string("x"))
// creatures[s].battleAnimation = CGameInfo::mainObj->spriteh->giveDef(defName);
// else
// creatures[s].battleAnimation = NULL;
// i+=2;
//}
}
int CCreatureAnimation::getType() const

View File

@ -16,7 +16,8 @@ public:
std::string namePl, nameSing, nameRef; //name in singular and plural form; and reference name
std::vector<int> cost; //cost[res_id] - amount of that resource
int fightValue, AIValue, growth, hordeGrowth, hitPoints, speed, attack, defence, shots, spells;
int low1, low2, high1, high2; //TODO - co to w ogóle jest???
int damageMin, damageMax;
int ammMin, ammMax;
int level; // 0 - unknown
std::string abilityText; //description of abilities
std::string abilityRefs; //references to abilities, in textformat
@ -36,7 +37,7 @@ public:
int indefLevel; //only if indefinite
bool indefUpgraded; //onlu if inddefinite
//end
CDefHandler * battleAnimation;
//CDefHandler * battleAnimation;
//TODO - zdolnoœci - na typie wyliczeniowym czy czymœ
static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion
@ -60,7 +61,7 @@ public:
std::map<int,SDL_Surface*> smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border
std::map<int,SDL_Surface*> bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border
std::map<int,SDL_Surface*> backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral
std::vector<CCreature> creatures;
std::vector<CCreature> creatures; //creature ID -> creature info
std::map<int,std::vector<CCreature*> > levelCreatures; //level -> list of creatures
std::map<std::string,int> nameToID;
void loadCreatures();