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

Minor changes.

This commit is contained in:
Michał W. Urbańczyk 2010-08-18 09:50:25 +00:00
parent 48b262756b
commit 4aa60cd40e
10 changed files with 55 additions and 34 deletions

View File

@ -51,6 +51,8 @@ struct PlayerSettings
struct StartInfo
{
enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN};
ui8 mode; //0 - new game; 1 - load game; 2 - campaign
ui8 difficulty; //0=easy; 4=impossible
std::map<int, PlayerSettings> playerInfos; //color indexed

View File

@ -639,11 +639,11 @@ void startGame(StartInfo * options)
CPlayerInterface::howManyPeople = 0;
switch(options->mode) //new game
{
case 0:
case 2:
case StartInfo::NEW_GAME:
case StartInfo::CAMPAIGN:
client->newGame(NULL, options);
break;
case 1:
case StartInfo::LOAD_GAME:
std::string fname = options->mapname;
boost::algorithm::erase_last(fname,".vlgm1");
client->loadGame(fname);

View File

@ -1818,12 +1818,12 @@ void CPlayerInterface::gameOver(ui8 player, bool victory )
howManyPeople--;
if(!howManyPeople) //all human players eliminated
{
//return to main menu
SDL_Event event;
event.type = SDL_USEREVENT;
event.user.code = 2;
SDL_PushEvent(&event);
if(cb->getStartInfo()->mode != StartInfo::CAMPAIGN)
requestReturningToMainMenu();
//TODO next campaign scenario
}
}
else
{
@ -2083,6 +2083,14 @@ void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj)
showShipyardDialog(obj);
}
void CPlayerInterface::requestReturningToMainMenu()
{
SDL_Event event;
event.type = SDL_USEREVENT;
event.user.code = 2;
SDL_PushEvent(&event);
}
CPlayerInterface::SpellbookLastSetting::SpellbookLastSetting()
{
spellbookLastPageBattle = spellbokLastPageAdvmap = 0;

View File

@ -244,6 +244,7 @@ public:
void acceptTurn(); //used during hot seat after your turn message is close
void tryDiggging(const CGHeroInstance *h);
void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard;
void requestReturningToMainMenu();
CPlayerInterface(int Player);//c-tor
~CPlayerInterface();//d-tor

View File

@ -337,7 +337,7 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, bool MultiPlayer)
sInfo.difficulty = 1;
current = NULL;
sInfo.mode = (Type == CMenuScreen::newGame ? 0 : 1);
sInfo.mode = (Type == CMenuScreen::newGame ? StartInfo::NEW_GAME : StartInfo::LOAD_GAME);
sInfo.turnTime = 0;
curTab = NULL;
@ -2363,7 +2363,7 @@ void CBonusSelection::selectMap( int whichOne )
{
sInfo.difficulty = ourCampaign->camp->scenarios[whichOne].difficulty;
sInfo.mapname = ourCampaign->camp->header.filename;
sInfo.mode = 2;
sInfo.mode = StartInfo::CAMPAIGN;
//get header
int i = 0;

View File

@ -805,4 +805,15 @@ void CArtHandler::clearHlpLists()
minors.clear();
majors.clear();
relics.clear();
}
void CArtHandler::initAllowedArtifactsList(const std::vector<ui8> &allowed)
{
allowedArtifacts.clear();
clearHlpLists();
for (int i=0; i<144; ++i) //yes, 144
{
if (allowed[i])
allowedArtifacts.push_back(artifacts[i]);
}
}

View File

