mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
* some functions have been written
* added CConsoleHandler to interact with user (it should be testing - only, the real console should be as in h3) pathfinder MAY work now, but it isn't tested
This commit is contained in:
parent
8cc7e103bd
commit
d708669a75
21
CConsoleHandler.cpp
Normal file
21
CConsoleHandler.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "CConsoleHandler.h"
|
||||
#include "stdafx.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_thread.h"
|
||||
|
||||
int internalFunc(void * nothingUsed)
|
||||
{
|
||||
char * usersMessage = new char[500];
|
||||
std::string readed;
|
||||
while(true)
|
||||
{
|
||||
std::cin.getline(usersMessage, 500);
|
||||
readed = std::string(usersMessage);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CConsoleHandler::runConsole()
|
||||
{
|
||||
SDL_Thread * myth = SDL_CreateThread(&internalFunc, NULL);
|
||||
}
|
10
CConsoleHandler.h
Normal file
10
CConsoleHandler.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef CCONSOLEHANDLER_H
|
||||
#define CCONSOLEHANDLER_H
|
||||
|
||||
class CConsoleHandler
|
||||
{
|
||||
public:
|
||||
void runConsole();
|
||||
};
|
||||
|
||||
#endif //CCONSOLEHANDLER_H
|
@ -20,6 +20,7 @@
|
||||
#include "CGameInterface.h"
|
||||
#include "CGameState.h"
|
||||
#include "mapHandler.h"
|
||||
#include "CConsoleHandler.h"
|
||||
#include "SDL.h"
|
||||
|
||||
#include <vector>
|
||||
@ -51,6 +52,7 @@ public:
|
||||
CLodHandler * spriteh;
|
||||
CLodHandler * bitmaph;
|
||||
CGeneralTextHandler * generaltexth;
|
||||
CConsoleHandler * consoleh;
|
||||
int localPlayer;
|
||||
std::vector<CGameInterface *> playerint;
|
||||
std::vector<SDL_Color> playerColors;
|
||||
|
148
CHeroHandler.cpp
148
CHeroHandler.cpp
@ -317,11 +317,25 @@ void CHeroHandler::initHeroClasses()
|
||||
{
|
||||
heroes[gg]->heroClass = heroClasses[heroes[gg]->heroType];
|
||||
}
|
||||
initTerrainCosts();
|
||||
}
|
||||
|
||||
unsigned int CHeroInstance::getTileCost(EterrainType & ttype, Eroad & rdtype, Eriver & rvtype)
|
||||
{
|
||||
return 100; //TODO: finish it
|
||||
unsigned int ret = type->heroClass->terrCosts[ttype];
|
||||
switch(rdtype)
|
||||
{
|
||||
case Eroad::dirtRoad:
|
||||
ret*=0.75;
|
||||
break;
|
||||
case Eroad::grazvelRoad:
|
||||
ret*=0.667;
|
||||
break;
|
||||
case Eroad::cobblestoneRoad:
|
||||
ret*=0.5;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned int CHeroHandler::level(unsigned int experience)
|
||||
@ -331,5 +345,133 @@ unsigned int CHeroHandler::level(unsigned int experience)
|
||||
|
||||
unsigned int CHeroInstance::getLowestCreatureSpeed()
|
||||
{
|
||||
return 1; //TODO: finish it
|
||||
}
|
||||
unsigned int sl = 100;
|
||||
for(int h=0; h<army.slots.size(); ++h)
|
||||
{
|
||||
if(army.slots[h].first->speed<sl)
|
||||
sl = army.slots[h].first->speed;
|
||||
}
|
||||
return sl;
|
||||
}
|
||||
|
||||
void CHeroHandler::initTerrainCosts()
|
||||
{
|
||||
for(int i=0; i<heroClasses.size(); ++i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case EHeroClasses::HERO_KNIGHT: case EHeroClasses::HERO_CLERIC:
|
||||
{
|
||||
heroClasses[i]->terrCosts.push_back(100); //dirt
|
||||
heroClasses[i]->terrCosts.push_back(150); //sand
|
||||
heroClasses[i]->terrCosts.push_back(100); //grass
|
||||
heroClasses[i]->terrCosts.push_back(150); //snow
|
||||
heroClasses[i]->terrCosts.push_back(175); //swamp
|
||||
heroClasses[i]->terrCosts.push_back(125); //rough
|
||||
heroClasses[i]->terrCosts.push_back(100); //subterrain
|
||||
heroClasses[i]->terrCosts.push_back(100); //lava
|
||||
heroClasses[i]->terrCosts.push_back(-1); //water
|
||||
heroClasses[i]->terrCosts.push_back(-1); //rock
|
||||
break;
|
||||
}
|
||||
case EHeroClasses::HERO_RANGER: case EHeroClasses::HERO_DRUID:
|
||||
{
|
||||
heroClasses[i]->terrCosts.push_back(100); //dirt
|
||||
heroClasses[i]->terrCosts.push_back(150); //sand
|
||||
heroClasses[i]->terrCosts.push_back(100); //grass
|
||||
heroClasses[i]->terrCosts.push_back(150); //snow
|
||||
heroClasses[i]->terrCosts.push_back(175); //swamp
|
||||
heroClasses[i]->terrCosts.push_back(125); //rough
|
||||
heroClasses[i]->terrCosts.push_back(100); //subterrain
|
||||
heroClasses[i]->terrCosts.push_back(100); //lava
|
||||
heroClasses[i]->terrCosts.push_back(-1); //water
|
||||
heroClasses[i]->terrCosts.push_back(-1); //rock
|
||||
break;
|
||||
}
|
||||
case EHeroClasses::HERO_ALCHEMIST: case EHeroClasses::HERO_WIZARD:
|
||||
{
|
||||
heroClasses[i]->terrCosts.push_back(100); //dirt
|
||||
heroClasses[i]->terrCosts.push_back(150); //sand
|
||||
heroClasses[i]->terrCosts.push_back(100); //grass
|
||||
heroClasses[i]->terrCosts.push_back(100); //snow
|
||||
heroClasses[i]->terrCosts.push_back(175); //swamp
|
||||
heroClasses[i]->terrCosts.push_back(125); //rough
|
||||
heroClasses[i]->terrCosts.push_back(100); //subterrain
|
||||
heroClasses[i]->terrCosts.push_back(100); //lava
|
||||
heroClasses[i]->terrCosts.push_back(-1); //water
|
||||
heroClasses[i]->terrCosts.push_back(-1); //rock
|
||||
break;
|
||||
}
|
||||
case EHeroClasses::HERO_DEMONIAC: case EHeroClasses::HERO_HERETIC:
|
||||
{
|
||||
heroClasses[i]->terrCosts.push_back(100); //dirt
|
||||
heroClasses[i]->terrCosts.push_back(150); //sand
|
||||
heroClasses[i]->terrCosts.push_back(100); //grass
|
||||
heroClasses[i]->terrCosts.push_back(150); //snow
|
||||
heroClasses[i]->terrCosts.push_back(175); //swamp
|
||||
heroClasses[i]->terrCosts.push_back(125); //rough
|
||||
heroClasses[i]->terrCosts.push_back(100); //subterrain
|
||||
heroClasses[i]->terrCosts.push_back(100); //lava
|
||||
heroClasses[i]->terrCosts.push_back(-1); //water
|
||||
heroClasses[i]->terrCosts.push_back(-1); //rock
|
||||
break;
|
||||
}
|
||||
case EHeroClasses::HERO_DEATHKNIGHT: case EHeroClasses::HERO_NECROMANCER:
|
||||
{
|
||||
heroClasses[i]->terrCosts.push_back(100); //dirt
|
||||
heroClasses[i]->terrCosts.push_back(150); //sand
|
||||
heroClasses[i]->terrCosts.push_back(100); //grass
|
||||
heroClasses[i]->terrCosts.push_back(150); //snow
|
||||
heroClasses[i]->terrCosts.push_back(175); //swamp
|
||||
heroClasses[i]->terrCosts.push_back(125); //rough
|
||||
heroClasses[i]->terrCosts.push_back(100); //subterrain
|
||||
heroClasses[i]->terrCosts.push_back(100); //lava
|
||||
heroClasses[i]->terrCosts.push_back(-1); //water
|
||||
heroClasses[i]->terrCosts.push_back(-1); //rock
|
||||
break;
|
||||
}
|
||||
case EHeroClasses::HERO_WARLOCK: case EHeroClasses::HERO_OVERLORD:
|
||||
{
|
||||
heroClasses[i]->terrCosts.push_back(100); //dirt
|
||||
heroClasses[i]->terrCosts.push_back(150); //sand
|
||||
heroClasses[i]->terrCosts.push_back(100); //grass
|
||||
heroClasses[i]->terrCosts.push_back(150); //snow
|
||||
heroClasses[i]->terrCosts.push_back(175); //swamp
|
||||
heroClasses[i]->terrCosts.push_back(125); //rough
|
||||
heroClasses[i]->terrCosts.push_back(100); //subterrain
|
||||
heroClasses[i]->terrCosts.push_back(100); //lava
|
||||
heroClasses[i]->terrCosts.push_back(-1); //water
|
||||
heroClasses[i]->terrCosts.push_back(-1); //rock
|
||||
break;
|
||||
}
|
||||
case EHeroClasses::HERO_BARBARIAN: case EHeroClasses::HERO_BATTLEMAGE:
|
||||
{
|
||||
heroClasses[i]->terrCosts.push_back(100); //dirt
|
||||
heroClasses[i]->terrCosts.push_back(150); //sand
|
||||
heroClasses[i]->terrCosts.push_back(100); //grass
|
||||
heroClasses[i]->terrCosts.push_back(150); //snow
|
||||
heroClasses[i]->terrCosts.push_back(175); //swamp
|
||||
heroClasses[i]->terrCosts.push_back(100); //rough
|
||||
heroClasses[i]->terrCosts.push_back(100); //subterrain
|
||||
heroClasses[i]->terrCosts.push_back(100); //lava
|
||||
heroClasses[i]->terrCosts.push_back(-1); //water
|
||||
heroClasses[i]->terrCosts.push_back(-1); //rock
|
||||
break;
|
||||
}
|
||||
case EHeroClasses::HERO_BEASTMASTER: case EHeroClasses::HERO_WITCH:
|
||||
{
|
||||
heroClasses[i]->terrCosts.push_back(100); //dirt
|
||||
heroClasses[i]->terrCosts.push_back(150); //sand
|
||||
heroClasses[i]->terrCosts.push_back(100); //grass
|
||||
heroClasses[i]->terrCosts.push_back(150); //snow
|
||||
heroClasses[i]->terrCosts.push_back(100); //swamp
|
||||
heroClasses[i]->terrCosts.push_back(125); //rough
|
||||
heroClasses[i]->terrCosts.push_back(100); //subterrain
|
||||
heroClasses[i]->terrCosts.push_back(100); //lava
|
||||
heroClasses[i]->terrCosts.push_back(-1); //water
|
||||
heroClasses[i]->terrCosts.push_back(-1); //rock
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
int proKnowledge[2]; //probability of gaining knowledge point on levels [0]: 2 - 9; [1]: 10+ (out of 100)
|
||||
std::vector<int> proSec; //probabilities of gaining secondary skills (out of 112), in id order
|
||||
int selectionProbability[9]; //probability of selection in towns
|
||||
std::vector<int> terrCosts; //default costs of going through terrains: dirt, sand, grass, snow, swamp, rough, subterrain, lava, water, rock; -1 means terrain is imapassable
|
||||
};
|
||||
|
||||
class CHeroInstance
|
||||
@ -75,6 +76,7 @@ public:
|
||||
void loadPortraits();
|
||||
void initHeroClasses();
|
||||
~CHeroHandler();
|
||||
void initTerrainCosts();
|
||||
};
|
||||
|
||||
|
||||
|
3
CMT.cpp
3
CMT.cpp
@ -37,6 +37,7 @@
|
||||
#include "global.h"
|
||||
#include "CPreGame.h"
|
||||
#include "CGeneralTextHandler.h"
|
||||
#include "CConsoleHandler.h"
|
||||
|
||||
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
|
||||
# include <fcntl.h>
|
||||
@ -110,6 +111,8 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
SDL_WM_SetCaption(NAME,""); //set window title
|
||||
CGameInfo * cgi = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.)
|
||||
CGameInfo::mainObj = cgi;
|
||||
cgi->consoleh = new CConsoleHandler;
|
||||
cgi->consoleh->runConsole();
|
||||
cgi->mush = mush;
|
||||
|
||||
THC std::cout<<"Initializing screen, fonts and sound handling: "<<tmh.getDif()<<std::endl;
|
||||
|
2
global.h
2
global.h
@ -16,7 +16,7 @@ enum Eformat { WoG=0x33, AB=0x15, RoE=0x0e, SoD=0x1c};
|
||||
enum EvictoryConditions {artifact, gatherTroop, gatherResource, buildCity, buildGrail, beatHero,
|
||||
captureCity, beatMonster, takeDwellings, takeMines, transportItem, winStandard=255};
|
||||
enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255};
|
||||
enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HREO_ALCHEMIST, HERO_WIZARD,
|
||||
enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HERO_ALCHEMIST, HERO_WIZARD,
|
||||
HERO_DEMONIAC, HERO_HERETIC, HERO_DEATHKNIGHT, HERO_NECROMANCER, HERO_WARLOCK, HERO_OVERLORD,
|
||||
HERO_BARBARIAN, HERO_BATTLEMAGE, HERO_BEASTMASTER, HERO_WITCH, HERO_PLANESWALKER, HERO_ELEMENTALIST};
|
||||
|
||||
|
@ -827,40 +827,10 @@ char & CMapHandler::undVisAccess(int x, int y)
|
||||
|
||||
int CMapHandler::getCost(int3 &a, int3 &b, CHeroInstance *hero)
|
||||
{
|
||||
int ret = 1500; //basic value
|
||||
switch(hero->getLowestCreatureSpeed())
|
||||
{
|
||||
case 0: case 1: case 2: case 3: case 4:
|
||||
{
|
||||
ret+=0;
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
ret+=100;
|
||||
break;
|
||||
}
|
||||
case 6: case 7:
|
||||
{
|
||||
ret+=200;
|
||||
break;
|
||||
}
|
||||
case 8:
|
||||
{
|
||||
ret+=300;
|
||||
break;
|
||||
}
|
||||
case 9: case 10:
|
||||
{
|
||||
ret+=400;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
ret+=500;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][a.y][a.z].malle];
|
||||
if(!(a.x==b.x || a.y==b.y))
|
||||
ret*=1.4142;
|
||||
|
||||
return ret; //TODO: finish it
|
||||
//TODO: use hero's pathfinding skill during calculating cost
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user