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

* next part of bonus selection screen (including Ivan's config)

This commit is contained in:
mateuszb 2010-02-16 17:28:56 +00:00
parent 4035155969
commit 968148c4dc
5 changed files with 346 additions and 17 deletions

View File

@ -2058,13 +2058,16 @@ void CHotSeatPlayers::enterSelectionScreen()
GH.pushInt(new CSelectionScreen(CMenuScreen::newGame)); GH.pushInt(new CSelectionScreen(CMenuScreen::newGame));
} }
CBonusSelection::CBonusSelection( const CCampaign * ourCampaign, int whichMap ) CBonusSelection::CBonusSelection( const CCampaign * _ourCampaign, int _whichMap )
: ourCampaign(_ourCampaign), whichMap(_whichMap), highlightedRegion(NULL)
{ {
OBJ_CONSTRUCTION; OBJ_CONSTRUCTION;
static const std::string bgNames [] = {"E1_BG.BMP", "G2_BG.BMP", "E2_BG.BMP", "G1_BG.BMP", "G3_BG.BMP", "N1_BG.BMP", static const std::string bgNames [] = {"E1_BG.BMP", "G2_BG.BMP", "E2_BG.BMP", "G1_BG.BMP", "G3_BG.BMP", "N1_BG.BMP",
"S1_BG.BMP", "BR_BG.BMP", "IS_BG.BMP", "KR_BG.BMP", "NI_BG.BMP", "TA_BG.BMP", "AR_BG.BMP", "HS_BG.BMP", "S1_BG.BMP", "BR_BG.BMP", "IS_BG.BMP", "KR_BG.BMP", "NI_BG.BMP", "TA_BG.BMP", "AR_BG.BMP", "HS_BG.BMP",
"BB_BG.BMP", "NB_BG.BMP", "EL_BG.BMP", "RN_BG.BMP", "UA_BG.BMP", "SP_BG.BMP"}; "BB_BG.BMP", "NB_BG.BMP", "EL_BG.BMP", "RN_BG.BMP", "UA_BG.BMP", "SP_BG.BMP"};
loadPositionsOfGraphics();
background = BitmapHandler::loadBitmap(bgNames[ourCampaign->header.mapVersion]); background = BitmapHandler::loadBitmap(bgNames[ourCampaign->header.mapVersion]);
SDL_Surface * panel = BitmapHandler::loadBitmap("CAMPBRF.BMP"); SDL_Surface * panel = BitmapHandler::loadBitmap("CAMPBRF.BMP");
@ -2146,6 +2149,29 @@ CBonusSelection::CBonusSelection( const CCampaign * ourCampaign, int whichMap )
SDL_FreeSurface(panel); SDL_FreeSurface(panel);
//bonus choosing
printAtLoc(CGI->generaltexth->allTexts[71], 510, 431, FONT_MEDIUM, zwykly, background); //Choose a bonus:
//difficulty
printAtLoc("Difficulty", 691, 431, FONT_MEDIUM, zwykly, background); //Difficulty
//set left part of window
for (int g=0; g<ourCampaign->scenarios.size(); ++g)
{
if(ourCampaign->conquerable(g))
{
regions.push_back(new CRegion(this, true, true, g));
if (highlightedRegion == NULL)
{
highlightedRegion = regions.back();
}
}
else if (ourCampaign->scenarios[g].conquered) //display as striped
{
regions.push_back(new CRegion(this, false, false, g));
}
}
} }
CBonusSelection::~CBonusSelection() CBonusSelection::~CBonusSelection()
@ -2163,3 +2189,103 @@ void CBonusSelection::showAll( SDL_Surface * to )
CIntObject::showAll(to); CIntObject::showAll(to);
blitAt(background, pos.x, pos.y, to); blitAt(background, pos.x, pos.y, to);
} }
void CBonusSelection::loadPositionsOfGraphics()
{
std::ifstream is((GVCMIDirs.UserPath + "/config/campaign_regions.txt").c_str(), std::ios_base::binary | std::ios_base::in);
assert(is.is_open());
for (int g=0; g<CGI->generaltexth->campaignMapNames.size(); ++g)
{
SCampPositions sc;
is >> sc.campPrefix;
is >> sc.colorSuffixLength;
bool contReading = true;
while(contReading)
{
SCampPositions::SRegionDesc rd;
is >> rd.infix;
if(rd.infix == "END")
{
contReading = false;
}
else
{
is >> rd.xpos >> rd.ypos;
sc.regions.push_back(rd);
}
}
campDescriptions.push_back(sc);
}
}
CBonusSelection::CRegion::CRegion( CBonusSelection * _owner, bool _accessible, bool _selectable, int _myNumber )
: owner(_owner), accessible(_accessible), selectable(_selectable), myNumber(_myNumber)
{
OBJ_CONSTRUCTION;
static const std::string colors[2][8] = {
{"R", "B", "N", "G", "O", "V", "T", "P"},
{"Re", "Bl", "Br", "Gr", "Or", "Vi", "Te", "Pi"}};
const SCampPositions & campDsc = owner->campDescriptions[owner->ourCampaign->header.mapVersion];
const SCampPositions::SRegionDesc & desc = campDsc.regions[myNumber];
pos.x = desc.xpos;
pos.y = desc.ypos;
//loading of graphics
std::string prefix = campDsc.campPrefix + desc.infix + "_";
std::string suffix = colors[campDsc.colorSuffixLength - 1][owner->ourCampaign->scenarios[myNumber].regionColor];
static const std::string infix [] = {"En", "Se", "Co"};
for (int g = 0; g < ARRAY_COUNT(infix); g++)
{
graphics[g] = BitmapHandler::loadBitmap(prefix + infix[g] + suffix + ".BMP");
}
}
CBonusSelection::CRegion::~CRegion()
{
for (int g=0; g<ARRAY_COUNT(graphics); ++g)
{
SDL_FreeSurface(graphics[g]);
}
}
void CBonusSelection::CRegion::clickLeft( tribool down, bool previousState )
{
//select if selectable & clicked inside our graphic
if(!down && selectable)
{
//owner->highlightedRegion = this;
}
}
void CBonusSelection::CRegion::clickRight( tribool down, bool previousState )
{
//show r-click text
}
void CBonusSelection::CRegion::show( SDL_Surface * to )
{
const SCampPositions::SRegionDesc & desc = owner->campDescriptions[owner->ourCampaign->header.mapVersion].regions[myNumber];
if (!accessible)
{
//show as striped
blitAt(graphics[2], pos.x, pos.y, to);
}
else if (this == owner->highlightedRegion)
{
//show as selected
blitAt(graphics[1], pos.x, pos.y, to);
}
else
{
//show as not selected selected
blitAt(graphics[0], pos.x, pos.y, to);
}
}

