mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
* version set to 0.63
* mostly done morketplace * more logging around netcode
This commit is contained in:
parent
2af92aa170
commit
3d147a7be8
@ -116,7 +116,6 @@ void AdventureMapButton::init(const CFunctionList<void()> &Callback, const std::
|
||||
state=0;
|
||||
hoverTexts = Name;
|
||||
helpBox=HelpBox;
|
||||
colorChange = playerColoredButton;
|
||||
int est = LOCPLINT->playerID;
|
||||
CDefHandler * temp = CDefHandler::giveDef(defName);
|
||||
temp->notFreeImgs = true;
|
||||
@ -320,3 +319,10 @@ CSlider::CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int
|
||||
|
||||
moveTo(value);
|
||||
}
|
||||
|
||||
void CSlider::block( bool on )
|
||||
{
|
||||
left.block(on);
|
||||
right.block(on);
|
||||
slider.block(on);
|
||||
}
|
@ -63,6 +63,7 @@ public:
|
||||
void mouseMoved (SDL_MouseMotionEvent & sEvent);
|
||||
void moveRight();
|
||||
void moveTo(int to);
|
||||
void block(bool on);
|
||||
void activate(); // makes button active
|
||||
void deactivate(); // makes button inactive (but doesn't delete)
|
||||
void show(SDL_Surface * to = NULL);
|
||||
|
@ -28,6 +28,21 @@
|
||||
#endif
|
||||
extern CSharedCond<std::set<IPack*> > mess;
|
||||
|
||||
int gcd(int x, int y)
|
||||
{
|
||||
int temp;
|
||||
if (y > x)
|
||||
swap(x,y);
|
||||
while (y != 0)
|
||||
{
|
||||
temp = y;
|
||||
y = x-y;
|
||||
x = temp;
|
||||
if (y > x)
|
||||
swap(x,y);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
HeroMoveDetails::HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho)
|
||||
:src(Src),dst(Dst),ho(Ho)
|
||||
{
|
||||
@ -544,3 +559,29 @@ std::vector < const CGObjectInstance * > CCallback::getVisitableObjs( int3 pos )
|
||||
ret.push_back(obj);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CCallback::getMarketOffer( int t1, int t2, int &give, int &rec, int mode/*=0*/ )
|
||||
{
|
||||
if(mode) return; //TODO - support
|
||||
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//if(gs->resVals[t1] >= gs->resVals[t2])
|
||||
float r = gs->resVals[t1],
|
||||
g = gs->resVals[t2] / gs->getMarketEfficiency(player,mode);
|
||||
if(r>g)
|
||||
{
|
||||
rec = r / g;
|
||||
give = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
give = g / r;
|
||||
rec = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void CCallback::trade( int mode, int id1, int id2, int val1 )
|
||||
{
|
||||
int p1, p2;
|
||||
getMarketOffer(id1,id2,p1,p2,mode);
|
||||
*cl->serv << ui16(511) << ui8(player) << ui32(mode) << ui32(id1) << ui32(id2) << ui32(val1);
|
||||
}
|
@ -41,6 +41,7 @@ public:
|
||||
virtual void endTurn()=0;
|
||||
virtual void swapGarrisonHero(const CGTownInstance *town)=0;
|
||||
virtual void buyArtifact(const CGHeroInstance *hero, int aid)=0; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith)
|
||||
virtual void trade(int mode, int id1, int id2, int val1)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce
|
||||
|
||||
//get info
|
||||
virtual bool verifyPath(CPath * path, bool blockSea)=0;
|
||||
@ -62,6 +63,7 @@ public:
|
||||
virtual const StartInfo * getStartInfo()=0;
|
||||
virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)=0;
|
||||
virtual std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos)=0;
|
||||
virtual void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0)=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
|
||||
@ -118,6 +120,7 @@ public:
|
||||
void endTurn();
|
||||
void swapGarrisonHero(const CGTownInstance *town);
|
||||
void buyArtifact(const CGHeroInstance *hero, int aid);
|
||||
void trade(int mode, int id1, int id2, int val1);
|
||||
|
||||
//get info
|
||||
bool verifyPath(CPath * path, bool blockSea);
|
||||
@ -138,9 +141,10 @@ public:
|
||||
int getMySerial();
|
||||
const CCreatureSet* getGarrison(const CGObjectInstance *obj);
|
||||
UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos);
|
||||
virtual const StartInfo * getStartInfo();
|
||||
const StartInfo * getStartInfo();
|
||||
std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos);
|
||||
std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos);
|
||||
void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0);
|
||||
|
||||
//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
|
||||
|
@ -280,7 +280,7 @@ void CHeroGSlot::show()
|
||||
if(hero) //there is hero
|
||||
blitAt(graphics->portraitLarge[hero->portrait],pos);
|
||||
else if(!upg) //up garrison
|
||||
blitAt((static_cast<CCastleInterface*>(LOCPLINT->curint))->flag->ourImages[(static_cast<CCastleInterface*>(LOCPLINT->curint))->town->getOwner()].bitmap,pos);
|
||||
blitAt(graphics->flags->ourImages[(static_cast<CCastleInterface*>(LOCPLINT->curint))->town->getOwner()].bitmap,pos);
|
||||
if(highlight)
|
||||
blitAt(graphics->bigImgs[-1],pos);
|
||||
}
|
||||
@ -348,7 +348,6 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
|
||||
cityBg = BitmapHandler::loadBitmap(getBgName(Town->subID));
|
||||
hall = CDefHandler::giveDef("ITMTL.DEF");
|
||||
fort = CDefHandler::giveDef("ITMCL.DEF");
|
||||
flag = CDefHandler::giveDef("CREST58.DEF");
|
||||
hBuild = NULL;
|
||||
count=0;
|
||||
town = Town;
|
||||
@ -436,7 +435,6 @@ CCastleInterface::~CCastleInterface()
|
||||
delete split;
|
||||
delete hall;
|
||||
delete fort;
|
||||
delete flag;
|
||||
delete garr;
|
||||
delete townlist;
|
||||
delete statusbar;
|
||||
@ -517,6 +515,13 @@ void CCastleInterface::buildingClicked(int building)
|
||||
case 10: case 11: case 12: case 13:
|
||||
enterHall();
|
||||
break;
|
||||
case 14:
|
||||
{
|
||||
deactivate();
|
||||
CMarketplaceWindow *cmw = new CMarketplaceWindow(0);
|
||||
cmw->activate();
|
||||
break;
|
||||
}
|
||||
case 16:
|
||||
{
|
||||
const CGHeroInstance *hero = town->visitingHero;
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
CStatusBar * statusbar;
|
||||
unsigned char animval, count;
|
||||
|
||||
CDefHandler *hall,*fort, *flag;
|
||||
CDefHandler *hall,*fort;
|
||||
CDefEssential* bicons; //150x70 buildings imgs
|
||||
CTownList * townlist;
|
||||
|
||||
|
@ -21,6 +21,12 @@
|
||||
boost::rand48 ran;
|
||||
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
CGObjectInstance * createObject(int id, int subid, int3 pos, int owner)
|
||||
{
|
||||
@ -931,6 +937,7 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed)
|
||||
startres.push_back(k);
|
||||
}
|
||||
tis.close();
|
||||
tis.clear();
|
||||
for (std::map<ui8,PlayerState>::iterator i = players.begin(); i!=players.end(); i++)
|
||||
{
|
||||
(*i).second.resources.resize(RESOURCE_QUANTITY);
|
||||
@ -938,6 +945,15 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed)
|
||||
(*i).second.resources[x] = startres[x];
|
||||
}
|
||||
|
||||
tis.open("config/resources.txt");
|
||||
tis >> k;
|
||||
int pom;
|
||||
for(int i=0;i<k;i++)
|
||||
{
|
||||
tis >> pom;
|
||||
resVals.push_back(pom);
|
||||
}
|
||||
|
||||
/*************************HEROES************************************************/
|
||||
for (int i=0; i<map->heroes.size();i++) //heroes instances
|
||||
{
|
||||
@ -1253,6 +1269,18 @@ UpgradeInfo CGameState::getUpgradeInfo(CArmedInstance *obj, int stackPos)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
float CGameState::getMarketEfficiency( int player, int mode/*=0*/ )
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> lock(*mx);
|
||||
if(mode) return -1; //todo - support other modes
|
||||
int mcount = 0;
|
||||
for(int i=0;i<players[player].towns.size();i++)
|
||||
if(vstd::contains(players[player].towns[i]->builtBuildings,14))
|
||||
mcount++;
|
||||
float ret = std::min(((float)mcount+1.0f)/20.0f,0.5f);
|
||||
return ret;
|
||||
}
|
||||
int BattleInfo::calculateDmg(const CStack* attacker, const CStack* defender)
|
||||
{
|
||||
int attackDefenseBonus = attacker->creature->attack - defender->creature->defence;
|
||||
|
@ -130,6 +130,7 @@ private:
|
||||
Mapa * map;
|
||||
std::map<ui8,PlayerState> players; //ID <-> playerstate
|
||||
std::map<int, CGDefInfo*> villages, forts, capitols; //def-info for town graphics
|
||||
std::vector<ui32> resVals;
|
||||
|
||||
boost::shared_mutex *mx;
|
||||
|
||||
@ -150,6 +151,7 @@ private:
|
||||
bool battleShootCreatureStack(int ID, int dest);
|
||||
int battleGetStack(int pos); //returns ID of stack at given tile
|
||||
UpgradeInfo getUpgradeInfo(CArmedInstance *obj, int stackPos);
|
||||
float getMarketEfficiency(int player, int mode=0);
|
||||
public:
|
||||
int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
|
||||
|
@ -31,10 +31,12 @@
|
||||
#include "timeHandler.h"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/assign/std/vector.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <cmath>
|
||||
#include <queue>
|
||||
#include <sstream>
|
||||
using namespace boost::assign;
|
||||
using namespace CSDL_Ext;
|
||||
|
||||
extern TTF_Font * GEOR16;
|
||||
@ -52,7 +54,6 @@ public:
|
||||
return (*a.first)<(*b.first);
|
||||
}
|
||||
} ocmptwo_cgin ;
|
||||
|
||||
void CGarrisonSlot::hover (bool on)
|
||||
{
|
||||
Hoverable::hover(on);
|
||||
@ -3421,3 +3422,265 @@ CCustomImgComponent::~CCustomImgComponent()
|
||||
if(free)
|
||||
SDL_FreeSurface(bmp);
|
||||
}
|
||||
|
||||
CMarketplaceWindow::CTradeableItem::CTradeableItem( int Type, int ID, bool Left)
|
||||
{
|
||||
left = Left;
|
||||
type = Type;
|
||||
id = ID;
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::CTradeableItem::show( SDL_Surface * to/*=NULL*/ )
|
||||
{
|
||||
SDL_Surface *hlp = getSurface();
|
||||
blitAt(hlp,pos.x+19,pos.y+9,to);
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::CTradeableItem::clickLeft( boost::logic::tribool down )
|
||||
{
|
||||
CMarketplaceWindow *mw = static_cast<CMarketplaceWindow *>(LOCPLINT->curint->subInt);
|
||||
if(down)
|
||||
{
|
||||
if(left)
|
||||
{
|
||||
if(mw->hLeft != this)
|
||||
mw->hLeft = this;
|
||||
else
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(mw->hRight != this)
|
||||
mw->hRight = this;
|
||||
else
|
||||
return;
|
||||
}
|
||||
mw->selectionChanged(left);
|
||||
}
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::CTradeableItem::activate()
|
||||
{
|
||||
ClickableL::activate();
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::CTradeableItem::deactivate()
|
||||
{
|
||||
ClickableL::deactivate();
|
||||
}
|
||||
|
||||
SDL_Surface * CMarketplaceWindow::CTradeableItem::getSurface()
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case 0:
|
||||
return graphics->resources32->ourImages[id].bitmap;
|
||||
case 1:
|
||||
return graphics->artDefs->ourImages[id].bitmap;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
void initItems( std::vector<CMarketplaceWindow::CTradeableItem*> &i, std::vector<SDL_Rect> &p, int type, int amount, bool left, std::vector<int> *ids/*=NULL*/ )
|
||||
{
|
||||
i.resize(amount);
|
||||
for(int j=0;j<amount;j++)
|
||||
{
|
||||
i[j] = new CMarketplaceWindow::CTradeableItem(type,(ids && ids->size()>j) ? (*ids)[j] : j, left);
|
||||
i[j]->pos = p[j];
|
||||
}
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::setMode( int mode )
|
||||
{
|
||||
std::vector<SDL_Rect> lpos, rpos;
|
||||
clear();
|
||||
switch(mode)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
SDL_Surface *bg2 = BitmapHandler::loadBitmap("TPMRKRES.bmp");
|
||||
SDL_SetColorKey(bg2,SDL_SRCCOLORKEY,SDL_MapRGB(bg2->format,0,255,255));
|
||||
graphics->blueToPlayersAdv(bg2,LOCPLINT->playerID);
|
||||
bg = SDL_ConvertSurface(bg2,screen->format,0);
|
||||
SDL_FreeSurface(bg2);
|
||||
lpos += genRect(66,69,39,180), genRect(66,69,122,180), genRect(66,69,204,180),
|
||||
genRect(66,69,39,259), genRect(66,69,122,259), genRect(66,69,204,259),
|
||||
genRect(66,69,122,338);
|
||||
for(int i=0;i<lpos.size();i++)
|
||||
{
|
||||
lpos[i].x += pos.x;
|
||||
lpos[i].y += pos.y;
|
||||
rpos.push_back(lpos[i]);
|
||||
rpos[rpos.size()-1].x += 288;
|
||||
}
|
||||
initItems(left,lpos,0,7,true,NULL);
|
||||
initItems(right,rpos,0,7,false,NULL);
|
||||
printAtMiddle(CGI->generaltexth->allTexts[158],303,28,GEORXX,tytulowy,bg); //title
|
||||
printAtMiddle(CGI->generaltexth->allTexts[270],158,148,GEOR13,zwykly,bg); //kingdom res.
|
||||
printAtMiddle(CGI->generaltexth->allTexts[168],450,148,GEOR13,zwykly,bg); //available for trade
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::clear()
|
||||
{
|
||||
for(int i=0;i<left.size();i++)
|
||||
delete left[i];
|
||||
for(int i=0;i<right.size();i++)
|
||||
delete right[i];
|
||||
left.clear();
|
||||
right.clear();
|
||||
SDL_FreeSurface(bg);
|
||||
}
|
||||
|
||||
CMarketplaceWindow::CMarketplaceWindow(int Mode)
|
||||
{
|
||||
mode = Mode;
|
||||
bg = NULL;
|
||||
ok = max = deal = NULL;
|
||||
pos.x = screen->w/2 - 300;
|
||||
pos.y = screen->h/2 - 296;
|
||||
slider = new CSlider(pos.x+231,pos.y+490,137,boost::bind(&CMarketplaceWindow::sliderMoved,this,_1),0,0);
|
||||
setMode(mode);
|
||||
hLeft = hRight = NULL;
|
||||
ok = new AdventureMapButton("","",boost::bind(&CMarketplaceWindow::deactivate,this),pos.x+516,pos.y+520,"IOK6432.DEF");
|
||||
ok->callback += boost::bind(&CMarketplaceWindow::clear,this); //clear
|
||||
ok->callback += boost::bind(vstd::delObj<CMarketplaceWindow>,this); //will delete
|
||||
ok->callback += boost::bind(&CMainInterface::activate,LOCPLINT->curint);
|
||||
deal = new AdventureMapButton("","",boost::bind(&CMarketplaceWindow::makeDeal,this),pos.x+307,pos.y+520,"TPMRKB.DEF");
|
||||
max = new AdventureMapButton("","",boost::bind(&CMarketplaceWindow::setMax,this),pos.x+229,pos.y+520,"IRCBTNS.DEF");
|
||||
|
||||
max->block(true);
|
||||
deal->block(true);
|
||||
}
|
||||
|
||||
CMarketplaceWindow::~CMarketplaceWindow()
|
||||
{
|
||||
delete slider;
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::show( SDL_Surface * to/*=NULL*/ )
|
||||
{
|
||||
blitAt(bg,pos);
|
||||
if(hRight)
|
||||
CSDL_Ext::drawBorder(screen,hRight->pos.x-1,hRight->pos.y-1,hRight->pos.w+2,hRight->pos.h+2,int3(255,231,148));
|
||||
if(hLeft)
|
||||
CSDL_Ext::drawBorder(screen,hLeft->pos.x-1,hLeft->pos.y-1,hLeft->pos.w+2,hLeft->pos.h+2,int3(255,231,148));
|
||||
ok->show();
|
||||
deal->show();
|
||||
max->show();
|
||||
slider->show();
|
||||
for(int i=0;i<left.size();i++)
|
||||
left[i]->show();
|
||||
for(int i=0;i<right.size();i++)
|
||||
right[i]->show();
|
||||
if(mode==0)
|
||||
{
|
||||
char buf[15];
|
||||
for(int i=0;i<left.size();i++)
|
||||
{
|
||||
SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
|
||||
printAtMiddle(buf,left[i]->pos.x+35,left[i]->pos.y+56,GEOR13,zwykly);
|
||||
}
|
||||
if(hLeft) //print prices
|
||||
{
|
||||
for(int i=0; i<right.size();i++)
|
||||
{
|
||||
if(right[i]->id != hLeft->id)
|
||||
printAtMiddle(rSubs[i],right[i]->pos.x+35,right[i]->pos.y+56,GEOR13,zwykly);
|
||||
else
|
||||
printAtMiddle(CGI->generaltexth->allTexts[164],right[i]->pos.x+35,right[i]->pos.y+56,GEOR13,zwykly);
|
||||
}
|
||||
}
|
||||
if(hLeft && hRight && hLeft->id!= hRight->id)
|
||||
{
|
||||
blitAt(hLeft->getSurface(),pos.x+142,pos.y+457,screen);
|
||||
blitAt(hRight->getSurface(),pos.x+430,pos.y+457,screen);
|
||||
SDL_itoa(slider->value * r1,buf,10);
|
||||
printAtMiddle(buf,pos.x+158,pos.y+504,GEOR13,zwykly);
|
||||
SDL_itoa(slider->value * r2,buf,10);
|
||||
printAtMiddle(buf,pos.x+446,pos.y+504,GEOR13,zwykly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::activate()
|
||||
{
|
||||
LOCPLINT->objsToBlit += this;
|
||||
LOCPLINT->curint->subInt = this;
|
||||
for(int i=0;i<left.size();i++)
|
||||
left[i]->activate();
|
||||
for(int i=0;i<right.size();i++)
|
||||
right[i]->activate();
|
||||
ok->activate();
|
||||
max->activate();
|
||||
deal->activate();
|
||||
slider->activate();
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::deactivate()
|
||||
{
|
||||
LOCPLINT->objsToBlit -= this;
|
||||
LOCPLINT->curint->subInt = NULL;
|
||||
for(int i=0;i<left.size();i++)
|
||||
left[i]->deactivate();
|
||||
for(int i=0;i<right.size();i++)
|
||||
right[i]->deactivate();
|
||||
ok->deactivate();
|
||||
max->deactivate();
|
||||
deal->deactivate();
|
||||
slider->deactivate();
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::setMax()
|
||||
{
|
||||
slider->moveTo(slider->amount);
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::makeDeal()
|
||||
{
|
||||
LOCPLINT->cb->trade(mode,hLeft->id,hRight->id,slider->value*r1);
|
||||
slider->moveTo(0);
|
||||
hLeft = NULL;
|
||||
selectionChanged(true);
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::sliderMoved( int to )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::selectionChanged(bool side)
|
||||
{
|
||||
if(hLeft && hRight && hLeft->id!= hRight->id)
|
||||
{
|
||||
LOCPLINT->cb->getMarketOffer(hLeft->id,hRight->id,r1,r2,0);
|
||||
slider->amount = LOCPLINT->cb->getResourceAmount(hLeft->id) / r1;
|
||||
slider->moveTo(0);
|
||||
max->block(false);
|
||||
deal->block(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
max->block(true);
|
||||
deal->block(true);
|
||||
slider->amount = 0;
|
||||
slider->moveTo(0);
|
||||
}
|
||||
if(side && hLeft) //left selection changed, recalculate offers
|
||||
{
|
||||
rSubs.clear();
|
||||
rSubs.resize(right.size());
|
||||
int h1, h2;
|
||||
for(int i=0;i<right.size();i++)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
LOCPLINT->cb->getMarketOffer(hLeft->id,i,h1,h2,0);
|
||||
oss << h2;
|
||||
if(h1!=1)
|
||||
oss << "/" << h1;
|
||||
rSubs[i] = oss.str();
|
||||
}
|
||||
}
|
||||
}
|
@ -592,6 +592,48 @@ public:
|
||||
~CMinorResDataBar();
|
||||
};
|
||||
|
||||
class CMarketplaceWindow : public IShowActivable, public CIntObject
|
||||
{
|
||||
public:
|
||||
class CTradeableItem : public ClickableL
|
||||
{
|
||||
public:
|
||||
int type; //0 - res, 1 - artif big, 2 - artif small, 3 - player flag
|
||||
int id;
|
||||
bool left;
|
||||
CFunctionList<void()> callback;
|
||||
|
||||
void activate();
|
||||
void deactivate();
|
||||
void show(SDL_Surface * to=NULL);
|
||||
void clickLeft(boost::logic::tribool down);
|
||||
SDL_Surface *getSurface();
|
||||
CTradeableItem(int Type, int ID, bool Left);
|
||||
};
|
||||
|
||||
SDL_Surface *bg;
|
||||
std::vector<CTradeableItem*> left, right;
|
||||
std::vector<std::string> rSubs;
|
||||
CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
|
||||
|
||||
int mode,//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
|
||||
r1, r2;
|
||||
AdventureMapButton *ok, *max, *deal;
|
||||
CSlider *slider;
|
||||
|
||||
void activate();
|
||||
void deactivate();
|
||||
void show(SDL_Surface * to=NULL);
|
||||
void setMax();
|
||||
void sliderMoved(int to);
|
||||
void makeDeal();
|
||||
void selectionChanged(bool side); //true == left
|
||||
CMarketplaceWindow(int Mode=0);
|
||||
~CMarketplaceWindow();
|
||||
void setMode(int mode);
|
||||
void clear();
|
||||
};
|
||||
|
||||
extern CPlayerInterface * LOCPLINT;
|
||||
|
||||
#endif //CPLAYERINTERFACE_H
|
||||
|
@ -192,6 +192,7 @@ Graphics::Graphics()
|
||||
tasks += GET_DEF(resources32,"RESOURCE.DEF");
|
||||
tasks += GET_DEF(smi,"CPRSMALL.DEF");
|
||||
tasks += GET_DEF(smi2,"TWCRPORT.DEF");
|
||||
tasks += GET_DEF(flags,"CREST58.DEF");
|
||||
|
||||
std::ifstream ifs("config/cr_bgs.txt");
|
||||
int id;
|
||||
|
@ -30,6 +30,7 @@ public:
|
||||
CDefHandler * pskillsm; //42x42
|
||||
CDefHandler * un44; //many things
|
||||
CDefHandler * smallIcons, *resources32; //resources 32x32
|
||||
CDefHandler * flags;
|
||||
//creatures
|
||||
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
|
||||
|
2
config/resources.txt
Normal file
2
config/resources.txt
Normal file
@ -0,0 +1,2 @@
|
||||
8
|
||||
250 500 250 500 500 500 1 0
|
9
global.h
9
global.h
@ -16,7 +16,7 @@ typedef boost::int8_t si8; //signed int 8 bits (1 byte)
|
||||
#define THC
|
||||
#endif
|
||||
|
||||
#define NAME_VER ("VCMI 0.62")
|
||||
#define NAME_VER ("VCMI 0.63")
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -141,7 +141,7 @@ namespace vstd
|
||||
return -1;
|
||||
}
|
||||
template <typename T1, typename T2, typename Func>
|
||||
int findPos(const std::vector<T1> & c, const T2 &s, Func &f) //Func(T1,T2) must say if these elements matches
|
||||
int findPos(const std::vector<T1> & c, const T2 &s, const Func &f) //Func(T1,T2) must say if these elements matches
|
||||
{
|
||||
for(int i=0;i<c.size();i++)
|
||||
if(f(c[i],s))
|
||||
@ -162,6 +162,11 @@ namespace vstd
|
||||
c.erase(itr);
|
||||
return true;
|
||||
}
|
||||
template <typename t1>
|
||||
void delObj(t1 *a1)
|
||||
{
|
||||
delete a1;
|
||||
}
|
||||
template <typename t1, typename t2>
|
||||
void assign(t1 &a1, const t2 &a2)
|
||||
{
|
||||
|
@ -42,10 +42,48 @@ CConnection::CConnection(std::string host, std::string port, std::string Name, s
|
||||
boost::system::error_code error = asio::error::host_not_found;
|
||||
socket = new tcp::socket(*io_service);
|
||||
tcp::resolver resolver(*io_service);
|
||||
tcp::resolver::iterator endpoint_iterator = resolver.resolve(tcp::resolver::query(host,port));
|
||||
socket->connect(*endpoint_iterator, error);
|
||||
if (error){ delete socket; throw "Can't establish connection :("; }
|
||||
init();
|
||||
tcp::resolver::iterator end, pom, endpoint_iterator = resolver.resolve(tcp::resolver::query(host,port),error);
|
||||
if(error)
|
||||
{
|
||||
std::cout << "Problem with resolving. " << std::endl << error <<std::endl;
|
||||
goto connerror1;
|
||||
}
|
||||
pom = endpoint_iterator;
|
||||
if(pom != end)
|
||||
std::cout<<"Found endpoints:" << std::endl;
|
||||
else
|
||||
{
|
||||
std::cout<< "Critical problem: No endpoints found!" << std::endl;
|
||||
goto connerror1;
|
||||
}
|
||||
while(pom != end)
|
||||
{
|
||||
std::cout << (boost::asio::ip::tcp::endpoint&)*pom << std::endl;
|
||||
pom++;
|
||||
}
|
||||
while(endpoint_iterator != end)
|
||||
{
|
||||
socket->connect(*endpoint_iterator, error);
|
||||
if(!error)
|
||||
{
|
||||
init();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Problem with connecting. " << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
//we shouldn't be here - error handling
|
||||
connerror1:
|
||||
if(error)
|
||||
std::cout << error <<std::endl;
|
||||
else
|
||||
std::cout << "No error info. " << std::endl;
|
||||
delete io_service;
|
||||
delete socket;
|
||||
throw std::string("Can't establish connection :(");
|
||||
}
|
||||
CConnection::CConnection(
|
||||
boost::asio::basic_stream_socket<boost::asio::ip::tcp , boost::asio::stream_socket_service<boost::asio::ip::tcp> > * Socket,
|
||||
|
2
map.cpp
2
map.cpp
@ -477,8 +477,8 @@ void Mapa::initFromBytes(unsigned char * bufor)
|
||||
if(!objects[f]->defInfo)
|
||||
continue;
|
||||
addBlockVisTiles(objects[f]);
|
||||
|
||||
}
|
||||
std::cout<<"\tCalculating blocked/visitable tiles: "<<th.getDif()<<std::endl;
|
||||
}
|
||||
void Mapa::removeBlockVisTiles(CGObjectInstance * obj)
|
||||
{
|
||||
|
@ -811,6 +811,26 @@ upgend:
|
||||
sha.artifWorn[9+aid] = aid;
|
||||
sendAndApply(&sha);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 511: //trade at marketplace
|
||||
{
|
||||
ui8 player;
|
||||
ui32 mode, id1, id2, val;
|
||||
c >> player >> mode >> id1 >> id2 >> val;
|
||||
val = std::min(si32(val),gs->players[player].resources[id1]);
|
||||
double uzysk = (double)gs->resVals[id1] * val * gs->getMarketEfficiency(player);
|
||||
uzysk /= gs->resVals[id2];
|
||||
SetResource sr;
|
||||
sr.player = player;
|
||||
sr.resid = id1;
|
||||
sr.val = gs->players[player].resources[id1] - val;
|
||||
sendAndApply(&sr);
|
||||
|
||||
sr.resid = id2;
|
||||
sr.val = gs->players[player].resources[id2] + (int)uzysk;
|
||||
sendAndApply(&sr);
|
||||
|
||||
break;
|
||||
}
|
||||
case 2001:
|
||||
@ -954,9 +974,11 @@ CGameHandler::~CGameHandler(void)
|
||||
void CGameHandler::init(StartInfo *si, int Seed)
|
||||
{
|
||||
Mapa *map = new Mapa(si->mapname);
|
||||
std::cout << "Map loaded!" << std::endl;
|
||||
gs = new CGameState();
|
||||
std::cout << "Gamestate created!" << std::endl;
|
||||
gs->init(si,map,Seed);
|
||||
|
||||
std::cout << "Gamestate initialized!" << std::endl;
|
||||
/****************************LUA OBJECT SCRIPTS************************************************/
|
||||
//std::vector<std::string> * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files
|
||||
//for (int i=0; i<lf->size(); i++)
|
||||
|
@ -26,6 +26,7 @@ bool end2 = false;
|
||||
CVCMIServer::CVCMIServer()
|
||||
: io(new io_service()), acceptor(new tcp::acceptor(*io, tcp::endpoint(tcp::v4(), 3030)))
|
||||
{
|
||||
std::cout << "CVCMIServer created!" <<std::endl;
|
||||
}
|
||||
CVCMIServer::~CVCMIServer()
|
||||
{
|
||||
@ -94,9 +95,10 @@ void CVCMIServer::start()
|
||||
acceptor->accept(*s,error);
|
||||
if (error)
|
||||
{
|
||||
std::cout<<"Got connection but there is an error " << std::endl;
|
||||
std::cout<<"Got connection but there is an error " << std::endl << error;
|
||||
return;
|
||||
}
|
||||
std::cout<<"We've accepted someone... " << std::endl;
|
||||
CConnection *connection = new CConnection(s,NAME,std::cout);
|
||||
std::cout<<"Got connection!" << std::endl;
|
||||
while(!end2)
|
||||
|
Loading…
Reference in New Issue
Block a user