@ -74,6 +74,7 @@ public:
bool isBigArtifact (ui32 artID) {return bigArtifacts.find(artID) != bigArtifacts.end();}
void equipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID, ui32 artifactID);
void unequipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID);
void initAllowedArtifactsList(const std::vector<ui8> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
static int convertMachineID(int id, bool creToArt);
CArtHandler();
~CArtHandler();

View File

@ -470,7 +470,7 @@ bool CScenarioTravel::STravelBonus::isBonusForHero() const
void CCampaignState::initNewCampaign( const StartInfo &si )
{
assert(si.mode == 2);
assert(si.mode == StartInfo::CAMPAIGN);
campaignName = si.mapname;
currentMap = si.whichMapInCampaign;

View File

@ -1267,33 +1267,31 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
}
};
VLC->arth->allowedArtifacts.clear();
VLC->arth->clearHlpLists();
switch(si->mode)
{
case 0:
case StartInfo::NEW_GAME:
map = new Mapa(si->mapname);
for (int i=0; i<144; ++i) //yes, 144
break;
case StartInfo::CAMPAIGN:
{
if (map->allowedArtifact[i])
VLC->arth->allowedArtifacts.push_back(VLC->arth->artifacts[i]);
}
break;
case 2:
campaign = new CCampaignState();
campaign->initNewCampaign(*si);
std::string &mapContent = campaign->camp->mapPieces[si->whichMapInCampaign];
map = new Mapa();
map->initFromBytes((const unsigned char*)mapContent.c_str());
for (int i=0; i<144; ++i)
{
if (map->allowedArtifact[i])
VLC->arth->allowedArtifacts.push_back(VLC->arth->artifacts[i]);
assert(vstd::contains(campaign->camp->mapPieces, si->whichMapInCampaign));
campaign = new CCampaignState();
campaign->initNewCampaign(*si);
std::string &mapContent = campaign->camp->mapPieces[si->whichMapInCampaign];
map = new Mapa();
map->initFromBytes((const unsigned char*)mapContent.c_str());
}
break;
default:
tlog1 << "Wrong mode: " << (int)si->mode << std::endl;
return;
}
VLC->arth->initAllowedArtifactsList(map->allowedArtifact);
tlog0 << "Map loaded!" << std::endl;
//tlog0 <<"Reading and detecting map file (together): "<<tmh.getDif()<<std::endl;
if(checksum)
{
@ -1434,7 +1432,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
map->objects.push_back(nnn);
map->addBlockVisTiles(nnn);
//give campaign bonus
if (si->mode == 2 && getPlayer(nnn->tempOwner)->human)
if (si->mode == StartInfo::CAMPAIGN && getPlayer(nnn->tempOwner)->human)
{
HLP::giveCampaignBonusToHero(nnn, si, campaign->camp->scenarios[si->whichMapInCampaign].travelOptions);
}
@ -1482,7 +1480,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
}
//give start resource bonus in case of campaign
if (si->mode == 2)
if (si->mode == StartInfo::CAMPAIGN)
{
CScenarioTravel::STravelBonus chosenBonus =
campaign->camp->scenarios[si->whichMapInCampaign].travelOptions.bonusesToChoose[si->choosenCampaignBonus];
@ -1566,7 +1564,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
hpool.pavailable[map->disposedHeroes[i].ID] = map->disposedHeroes[i].players;
}
if (si->mode == 2) //give campaign bonuses for specific / best hero
if (si->mode == StartInfo::CAMPAIGN) //give campaign bonuses for specific / best hero
{
CScenarioTravel::STravelBonus chosenBonus =
@ -1763,7 +1761,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
}
//campaign bonuses for towns
if (si->mode == 2)
if (si->mode == StartInfo::CAMPAIGN)
{
CScenarioTravel::STravelBonus chosenBonus =
campaign->camp->scenarios[si->whichMapInCampaign].travelOptions.bonusesToChoose[si->choosenCampaignBonus];

View File

@ -81,7 +81,7 @@ void CVCMIServer::newGame(CConnection *c)
FILE * f = fopen(si->mapname.c_str(),"r");
problem = !f;
#endif
if(problem && si->mode == 0) //TODO some checking for campaigns
if(problem && si->mode == StartInfo::NEW_GAME) //TODO some checking for campaigns
{
*c << ui8(problem); //WRONG!
return;