View File

@ -256,8 +256,48 @@ class CBonusSelection : public CIntObject
{ {
SDL_Surface * background; SDL_Surface * background;
AdventureMapButton * startB, * backB; AdventureMapButton * startB, * backB;
struct SCampPositions
{
std::string campPrefix;
int colorSuffixLength;
struct SRegionDesc
{
std::string infix;
int xpos, ypos;
};
std::vector<SRegionDesc> regions;
};
std::vector<SCampPositions> campDescriptions;
class CRegion : public CIntObject
{
CBonusSelection * owner;
SDL_Surface * graphics[3]; //[0] - not selected, [1] - selected, [2] - striped
bool accessible; //false if region should be striped
bool selectable; //true if region should be selectable
int myNumber; //number of region
public:
CRegion(CBonusSelection * _owner, bool _accessible, bool _selectable, int _myNumber);
~CRegion();
void clickLeft(tribool down, bool previousState);
void clickRight(tribool down, bool previousState);
void show(SDL_Surface * to);
};
std::vector<CRegion *> regions;
CRegion * highlightedRegion;
void loadPositionsOfGraphics();
const CCampaign * ourCampaign;
int whichMap;
public: public:
CBonusSelection(const CCampaign * ourCampaign, int whichMap); CBonusSelection(const CCampaign * _ourCampaign, int _whichMap);
~CBonusSelection(); ~CBonusSelection();
void showAll(SDL_Surface * to); void showAll(SDL_Surface * to);

131
config/campaign_regions.txt Normal file
View File

@ -0,0 +1,131 @@
E1 1
A 270 332
B 138 113
C 26 70
P1 256 127
P2 57 314
P3 137 310
P4 44 163
END
G2 1
A 56 90
B 316 49
C 54 378
D 151 126
END
E2 1
A 131 202
B 60 145
C 92 261
D 218 307
END
G1 1
A 57 314
B 137 309
C 44 163
END
G3 1
A 289 376
B 60 147
C 131 202
END
N1 1
A 42 94
B 309 290
CD 188 202
END
S1 1
A 263 199
B 182 210
C 82 152
END
BR 2
A 18 233
B 125 381
C 224 357
D 192 320
END
IS 2
A 294 399
B 183 293
C 40 92
D 294 398
END
KR 2
A 148 323
B 192 235
C 136 158
D 87 107
END
NI 2
A 118 111
B 223 145
C 320 213
D 233 250
END
TA 2
A 228 233
B 147 194
C 112 97
END
AR 2
A 135 238
B 135 121
C 206 155
D 105 397
E 109 275
F 158 188
G 200 261
H 232 197
END
HS 2
A 140 326
B 238 275
C 22 161
D 5 9
END
BB 2
A 167 342
B 217 263
C 0 71
D 291 79
E 316 199
END
NB 2
A 6 292
B 161 334
C 63 195
D 56 46
END
EL 2
A 11 73
B 0 241
C 254 34
D 91 144
END
RN 2
A 84 319
B 194 275
C 67 185
D 77 30
END
UA 2
A 157 409
B 62 346
C 8 8
D 206 1
E 132 357
F 184 83
G 159 263
H 108 173
I 55 127
J 9 252
K 210 176
L 260 210
END
SP 2
A 7 295
B 44 141
C 141 21
D 243 156
END

View File

@ -79,17 +79,20 @@ CCampaign * CCampaignHandler::getCampaign( const std::string & name )
std::vector<ui32> h3mStarts = locateH3mStarts(cmpgn, it, realSize); std::vector<ui32> h3mStarts = locateH3mStarts(cmpgn, it, realSize);
if(h3mStarts.size() != howManyScenarios) assert(h3mStarts.size() <= howManyScenarios);
{ //it looks like we can have less scenarios than we should..
tlog1<<"Our heuristic for h3m start points gave wrong results for campaign " << name <<std::endl; //if(h3mStarts.size() != howManyScenarios)
tlog1<<"Please send this campaign to VCMI Project team to help us fix this problem" << std::endl; //{
delete [] cmpgn; // tlog1<<"Our heuristic for h3m start points gave wrong results for campaign " << name <<std::endl;
return NULL; // tlog1<<"Please send this campaign to VCMI Project team to help us fix this problem" << std::endl;
} // delete [] cmpgn;
// assert(0);
// return NULL;
//}
for (int g=0; g<howManyScenarios; ++g) for (int g=0; g<h3mStarts.size(); ++g)
{ {
if(g == howManyScenarios - 1) if(g == h3mStarts.size() - 1)
{ {
ret->mapPieces.push_back(std::string( cmpgn + h3mStarts[g], cmpgn + realSize )); ret->mapPieces.push_back(std::string( cmpgn + h3mStarts[g], cmpgn + realSize ));
} }
@ -141,11 +144,17 @@ CCampaignScenario CCampaignHandler::readScenarioFromMemory( const unsigned char
} }
}; };
CCampaignScenario ret; CCampaignScenario ret;
ret.conquered = false;
ret.mapName = readString(buffer, outIt); ret.mapName = readString(buffer, outIt);
ret.packedMapSize = readNormalNr(buffer, outIt); outIt += 4; ret.packedMapSize = readNormalNr(buffer, outIt); outIt += 4;
if(mapVersion == 18)//unholy alliance if(mapVersion == 18)//unholy alliance
outIt++; {
ret.preconditionRegion = buffer[outIt++]; ret.preconditionRegion = readNormalNr(buffer, outIt, 2); outIt += 2;
}
else
{
ret.preconditionRegion = buffer[outIt++];
}
ret.regionColor = buffer[outIt++]; ret.regionColor = buffer[outIt++];
ret.difficulty = buffer[outIt++]; ret.difficulty = buffer[outIt++];
ret.regionText = readString(buffer, outIt); ret.regionText = readString(buffer, outIt);
@ -181,6 +190,9 @@ CScenarioTravel CCampaignHandler::readScenarioTravelFromMemory( const unsigned c
switch(ret.startOptions) switch(ret.startOptions)
{ {
case 0:
//no bonuses. Seems to be OK
break;
case 1: //reading of bonuses player can choose case 1: //reading of bonuses player can choose
{ {
ret.playerColor = buffer[outIt++]; ret.playerColor = buffer[outIt++];
@ -369,3 +381,19 @@ bool CCampaignHandler::startsAt( const unsigned char * buffer, int size, int pos
} }
return true; return true;
} }
bool CCampaign::conquerable( int whichScenario ) const
{
if (scenarios[whichScenario].conquered)
{
return false;
}
//check preconditioned regions
for (int g=0; g<scenarios.size(); ++g)
{
if(( (1 << g) & scenarios[whichScenario].preconditionRegion ) && !scenarios[g].conquered)
return false; //prerequisite does not met
}
return true;
}

View File

@ -66,10 +66,11 @@ class DLL_EXPORT CCampaignScenario
{ {
public: public:
std::string mapName; std::string mapName;
ui32 packedMapSize; ui32 packedMapSize; //generally not used
ui8 preconditionRegion; ui16 preconditionRegion; //what we need to conquer to conquer this one (bitfield!)
ui8 regionColor; ui8 regionColor;
ui8 difficulty; ui8 difficulty;
ui8 conquered;
std::string regionText; std::string regionText;
@ -92,7 +93,8 @@ public:
template <typename Handler> void serialize(Handler &h, const int formatVersion) template <typename Handler> void serialize(Handler &h, const int formatVersion)
{ {
h & mapName & packedMapSize & preconditionRegion & regionColor & difficulty & regionText & prolog & epilog & travelOptions; h & mapName & packedMapSize & preconditionRegion & regionColor & difficulty & conquered & regionText &
prolog & epilog & travelOptions;
} }
}; };
@ -107,6 +109,8 @@ public:
{ {
h & header & scenarios & mapPieces; h & header & scenarios & mapPieces;
} }
bool conquerable(int whichScenario) const;
}; };
class DLL_EXPORT CCampaignHandler class DLL_EXPORT CCampaignHandler