1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

* redone def info handling

* redone randomization (mam nadziemę, że będzie toto działać)
* no more cheating pathfinder
* minor improvements
* version changed to 0.52
This commit is contained in:
Michał W. Urbańczyk 2008-02-05 03:56:45 +00:00
parent 21ec0b77d4
commit fe5bcc19cf
22 changed files with 775 additions and 1403 deletions

View File

@ -11,10 +11,10 @@ void CEmptyAI::init(ICallback * CB)
void CEmptyAI::yourTurn()
{
}
void CEmptyAI::heroKilled(const CHeroInstance *)
void CEmptyAI::heroKilled(const CGHeroInstance *)
{
}
void CEmptyAI::heroCreated(const CHeroInstance *)
void CEmptyAI::heroCreated(const CGHeroInstance *)
{
}
void CEmptyAI::heroMoved(const HeroMoveDetails &)

View File

@ -6,8 +6,8 @@ class CEmptyAI : public CGlobalAI
public:
void init(ICallback * CB);
void yourTurn();
void heroKilled(const CHeroInstance *);
void heroCreated(const CHeroInstance *);
void heroKilled(const CGHeroInstance *);
void heroCreated(const CGHeroInstance *);
void heroMoved(const HeroMoveDetails &);
void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) {};
void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID){};

View File

@ -19,6 +19,7 @@
#include "CPlayerInterface.h"
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp>
#include "hch/CDefObjInfoHandler.h"
#pragma warning (disable : 4311)
bool getGlobalFunc(lua_State * L, std::string fname)
{

View File

@ -57,7 +57,7 @@
#endif
#define CHUNK 16384
const char * NAME = "VCMI 0.51 \"Tirion\" Techdemo";
const char * NAME = "VCMI 0.52 \"Tirion\" Techdemo";
SDL_Surface * ekran, * screen, * screen2;
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
@ -82,7 +82,7 @@ void initGameState(CGameInfo * cgi)
cgi->state->players.insert(ins);
}
/******************RESOURCES****************************************************/
//TODO: zeby komputer dostawal inaczej niz gracz
//TODO: zeby komputer dostawal inaczej niz gracz
std::vector<int> startres;
std::ifstream tis("config/startres.txt");
int k;
@ -814,7 +814,10 @@ int _tmain(int argc, _TCHAR* argv[])
for (int i=0;i<cgi->playerint.size();i++)
{
cgi->state->currentPlayer=cgi->playerint[i]->playerID;
cgi->playerint[i]->yourTurn();
try
{
cgi->playerint[i]->yourTurn();
}HANDLE_EXCEPTION
}
}
}

View File

@ -174,6 +174,9 @@ CPath * CPathfinder::getPath(int3 src, int3 dest, const CGHeroInstance * hero, u
}
CPathNode * curNode = graph[dest.x][dest.y];
if(!curNode->theNodeBefore)
return NULL;
CPath * ret = new CPath;
while(curNode!=graph[src.x][src.y] && curNode != NULL)

72
config/basicCres.txt Normal file
View File

@ -0,0 +1,72 @@
0 0 0
0 1 2
0 2 4
0 3 6
0 4 8
0 5 10
0 6 12
0 7 150
1 0 14
1 1 16
1 2 18
1 3 20
1 4 22
1 5 24
1 6 26
1 7 151
2 0 28
2 1 30
2 2 32
2 3 34
2 4 36
2 5 38
2 6 40
2 7 152
3 0 42
3 1 44
3 2 46
3 3 48
3 4 50
3 5 52
3 6 54
3 7 153
4 0 56
4 1 58
4 2 60
4 3 62
4 4 64
4 5 66
4 6 68
4 7 154
5 0 70
5 1 72
5 2 74
5 3 76
5 4 78
5 5 80
5 6 82
5 7 155
6 0 84
6 1 86
6 2 88
6 3 90
6 4 92
6 5 94
6 6 96
6 7 156
7 0 98
7 1 100
7 2 104
7 3 106
7 4 102
7 5 108
7 6 110
7 7 157
8 0 118
8 1 112
8 2 115
8 3 114
8 4 113
8 5 120
8 6 130
8 7 158

99
config/cregens.txt Normal file
View File

@ -0,0 +1,99 @@
56 0
57 2
25 4
58 6
35 8
5 10
8 12
80 150
6 14
12 16
15 18
50 20
45 22
51 24
24 26
81 151
43 28
17 30
31 34
18 36
36 38
44 40
82 152
29 42
22 44
27 46
37 48
40 50
14 52
10 54
83 153
54 56
55 58
48 60
53 62
52 64
3 66
4 68
84 154
46 70
26 72
2 74
33 76
34 78
32 80
41 82
85 155
21 84
19 86
39 88
38 90
42 92
9 94
1 96
86 156
20 98
30 100
11 104
0 106
23 102
49 108
28 110
87 157
59 118
07 112
69 112
47 115
72 115
16 114
71 114
13 113
70 113
60 120
61 130
88 158
74 139
73 138
75 140
78 143
77 142
76 141
67 137
79 144
66 136
64 134
65 135
63 133
62 132
89 171
90 170
91 168
92 172
94 169
95 173
96 192
97 193
98 194
99 195
100 196

197
config/monsters.txt Normal file
View File

@ -0,0 +1,197 @@
0 1
1 1
2 2
3 2
4 3
5 3
6 4
7 4
8 5
9 5
10 6
11 6
12 7
13 7
14 1
15 1
16 2
17 2
18 3
19 3
20 4
21 4
22 5
23 5
24 6
25 6
26 7
27 7
28 1
29 1
30 2
31 2
32 3
33 3
34 4
35 4
36 5
37 5
38 6
39 6
40 7
41 7
42 1
43 1
44 2
45 2
46 3
47 3
48 4
49 4
50 5
51 5
52 6
53 6
54 7
55 7
56 1
57 1
58 2
59 2
60 3
61 3
62 4
63 4
64 5
65 5
66 6
67 6
68 7
69 7
70 1
71 1
72 2
73 2
74 3
75 3
76 4
77 4
78 5
79 5
80 6
81 6
82 7
83 7
84 1
85 1
86 2
87 2
88 3
89 3
90 4
91 4
92 5
93 5
94 6
95 6
96 7
97 7
98 1
99 1
100 2
101 2
102 3
103 3
104 4
105 4
106 5
107 5
108 6
109 6
110 7
111 7
112 2
113 5
114 4
115 3
116 4
117 5
118 1
119 1
120 6
121 6
122 000000
123 3
124 000000
125 5
126 000000
127 2
128 000000
129 4
130 7
131 7
132 10
133 10
134 8
135 10
136 6
137 4
138 1
139 1
140 2
141 3
142 3
143 2
144 5
145 000000
146 000000
147 000000
148 000000
149 000000
150 000000
151 8
152 8
153 8
154 8
155 8
156 8
157 8
158 8
159 000000
160 000000
161 000000
162 000000
163 000000
164 000000
165 000000
166 000000
167 000000
168 000000
169 000000
170 000000
171 000000
172 000000
173 000000
174 000000
175 000000
176 000000
177 000000
178 000000
179 000000
180 000000
181 000000
182 000000
183 000000
184 000000
185 000000
186 000000
187 000000
188 000000
189 000000
190 000000
191 000000
192 000000
193 000000
194 000000
195 000000
196 000000

19
config/townsDefs.txt Normal file
View File

@ -0,0 +1,19 @@
8
AVCCAST0.DEF
AVCRAMP0.DEF
AVCTOWR0.DEF
AVCINFT0.DEF
AVCNECR0.DEF
AVCDUNG0.DEF
AVCSTRO0.DEF
AVCFTRT0.DEF
AVCHFOR0.DEF
AVCCASZ0.DEF
AVCRAMZ0.DEF
AVCTOWZ0.DEF
AVCINFZ0.DEF
AVCNECZ0.DEF
AVCDUNZ0.DEF
AVCSTRZ0.DEF
AVCFORZ0.DEF
AVCHFORZ0.DEF

View File

@ -15,6 +15,17 @@
#include <sstream>
#include "../CLua.h"
int readInt(unsigned char * bufor, int bytCon)
{
int ret=0;
int amp=1;
for (int i=0; i<bytCon; i++)
{
ret+=bufor[i]*amp;
amp*=256;
}
return ret;
}
unsigned int intPow(unsigned int a, unsigned int b)
{
unsigned int ret=1;
@ -1692,225 +1703,9 @@ void CAmbarCendamo::deh3m()
(*(static_cast<CGObjectInstance*>(nt))) = *nobj;
delete nobj;
nobj = nt;
nt->identifier = readInt(spec->bytes,4);;
if(spec->unusualBuildins)
{
//nt->builtBuildings.insert(10);
//for(int ir = 0; ir < 6; ir++)
//{
// for(int bs=0;bs<8;bs++)
// {
// if(ir==0)
// {
// if (bs<3)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(11+bs);
// }
// }
// else if (bs<6)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(7+bs-3);
// }
// }
// else if(bs==6)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(5);
// }
// }
// else// if(bs==7)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(16);
// }
// }
// } //if(ir==0)
// else if(ir==1)
// {
// if(bs<2)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(14+bs);
// }
// }
// else if (bs==2)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// std::cout<<"Hej, sprawdz co to za budynek w miescie " <<nt<<std::endl;
// }
// }//bs==3 - not known what it is, 4 in 2. byte
// else
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(0+bs-3);
// }
// }
// }//else if(ir==1)
// else if(ir==2)
// {
// if(bs==0)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(6); //stocznia
// }
// }
// else if(bs==1)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(26); //grail
// }
// }
// else if(bs==2)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(17); //latarnia
// }
// }
// else if(bs==3)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(22); //bractwo miecza
// }
// }
// else if(bs==4)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(21); //stables
// }
// }
// else if(bs==5)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// std::cout<<"Hej, sprawdz co to za budynek2 w miescie " <<nt<<std::endl;
// }
// }
// else if(bs==6)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(30); //gen1
// }
// }
// else if(bs==7)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(37); //gen1+
// }
// }
// }//else if(ir==2)
// else if (ir==3)
// {
// if(bs==0)
// {
// //horda dla 1 poziomu???
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// std::cout<<"Hej, sprawdz co to za budynek3 w miescie " <<nt<<std::endl;
// }
// continue;
// }
// else if(bs<3)
// {
// if(bs==1)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(31); //gen2
// }
// }
// else
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(38); //gen2+
// }
// }
// }
// else if (bs==3)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// //horde building for 2lvl
// if(nt->builtBuildings.find(38)!=nt->builtBuildings.end())
// nt->builtBuildings.insert(19);
// else
// nt->builtBuildings.insert(18);
// }
// continue;
// }
// else if(bs==4)
// {
// if(bs%2) //nieulepszone
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert((int)(39+(bs/2)-2));
// }
// }
// else
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(32+(bs/2)-2);
// }
// }
// }
// }//else if (ir==3)
// else if (ir==4 && bs==0)
// {
// if(spec->buildingSettings[ir] & 1<<0)
// nt->builtBuildings.insert(40);
// if(spec->buildingSettings[ir] & 1<<2)
// nt->builtBuildings.insert(34);
// if(spec->buildingSettings[ir] & 1<<3)
// nt->builtBuildings.insert(41);
// if(spec->buildingSettings[ir] & 1<<4)
// {
// if(nt->builtBuildings.find(41)!=nt->builtBuildings.end())
// nt->builtBuildings.insert(25);
// else
// nt->builtBuildings.insert(24);
// }
// if(spec->buildingSettings[ir] & 1<<5)
// nt->builtBuildings.insert(35);
// if(spec->buildingSettings[ir] & 1<<6)
// nt->builtBuildings.insert(42);
// if(spec->buildingSettings[ir] & 1<<7)
// nt->builtBuildings.insert(36);
// }//else if (ir==4)
// else if (ir==5)
// {
// if(bs==0)
// {
// if(spec->buildingSettings[ir] & (1<<bs))
// {
// nt->builtBuildings.insert(43); //gen7+
// }
// }
// }//else if (ir==5)
// }
//}
//testowe zczytywanie h3mowych ID
for(int byte=0;byte<6;byte++)
{
for(int bit=0;bit<8;bit++)
@ -2057,13 +1852,9 @@ void CAmbarCendamo::deh3m()
case EDefType::CREGEN_DEF:
{
CCreGenObjInfo * spec = new CCreGenObjInfo;
spec->player = bufor[i]; ++i;
i+=3;
for(int ggg=0; ggg<4; ++ggg)
{
spec->bytes[ggg] = bufor[i]; ++i;
}
if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
spec->player = readNormalNr(i); i+=4;
spec->identifier = readNormalNr(i); i+=4;
if(!spec->identifier)
{
spec->asCastle = false;
spec->castles[0] = bufor[i]; ++i;
@ -2080,13 +1871,9 @@ void CAmbarCendamo::deh3m()
case EDefType::CREGEN2_DEF:
{
CCreGen2ObjInfo * spec = new CCreGen2ObjInfo;
spec->player = bufor[i]; ++i;
i+=3;
for(int ggg=0; ggg<4; ++ggg)
{
spec->bytes[ggg] = bufor[i]; ++i;
}
if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
spec->player = readNormalNr(i); i+=4;
spec->identifier = readNormalNr(i); i+=4;
if(!spec->identifier)
{
spec->asCastle = false;
spec->castles[0] = bufor[i]; ++i;
@ -2098,10 +1885,10 @@ void CAmbarCendamo::deh3m()
}
spec->minLevel = bufor[i]; ++i;
spec->maxLevel = bufor[i]; ++i;
if(spec->maxLevel>7)
spec->maxLevel = 7;
if(spec->minLevel<1)
spec->minLevel = 1;
//if(spec->maxLevel>7)
// spec->maxLevel = 7;
//if(spec->minLevel<1)
// spec->minLevel = 1;
nobj->setOwner(spec->player);
nobj->info = spec;
break;
@ -2344,7 +2131,14 @@ borderguardend:
THC std::cout<<"\tUnpacking defs: "<<th.getDif()<<std::endl;
for (int i=0;i<dhandlers.size();i++)
{
map.defy[i]->handler=dhandlers[i];
CGDefInfo* pom = CGI->dobjinfo->gobjs[map.defy[i]->id][map.defy[i]->subid];
if(pom)
pom->handler=dhandlers[i];
else
std::cout << "Lacking def info for " << map.defy[i]->id << " " << map.defy[i]->subid <<" " << map.defy[i]->name << std::endl;
}
for(int vv=0; vv<map.defy.size(); ++vv)
{
if(map.defy[vv]->handler->alphaTransformed)
@ -2654,672 +2448,4 @@ CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number)
}
void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
{
resDefNames.push_back("AVTRNDM0.DEF");
resDefNames.push_back("AVTWOOD0.DEF");
resDefNames.push_back("AVTMERC0.DEF");
resDefNames.push_back("AVTORE0.DEF");
resDefNames.push_back("AVTSULF0.DEF");
resDefNames.push_back("AVTCRYS0.DEF");
resDefNames.push_back("AVTGEMS0.DEF");
resDefNames.push_back("AVTGOLD0.DEF");
resDefNames.push_back("ZMITHR.DEF");
std::vector<CGDefInfo*> resDefNumbers;
for(int hh=0; hh<resDefNames.size(); ++hh)
{
resDefNumbers.push_back(NULL);
for(int k=0; k<map.defy.size(); ++k)
{
std::string buf = map.defy[k]->name;
std::transform(buf.begin(), buf.end(), buf.begin(), (int(*)(int))toupper);
if(resDefNames[hh] == buf)
{
resDefNumbers[resDefNumbers.size()-1] = map.defy[k];
break;
}
}
}
std::vector<std::string> creDefNames;
for(int dd=0; dd<140; ++dd) //we do not use here WoG units
{
creDefNames.push_back(CGI->dobjinfo->objs[dd+1184].defName);
}
std::vector<CGDefInfo*> creDefNumbers;
for(int ee=0; ee<creDefNames.size(); ++ee)
{
creDefNumbers.push_back(NULL);
}
std::vector<std::string> artDefNames;
std::vector<CGDefInfo* > artDefNumbers;
for(int bb=0; bb<162; ++bb)
{
if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass!=EartClass::SartClass)
artDefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
}
for(int ee=0; ee<artDefNames.size(); ++ee)
{
artDefNumbers.push_back(NULL);
}
std::vector<std::string> art1DefNames;
std::vector<CGDefInfo*> art1DefNumbers;
for(int bb=0; bb<162; ++bb)
{
if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::TartClass)
art1DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
}
for(int ee=0; ee<art1DefNames.size(); ++ee)
{
art1DefNumbers.push_back(NULL);
}
std::vector<std::string> art2DefNames;
std::vector<CGDefInfo*> art2DefNumbers;
for(int bb=0; bb<162; ++bb)
{
if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::NartClass)
art2DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
}
for(int ee=0; ee<art2DefNames.size(); ++ee)
{
art2DefNumbers.push_back(NULL);
}
std::vector<std::string> art3DefNames;
std::vector<CGDefInfo*> art3DefNumbers;
for(int bb=0; bb<162; ++bb)
{
if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::JartClass)
art3DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
}
for(int ee=0; ee<art3DefNames.size(); ++ee)
{
art3DefNumbers.push_back(NULL);
}
std::vector<std::string> art4DefNames;
std::vector<CGDefInfo*> art4DefNumbers;
for(int bb=0; bb<162; ++bb)
{
if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::RartClass)
art4DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
}
for(int ee=0; ee<art4DefNames.size(); ++ee)
{
art4DefNumbers.push_back(NULL);
}
std::vector<std::string> town0DefNames; //without fort
std::vector<CGDefInfo*> town0DefNumbers;
std::vector<std::string> town1DefNames; //with fort
std::vector<CGDefInfo*> town1DefNumbers;
for(int dd=0; dd<F_NUMBER; ++dd)
{
town1DefNames.push_back(CGI->dobjinfo->objs[dd+385].defName);
town1DefNumbers.push_back(NULL);
}
std::vector< std::vector<std::string> > creGenNames;
std::vector< std::vector<CGDefInfo*> > creGenNumbers;
creGenNames.resize(F_NUMBER);
creGenNumbers.resize(F_NUMBER);
for(int ff=0; ff<F_NUMBER-1; ++ff)
{
for(int dd=0; dd<7; ++dd)
{
creGenNames[ff].push_back(CGI->dobjinfo->objs[395+7*ff+dd].defName);
creGenNumbers[ff].push_back(NULL);
}
}
for(int dd=0; dd<7; ++dd)
{
creGenNumbers[8].push_back(NULL);
}
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[457].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[452].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[455].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[454].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[453].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[458].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[459].defName);
for(int b=0; b<CGI->scenarioOps.playerInfos.size(); ++b) // choosing random player alignment
{
if(CGI->scenarioOps.playerInfos[b].castle==-1)
CGI->scenarioOps.playerInfos[b].castle = rand()%F_NUMBER;
}
//variables initialized
for(int j=0; j<CGI->objh->objInstances.size(); ++j)
{
CGDefInfo * curDef = CGI->objh->objInstances[j]->defInfo;
switch(getDefType(curDef))
{
case EDefType::RESOURCE_DEF:
{
if(curDef->id==76) //resource to specify
{
CGDefInfo * nxt = curDef;
nxt->id = 79;
nxt->subid = rand()%7;
if(resDefNumbers[nxt->subid+1]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = resDefNumbers[nxt->subid+1];
continue;
}
nxt->name = resDefNames[nxt->subid+1];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(resDefNumbers[nxt->subid+1]==NULL)
{
resDefNumbers[nxt->subid+1] = nxt;
}
}
break;
}
case EDefType::CREATURES_DEF:
{
if(curDef->id==72) //random monster lvl 1
{
CGDefInfo * nxt = curDef;
nxt->id = 54;
nxt->subid = 14*(rand()%9)+rand()%2;
if(creDefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
continue;
}
nxt->name = creDefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creDefNumbers[nxt->subid]==NULL)
{
creDefNumbers[nxt->subid] = nxt;
}
}
if(curDef->id==73) //random monster lvl 2
{
CGDefInfo * nxt = curDef;
nxt->id = 54;
nxt->subid = 14*(rand()%9)+rand()%2+2;
if(creDefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
continue;
}
nxt->name = creDefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creDefNumbers[nxt->subid]==NULL)
{
creDefNumbers[nxt->subid] = nxt;
}
}
if(curDef->id==74) //random monster lvl 3
{
CGDefInfo *nxt = curDef;
nxt->id = 54;
nxt->subid = 14*(rand()%9)+rand()%2+4;
if(creDefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
continue;
}
nxt->name = creDefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creDefNumbers[nxt->subid]==NULL)
{
creDefNumbers[nxt->subid] = nxt;
}
}
if(curDef->id==75) //random monster lvl 4
{
CGDefInfo * nxt = curDef;
nxt->id = 54;
nxt->subid = 14*(rand()%9)+rand()%2+6;
if(creDefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
continue;
}
nxt->name = creDefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creDefNumbers[nxt->subid]==NULL)
{
creDefNumbers[nxt->subid] = nxt;
}
}
if(curDef->id==162) //random monster lvl 5
{
CGDefInfo * nxt = curDef;
nxt->id = 54;
nxt->subid = 14*(rand()%9)+rand()%2+8;
if(creDefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
continue;
}
nxt->name = creDefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creDefNumbers[nxt->subid]==NULL)
{
creDefNumbers[nxt->subid] = nxt;
}
}
if(curDef->id==163) //random monster lvl 6
{
CGDefInfo* nxt = curDef;
nxt->id = 54;
nxt->subid = 14*(rand()%9)+rand()%2+10;
if(creDefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
continue;
}
nxt->name = creDefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creDefNumbers[nxt->subid]==NULL)
{
creDefNumbers[nxt->subid] = nxt;
}
}
if(curDef->id==164) //random monster lvl 7
{
CGDefInfo * nxt = curDef;
nxt->id = 54;
nxt->subid = 14*(rand()%9)+rand()%2+12;
if(creDefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
continue;
}
nxt->name = creDefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creDefNumbers[nxt->subid]==NULL)
{
creDefNumbers[nxt->subid] = nxt;
}
}
if(curDef->id==71) //random monster (any level)
{
CGDefInfo * nxt = curDef;
nxt->id = 54;
nxt->subid = rand()%126;
if(creDefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
continue;
}
nxt->name = creDefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creDefNumbers[nxt->subid]==NULL)
{
creDefNumbers[nxt->subid] = nxt;
}
}
break;
} //end of case
case EDefType::ARTIFACT_DEF:
{
if(curDef->id==65) //random atrifact (any class)
{
CGDefInfo *nxt = curDef;
nxt->id = 5;
nxt->subid = rand()%artDefNames.size();
if(artDefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = artDefNumbers[nxt->subid];
continue;
}
nxt->name = artDefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(artDefNumbers[nxt->subid]==NULL)
{
artDefNumbers[nxt->subid] = nxt;
}
}
if(curDef->id==66) //random atrifact (treasure)
{
CGDefInfo* nxt = curDef;
nxt->id = 5;
nxt->subid = rand()%art1DefNames.size();
if(art1DefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = art1DefNumbers[nxt->subid];
continue;
}
nxt->name = art1DefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(art1DefNumbers[nxt->subid]==NULL)
{
art1DefNumbers[nxt->subid] = nxt;
}
}
if(curDef->id==67) //random atrifact (minor)
{
CGDefInfo *nxt = curDef;
nxt->id = 5;
nxt->subid = rand()%art2DefNames.size();
if(art2DefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = art2DefNumbers[nxt->subid];
continue;
}
nxt->name = art2DefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(art2DefNumbers[nxt->subid]==NULL)
{
art2DefNumbers[nxt->subid] = nxt;
}
}
if(curDef->id==68) //random atrifact (major)
{
CGDefInfo* nxt = curDef;
nxt->id = 5;
nxt->subid = rand()%art3DefNames.size();
if(art3DefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = art3DefNumbers[nxt->subid];
continue;
}
nxt->name = art3DefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(art3DefNumbers[nxt->subid]==NULL)
{
art3DefNumbers[nxt->subid] =nxt;
}
}
if(curDef->id==69) //random atrifact (relic)
{
CGDefInfo *nxt = curDef;
nxt->id = 5;
nxt->subid = rand()%art4DefNames.size();
if(art4DefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = art4DefNumbers[nxt->subid];
continue;
}
nxt->name = art4DefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(art4DefNumbers[nxt->subid]==NULL)
{
art4DefNumbers[nxt->subid] = nxt;
}
}
break;
}
case EDefType::TOWN_DEF:
{
if(curDef->id==77) //random town
{
CGDefInfo* nxt = curDef;
nxt->id = 98;
if(((CCastleObjInfo*)CGI->objh->objInstances[j]->info)->player==0xff)
{
nxt->subid = rand()%town1DefNames.size();
}
else
{
if(CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)CGI->objh->objInstances[j]->info)->player).castle>-1)
{
nxt->subid = CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)CGI->objh->objInstances[j]->info)->player).castle;
}
else
{
nxt->subid = rand()%town1DefNames.size();
}
}
if(town1DefNumbers[nxt->subid]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = town1DefNumbers[nxt->subid];
continue;
}
nxt->name = town1DefNames[nxt->subid];
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(town1DefNumbers[nxt->subid]==NULL)
{
town1DefNumbers[nxt->subid] = nxt;
}
for (int ij=0;ij<CGI->townh->townInstances.size();ij++) // wyharatac gdy bedzie dziedziczenie
{
if (CGI->townh->townInstances[ij]->pos==CGI->objh->objInstances[j]->pos)
{
CGI->townh->townInstances[ij]->town = &CGI->townh->towns[nxt->subid];
break;
}
}
}
//((CCastleObjInfo*)CGI->objh->objInstances[j].info)
break;
}
case EDefType::HERO_DEF:
{
CGI->objh->objInstances[j]->defInfo->printPriority = 0;
break;
}
} //end of main switch
} //end of main loop
for(int j=0; j<CGI->objh->objInstances.size(); ++j) //for creature dwellings on map (they are town type dependent)
{
CGDefInfo * curDef = CGI->objh->objInstances[j]->defInfo;
switch(getDefType(curDef))
{
case EDefType::CREGEN_DEF:
{
if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->asCastle)
{
CGDefInfo *nxt = curDef;
nxt->id = 17;
for(int vv=0; vv<CGI->objh->objInstances.size(); ++vv)
{
if(getDefType(CGI->objh->objInstances[vv]->defInfo)==EDefType::TOWN_DEF)
{
if(
((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[0]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[0]
&& ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[1]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[1]
&& ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[2]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[2]
&& ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[3]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[3])
{
for(int mm=0; mm<town1DefNames.size(); ++mm)
{
std::transform(town1DefNames[mm].begin(), town1DefNames[mm].end(), town1DefNames[mm].begin(), (int(*)(int))toupper);
std::string hlp = CGI->objh->objInstances[vv]->defInfo->name;
std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
if(town1DefNames[mm]==hlp)
{
nxt->subid = mm;
}
}
}
}
}
int lvl = atoi(CGI->objh->objInstances[j]->defInfo->name.substr(7, 8).c_str())-1;
nxt->name = creGenNames[nxt->subid][lvl];
if(creGenNumbers[nxt->subid][lvl]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
continue;
}
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creGenNumbers[nxt->subid][lvl]==NULL)
{
creGenNumbers[nxt->subid][lvl] = nxt;
}
}
else //if not as castle
{
CGDefInfo * nxt = curDef;
nxt->id = 17;
std::vector<int> possibleTowns;
for(int bb=0; bb<8; ++bb)
{
if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->castles[0] & (1<<bb))
{
possibleTowns.push_back(bb);
}
}
if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->castles[1])
possibleTowns.push_back(8);
nxt->subid = possibleTowns[rand()%possibleTowns.size()];
int lvl = atoi(CGI->objh->objInstances[j]->defInfo->name.substr(7, 8).c_str())-1;
nxt->name = creGenNames[nxt->subid][lvl];
if(creGenNumbers[nxt->subid][lvl]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
continue;
}
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creGenNumbers[nxt->subid][lvl]==NULL)
{
creGenNumbers[nxt->subid][lvl] = nxt;
}
}
break;
}
case EDefType::CREGEN2_DEF:
{
if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->asCastle)
{
CGDefInfo * nxt = curDef;
nxt->id = 17;
for(int vv=0; vv<CGI->objh->objInstances.size(); ++vv)
{
if(getDefType(CGI->objh->objInstances[vv]->defInfo)==EDefType::TOWN_DEF)
{
if(
((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[0]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[0]
&& ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[1]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[1]
&& ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[2]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[2]
&& ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[3]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[3])
{
for(int mm=0; mm<town1DefNames.size(); ++mm)
{
std::transform(town1DefNames[mm].begin(), town1DefNames[mm].end(), town1DefNames[mm].begin(), (int(*)(int))toupper);
std::string hlp = CGI->objh->objInstances[vv]->defInfo->name;
std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
if(town1DefNames[mm]==hlp)
{
nxt->subid = mm;
}
}
}
}
}
int lvl;
if((((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel)!=0)
lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel;
else lvl = 0;
nxt->name = creGenNames[nxt->subid][lvl];
if(creGenNumbers[nxt->subid][lvl]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
continue;
}
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creGenNumbers[nxt->subid][lvl]==NULL)
{
creGenNumbers[nxt->subid][lvl] = nxt;
}
}
else //if not as castle
{
CGDefInfo * nxt = curDef;
nxt->id = 17;
std::vector<int> possibleTowns;
for(int bb=0; bb<8; ++bb)
{
if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->castles[0] & (1<<bb))
{
possibleTowns.push_back(bb);
}
}
if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->castles[1])
possibleTowns.push_back(8);
nxt->subid = possibleTowns[rand()%possibleTowns.size()];
int lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel;
nxt->name = creGenNames[nxt->subid][lvl];
if(creGenNumbers[nxt->subid][lvl]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
continue;
}
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creGenNumbers[nxt->subid][lvl]==NULL)
{
creGenNumbers[nxt->subid][lvl] = nxt;
}
}
}
case EDefType::CREGEN3_DEF:
{
CGDefInfo * nxt = curDef;
nxt->id = 17;
nxt->subid = atoi(CGI->objh->objInstances[j]->defInfo->name.substr(7, 8).c_str());
int lvl = -1;
CCreGen3ObjInfo * ct = (CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info;
if(ct->maxLevel>7)
ct->maxLevel = 7;
if(ct->minLevel<1)
ct->minLevel = 1;
if((((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel)!=0)
lvl = rand()%(((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel) + ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel;
else
lvl = ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel;
nxt->name = creGenNames[nxt->subid][lvl];
if(creGenNumbers[nxt->subid][lvl]!=NULL)
{
CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
continue;
}
map.defy.push_back(nxt); // add this def to the vector
defsToUnpack.push_back(nxt->name);
CGI->objh->objInstances[j]->defInfo = nxt;
if(creGenNumbers[nxt->subid][lvl]==NULL)
{
creGenNumbers[nxt->subid][lvl] = nxt;
}
break;
}
}//end of main switch
} //end of sencond for loop
}
{}

View File

@ -143,4 +143,22 @@ void CArtHandler::loadArtifacts()
artifacts.push_back(nart);
}
for(int i=0;i<144;i++) //do 144, bo nie chcemy bzdurek
{
switch (artifacts[i].aClass)
{
case TartClass:
treasures.push_back(&(artifacts[i]));
break;
case NartClass:
minors.push_back(&(artifacts[i]));
break;
case JartClass:
majors.push_back(&(artifacts[i]));
break;
case RartClass:
relics.push_back(&(artifacts[i]));
break;
}
}
}

View File

@ -25,6 +25,7 @@ class CArtHandler //handles artifacts
{
public:
CDefHandler * artDefs;
std::vector<CArtifact*> treasures, minors, majors, relics;
std::vector<CArtifact> artifacts;
void loadArtifacts();
bool loadArtEvents();

View File

@ -24,15 +24,8 @@ void CCreatureHandler::loadCreatures()
while(i<buf.size())
{
//if(creatures.size()>190 && buf.substr(i, buf.size()-i).find('\r')==std::string::npos)
//{
// loadAnimationInfo();
// loadUnitAnimations();
// break;
//}
CCreature ncre;
ncre.level=0;
int befi=i;
for(i; i<andame; ++i)
{
@ -288,6 +281,22 @@ void CCreatureHandler::loadCreatures()
creatures[tempi].nameRef=temps;
}
ifs.close();
ifs.clear();
for(int i=1;i<=10;i++)
levelCreatures.insert(std::pair<int,std::vector<CCreature*> >(i,std::vector<CCreature*>()));
ifs.open("config/monsters.txt");
{
while(!ifs.eof())
{
int id, lvl;
ifs >> id >> lvl;
if(lvl>0)
{
creatures[id].level = lvl;
levelCreatures[lvl].push_back(&(creatures[id]));
}
}
}
//loading 32x32px imgs
CDefHandler *smi = CGI->spriteh->giveDef("CPRSMALL.DEF");

View File

@ -16,6 +16,7 @@ public:
std::string namePl, nameSing, nameRef; //name in singular and plural form; and reference name
int wood, mercury, ore, sulfur, crystal, gems, gold, fightValue, AIValue, growth, hordeGrowth, hitPoints, speed, attack, defence, shots, spells;
int low1, low2, high1, high2; //TODO - co to w ogóle jest???
int level; // 0 - unknown
std::string abilityText; //description of abilities
std::string abilityRefs; //references to abilities, in textformat
int idNumber;
@ -51,6 +52,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::vector<CCreature> creatures;
std::map<int,std::vector<CCreature*> > levelCreatures; //level -> list of creatures
std::map<std::string,int> nameToID;
void loadCreatures();
void loadAnimationInfo();

View File

@ -4,6 +4,15 @@
#include "CLodHandler.h"
#include <sstream>
bool CGDefInfo::isVisitable()
{
for (int i=0; i<6; i++)
{
if (visitMap[i])
return true;
}
return false;
}
bool DefObjInfo::operator==(const std::string & por) const
{
return this->defName == por;
@ -11,21 +20,23 @@ bool DefObjInfo::operator==(const std::string & por) const
void CDefObjInfoHandler::load()
{
nodrze<int> ideki;
std::istringstream inp(CGameInfo::mainObj->bitmaph->getTextFile("ZOBJCTS.TXT"));
int objNumber;
inp>>objNumber;
for(int hh=0; hh<objNumber; ++hh)
{
DefObjInfo nobj;
CGDefInfo* nobj = new CGDefInfo();
nobj->handler = NULL;
std::string dump;
inp>>nobj.defName;
inp>>nobj->name;
std::transform(nobj.defName.begin(), nobj.defName.end(), nobj.defName.begin(), (int(*)(int))toupper);
std::transform(nobj->name.begin(), nobj->name.end(), nobj->name.begin(), (int(*)(int))toupper);
for(int o=0; o<6; ++o)
{
nobj.blockMap[o] = 0xff;
nobj.visitMap[o] = 0x00;
nobj->blockMap[o] = 0xff;
nobj->visitMap[o] = 0x00;
}
std::string mapStr;
inp>>mapStr;
@ -34,7 +45,7 @@ void CDefObjInfoHandler::load()
{
if(mapStr[v]=='0')
{
nobj.blockMap[v/8] &= 255 - (128 >> (v%8));
nobj->blockMap[v/8] &= 255 - (128 >> (v%8));
}
}
inp>>mapStr;
@ -43,17 +54,19 @@ void CDefObjInfoHandler::load()
{
if(mapStr[v]=='1')
{
nobj.visitMap[v/8] |= (128 >> (v%8));
nobj->visitMap[v/8] |= (128 >> (v%8));
}
}
for(int yy=0; yy<2; ++yy)
inp>>dump;
inp>>nobj.type;
inp>>nobj.subtype;
inp>>nobj.objType;
inp>>nobj.priority;
objs.push_back(nobj);
inp>>nobj->id;
inp>>nobj->subid;
inp>>nobj->type;
inp>>nobj->printPriority;
gobjs[nobj->id][nobj->subid] = nobj;
if(nobj->id==98)
castles[nobj->subid]=nobj;
}
}

View File

@ -1,8 +1,30 @@
#ifndef COBJINFOECTHANDLER_H
#define COBJINFOECTHANDLER_H
#include <vector>
#include <map>
class CDefHandler;
class CGDefInfo
{
public:
std::string name;
unsigned char visitMap[6];
unsigned char blockMap[6];
int id, subid; //of object described by this defInfo
int terrainAllowed, //on which terrain it is possible to place object
terrainMenu; //in which menus in map editor object will be showed
int type; //(0- ground, 1- towns, 2-creatures, 3- heroes, 4-artifacts, 5- resources)
CDefHandler * handler;
int printPriority;
bool isVisitable();
bool operator<(const CGDefInfo& por)
{
if(id!=por.id)
return id<por.id;
else
return subid<por.subid;
}
};
struct DefObjInfo
{
std::string defName;
@ -18,8 +40,9 @@ struct DefObjInfo
class CDefObjInfoHandler
{
public:
//std::vector<std::vector<CGDefInfo> > gobjs;
std::vector<DefObjInfo> objs;
std::map<int,std::map<int,CGDefInfo*> > gobjs;
std::map<int,CGDefInfo*> castles;
//std::vector<DefObjInfo> objs;
void load();
};

View File

@ -69,7 +69,16 @@ void CObjectHandler::loadObjects()
restypes.push_back(temp);
}
cregens.resize(110); //TODO: hardcoded value - change
for(int i=0; i<cregens.size();i++)
cregens[i]=-1;
std::ifstream ifs("config/cregens.txt");
while(!ifs.eof())
{
int dw, cr;
ifs >> dw >> cr;
cregens[dw]=cr;
}
}
@ -131,15 +140,6 @@ bool CGObjectInstance::operator<(const CGObjectInstance & cmp) const //screen p
return false;
}
bool CGDefInfo::isVisitable()
{
for (int i=0; i<6; i++)
{
if (visitMap[i])
return true;
}
return false;
}
bool CGHeroInstance::isHero() const
{
@ -228,6 +228,10 @@ bool CGTownInstance::hasFort() const
{
return (builtBuildings.find(7))!=builtBuildings.end();
}
bool CGTownInstance::hasCapitol() const
{
return (builtBuildings.find(13))!=builtBuildings.end();
}
CGTownInstance::CGTownInstance()
{
pos = int3(-1,-1,-1);

View File

@ -242,7 +242,7 @@ class CCreGenObjInfo : public CSpecObjInfo
public:
unsigned char player; //owner
bool asCastle;
unsigned char bytes[4]; //castle identifier
int identifier;
unsigned char castles[2]; //allowed castles
};
@ -251,7 +251,7 @@ class CCreGen2ObjInfo : public CSpecObjInfo
public:
unsigned char player; //owner
bool asCastle;
unsigned char bytes[4]; //castle identifier
int identifier;
unsigned char castles[2]; //allowed castles
unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6>
};
@ -298,44 +298,7 @@ public:
std::string name; //object's name
};
class CGDefInfo
{
public:
std::string name;
unsigned char visitMap[6];
unsigned char blockMap[6];
int id, subid; //of object described by this defInfo
int terrainAllowed, //on which terrain it is possible to place object
terrainMenu; //in which menus in map editor object will be showed
int type; //(0- ground, 1- towns, 2-creatures, 3- heroes, 4-artifacts, 5- resources)
CDefHandler * handler;
int printPriority;
bool isVisitable();
};
//class CObjectType
//{
//public:
// CGObjectInstance * ourObj;
// int type;
// int owner; //254 - can't be flagged; 255 - neutral
////};
//class IVisitable
//{
// virtual void newObject(CGObjectInstance *os);
// virtual void onHeroVisit(CGObjectInstance *os, int heroID);
// virtual void getRightText(tribool visited);
// virtual void getHoverText(tribool visited);
//};
//
//class CVisitableOPH //object visitable once per hero
//{
// virtual void newObject(CGObjectInstance *os);
// virtual void onHeroVisit(CGObjectInstance *os, int heroID);
// virtual void getRightText(tribool visited);
// virtual void getHoverText(tribool visited);
//};
class CGDefInfo;
class CGObjectInstance
{
@ -415,6 +378,7 @@ public:
CCreatureSet garrison;
int builded; //how many buildings has been built this turn
int destroyed; //how many buildings has been destroyed this turn
int identifier;
int income;
@ -429,6 +393,7 @@ public:
int getSightDistance() const; //returns sight distance
bool hasFort() const;
bool hasCapitol() const;
int dailyIncome() const;
CGTownInstance();
@ -440,6 +405,7 @@ class CObjectHandler
public:
std::vector<CObject> objects; //vector of objects; i-th object in vector has subnumber i
std::vector<CGObjectInstance*> objInstances; //vector with objects on map
std::vector<int> cregens; //type 17. dwelling subid -> creature ID
void loadObjects();
std::vector<std::string> advobtxt;

View File

@ -199,6 +199,20 @@ void CTownHandler::loadNames()
}
of.close();
of.clear();
for(int x=0;x<towns.size();x++)
towns[x].basicCreatures.resize(7);
of.open("config/basicCres.txt");
while(!of.eof())
{
int tid, lid, cid; //town,level,creature
of >> tid >> lid >> cid;
if(lid < towns[tid].basicCreatures.size())
towns[tid].basicCreatures[lid]=cid;
}
of.close();
of.clear();
}
}
SDL_Surface * CTownHandler::getPic(int ID, bool fort, bool builded)

View File

@ -17,6 +17,7 @@ class CTown
public:
std::string name; //name of type
std::vector<std::string> names; //names of the town instances
std::vector<int> basicCreatures; //level (from 0) -> ID
int bonus; //pic number
int typeID;
};

View File

@ -25,78 +25,199 @@ public:
return (*a.first)<(*b.first);
}
} ocmptwo ;
void CMapHandler::randomizeObjects()
{
for(int gh=0; gh<2; ++gh) //some objects can be initialized not before initializing some other
void alphaTransformDef(CGDefInfo * defInfo)
{
SDL_Surface * alphaTransSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 12, 12, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
for(int yy=0;yy<defInfo->handler->ourImages.size();yy++)
{
for(int no=0; no<CGI->objh->objInstances.size(); ++no)
defInfo->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(defInfo->handler->ourImages[yy].bitmap);
SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(defInfo->handler->ourImages[yy].bitmap, alphaTransSurf);
SDL_FreeSurface(defInfo->handler->ourImages[yy].bitmap);
defInfo->handler->ourImages[yy].bitmap = bufs;
defInfo->handler->alphaTransformed = true;
}
SDL_FreeSurface(alphaTransSurf);
}
std::pair<int,int> CMapHandler::pickObject(CGObjectInstance *obj)
{
switch(obj->ID)
{
case 65: //random artifact
return std::pair<int,int>(5,(rand()%136)+7); //tylko sensowny zakres - na poczatku sa katapulty itp, na koncu specjalne i blanki
case 66: //random treasure artifact
return std::pair<int,int>(5,CGI->arth->treasures[rand()%CGI->arth->treasures.size()]->id);
case 67: //random minor artifact
return std::pair<int,int>(5,CGI->arth->minors[rand()%CGI->arth->minors.size()]->id);
case 68: //random major artifact
return std::pair<int,int>(5,CGI->arth->majors[rand()%CGI->arth->majors.size()]->id);
case 69: //random relic artifact
return std::pair<int,int>(5,CGI->arth->relics[rand()%CGI->arth->relics.size()]->id);
case 70: //random hero
return std::pair<int,int>(34,rand()%CGI->heroh->heroes.size());
case 71: //random monster
return std::pair<int,int>(54,rand()%(CGI->creh->creatures.size()));
case 72: //random monster lvl1
return std::pair<int,int>(54,CGI->creh->levelCreatures[1][rand()%CGI->creh->levelCreatures[1].size()]->idNumber);
case 73: //random monster lvl2
return std::pair<int,int>(54,CGI->creh->levelCreatures[2][rand()%CGI->creh->levelCreatures[2].size()]->idNumber);
case 74: //random monster lvl3
return std::pair<int,int>(54,CGI->creh->levelCreatures[3][rand()%CGI->creh->levelCreatures[3].size()]->idNumber);
case 75: //random monster lvl4
return std::pair<int,int>(54,CGI->creh->levelCreatures[4][rand()%CGI->creh->levelCreatures[4].size()]->idNumber);
case 76: //random resource
return std::pair<int,int>(79,rand()%7); //now it's OH3 style, use %8 for mithril
case 77: //random town
return std::pair<int,int>(98,rand()%CGI->townh->towns.size());
case 162: //random monster lvl5
return std::pair<int,int>(54,CGI->creh->levelCreatures[5][rand()%CGI->creh->levelCreatures[5].size()]->idNumber);
case 163: //random monster lvl6
return std::pair<int,int>(54,CGI->creh->levelCreatures[6][rand()%CGI->creh->levelCreatures[6].size()]->idNumber);
case 164: //random monster lvl7
return std::pair<int,int>(54,CGI->creh->levelCreatures[7][rand()%CGI->creh->levelCreatures[7].size()]->idNumber);
case 216: //random dwelling
{
std::string nname = getRandomizedDefName(CGI->objh->objInstances[no]->defInfo, CGI->objh->objInstances[no]);
if(nname.size()>0) //change def
int faction = rand()%F_NUMBER;
CCreGen2ObjInfo* info =(CCreGen2ObjInfo*)obj->info;
if (info->asCastle)
{
CGDefInfo * ndi = new CGDefInfo;
*ndi = *CGI->objh->objInstances[no]->defInfo; //something to start with
CGI->mh->reader->map.defy.push_back(ndi);
CGI->objh->objInstances[no]->defInfo = ndi;
int f=-1;
for(f=0; f<CGI->dobjinfo->objs.size(); ++f)
for(int i=0;i<CGI->objh->objInstances.size();i++)
{
if(CGI->dobjinfo->objs[f].defName==nname)
if(CGI->objh->objInstances[i]->ID==77 && dynamic_cast<CGTownInstance*>(CGI->objh->objInstances[i])->identifier == info->identifier)
{
randomizeObject(CGI->objh->objInstances[i]); //we have to randomize the castle first
faction = CGI->objh->objInstances[i]->subID;
break;
}
else if(CGI->objh->objInstances[i]->ID==98 && dynamic_cast<CGTownInstance*>(CGI->objh->objInstances[i])->identifier == info->identifier)
{
faction = CGI->objh->objInstances[i]->subID;
break;
}
}
CGI->objh->objInstances[no]->defInfo->name = nname;
if(CGI->objh->objInstances[no]->ID==70) //random hero - init here
}
else
{
while((!(info->castles[0]&(1<<faction))))
{
CHeroObjInfo* curc = ((CHeroObjInfo*)CGI->objh->objInstances[no]->info);
curc->type = CGI->heroh->heroes[rand()%CGI->heroh->heroes.size()];
//making def appropriate for hero type
std::stringstream nm;
nm<<"AH";
nm<<std::setw(2);
nm<<std::setfill('0');
nm<<curc->type->heroType; //HARDCODED VALUE! TODO: REMOVE IN FUTURE
nm<<"_.DEF";
nname = nm.str();
curc->sex = rand()%2; //TODO: what to do with that?
curc->name = curc->type->name;
curc->attack = curc->type->heroClass->initialAttack;
curc->defence = curc->type->heroClass->initialDefence;
curc->knowledge = curc->type->heroClass->initialKnowledge;
curc->power = curc->type->heroClass->initialPower;
}
if(loadedDefs.find(nname)!=loadedDefs.end())
{
CGI->objh->objInstances[no]->defInfo->handler = loadedDefs.find(nname)->second;
}
else
{
CGI->objh->objInstances[no]->defInfo->handler = CGI->spriteh->giveDef(nname);
for(int dd=0; dd<CGI->objh->objInstances[no]->defInfo->handler->ourImages.size(); ++dd)
{
CSDL_Ext::fullAlphaTransform(CGI->objh->objInstances[no]->defInfo->handler->ourImages[dd].bitmap);
}
loadedDefs.insert(std::pair<std::string, CDefHandler*>(nname, CGI->objh->objInstances[no]->defInfo->handler));
}
if(f!=-1 && f!=CGI->dobjinfo->objs.size())
{
CGI->objh->objInstances[no]->ID = CGI->dobjinfo->objs[f].type;
CGI->objh->objInstances[no]->subID = CGI->dobjinfo->objs[f].subtype;
CGI->objh->objInstances[no]->defInfo->id = CGI->dobjinfo->objs[f].type;
CGI->objh->objInstances[no]->defInfo->subid = CGI->dobjinfo->objs[f].subtype;
CGI->objh->objInstances[no]->defInfo->printPriority = CGI->dobjinfo->objs[f].priority;
}
else
{
CGI->objh->objInstances[no]->defInfo->printPriority = 0;
if((faction>7) && (info->castles[1]&(1<<(faction-8))))
break;
faction = rand()%F_NUMBER;
}
}
int level = ((info->maxLevel-info->minLevel) ? (rand()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel));
int cid = CGI->townh->towns[faction].basicCreatures[level];
for(int i=0;i<CGI->objh->cregens.size();i++)
if(CGI->objh->cregens[i]==cid)
return std::pair<int,int>(17,i);
std::cout << "Cannot find a dwelling for creature "<<cid <<std::endl;
return std::pair<int,int>(17,0);
}
case 217:
{
int faction = rand()%F_NUMBER;
CCreGenObjInfo* info =(CCreGenObjInfo*)obj->info;
if (info->asCastle)
{
for(int i=0;i<CGI->objh->objInstances.size();i++)
{
if(CGI->objh->objInstances[i]->ID==77 && dynamic_cast<CGTownInstance*>(CGI->objh->objInstances[i])->identifier == info->identifier)
{
randomizeObject(CGI->objh->objInstances[i]); //we have to randomize the castle first
faction = CGI->objh->objInstances[i]->subID;
break;
}
else if(CGI->objh->objInstances[i]->ID==98 && dynamic_cast<CGTownInstance*>(CGI->objh->objInstances[i])->identifier == info->identifier)
{
faction = CGI->objh->objInstances[i]->subID;
break;
}
}
}
else
{
while((!(info->castles[0]&(1<<faction))))
{
if((faction>7) && (info->castles[1]&(1<<(faction-8))))
break;
faction = rand()%F_NUMBER;
}
}
int cid = CGI->townh->towns[faction].basicCreatures[obj->subID];
for(int i=0;i<CGI->objh->cregens.size();i++)
if(CGI->objh->cregens[i]==cid)
return std::pair<int,int>(17,i);
std::cout << "Cannot find a dwelling for creature "<<cid <<std::endl;
return std::pair<int,int>(17,0);
}
case 218:
{
CCreGen3ObjInfo* info =(CCreGen3ObjInfo*)obj->info;
int level = ((info->maxLevel-info->minLevel) ? (rand()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel));
int cid = CGI->townh->towns[obj->subID].basicCreatures[level];
for(int i=0;i<CGI->objh->cregens.size();i++)
if(CGI->objh->cregens[i]==cid)
return std::pair<int,int>(17,i);
std::cout << "Cannot find a dwelling for creature "<<cid <<std::endl;
return std::pair<int,int>(17,0);
}
}
return std::pair<int,int>(-1,-1);
}
void CMapHandler::randomizeObject(CGObjectInstance *cur)
{
std::pair<int,int> ran = pickObject(cur);
if(ran.first<0 || ran.second<0) //this is not a random object, or we couldn't find anything
return;
else if(ran.first==34)//special code for hero
{
CGHeroInstance *h = dynamic_cast<CGHeroInstance *>(cur);
if(!h) {std::cout<<"Wrong random hero at "<<cur->pos<<std::endl; return;}
cur->ID = ran.first;
cur->subID = ran.second;
h->type = CGI->heroh->heroes[ran.second];
CGI->heroh->heroInstances.push_back(h);
CGI->objh->objInstances.erase(std::find(CGI->objh->objInstances.begin(),CGI->objh->objInstances.end(),h));
return; //TODO: maybe we should do something with definfo?
}
else if(ran.first==98)//special code for town
{
CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur);
if(!t) {std::cout<<"Wrong random town at "<<cur->pos<<std::endl; return;}
cur->ID = ran.first;
cur->subID = ran.second;
t->town = &CGI->townh->towns[ran.second];
if(t->hasCapitol())
t->defInfo = capitols[t->subID];
else if(t->hasFort())
t->defInfo = CGI->dobjinfo->castles[t->subID];
else
t->defInfo = villages[t->subID];
if(!t->defInfo->handler)
{
t->defInfo->handler = CGI->spriteh->giveDef(t->defInfo->name);
alphaTransformDef(t->defInfo);
}
CGI->townh->townInstances.push_back(t);
return;
}
//we have to replace normal random object
cur->ID = ran.first;
cur->subID = ran.second;
cur->defInfo = CGI->dobjinfo->gobjs[ran.first][ran.second];
if(!cur->defInfo){std::cout<<"Missing def declaration for "<<cur->ID<<" "<<cur->subID<<std::endl;return;}
if(!cur->defInfo->handler) //if we have to load def
{
cur->defInfo->handler = CGI->spriteh->giveDef(cur->defInfo->name);
alphaTransformDef(cur->defInfo);
}
}
void CMapHandler::randomizeObjects()
{
CGObjectInstance * cur;
for(int no=0; no<CGI->objh->objInstances.size(); ++no)
{
randomizeObject(CGI->objh->objInstances[no]);
}
}
void CMapHandler::prepareFOWDefs()
@ -502,6 +623,10 @@ void CMapHandler::initObjectRects()
{
/*CGI->objh->objInstances[f]->pos.x+=1;
CGI->objh->objInstances[f]->pos.y+=1;*/
if(!CGI->objh->objInstances[f]->defInfo)
{
continue;
}
CDefHandler * curd = CGI->objh->objInstances[f]->defInfo->handler;
for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
{
@ -569,6 +694,8 @@ void CMapHandler::calculateBlockedPos()
{
for(int f=0; f<CGI->objh->objInstances.size(); ++f) //calculationg blocked / visitable positions
{
if(!CGI->objh->objInstances[f]->defInfo)
continue;
CDefHandler * curd = CGI->objh->objInstances[f]->defInfo->handler;
for(int fx=0; fx<8; ++fx)
{
@ -591,6 +718,22 @@ void CMapHandler::calculateBlockedPos()
}
void CMapHandler::init()
{
std::ifstream ifs("config/townsDefs.txt");
int ccc;
ifs>>ccc;
for(int i=0;i<ccc*2;i++)
{
CGDefInfo * n = new CGDefInfo(*CGI->dobjinfo->castles[i%ccc]);
ifs >> n->name;
if (!(n->handler = CGI->spriteh->giveDef(n->name)))
std::cout << "Cannot open "<<n->name<<std::endl;
if(i<ccc)
villages[i]=n;
else
capitols[i%ccc]=n;
alphaTransformDef(n);
}
timeHandler th;
th.getDif();
randomizeObjects();//randomizing objects on map
@ -598,9 +741,9 @@ void CMapHandler::init()
for(int h=0; h<reader->map.defy.size(); ++h) //initializing loaded def handler's info
{
std::string hlp = reader->map.defy[h]->name;
std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
CGI->mh->loadedDefs.insert(std::make_pair(hlp, reader->map.defy[h]->handler));
//std::string hlp = reader->map.defy[h]->name;
//std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
CGI->mh->loadedDefs.insert(std::make_pair(reader->map.defy[h]->name, reader->map.defy[h]->handler));
}
std::cout<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl;
@ -1428,16 +1571,6 @@ SDL_Surface * CMapHandler::getVisBitmap(int x, int y, PseudoV< PseudoV< PseudoV<
return fullHide->ourImages[0].bitmap; //this case should never happen, but it is better to hide too much than reveal it....
}
//char & CMapHandler::visAccess(int x, int y)
//{
// return visibility[x+Woff][y+Hoff];
//}
//
//char & CMapHandler::undVisAccess(int x, int y)
//{
// return undVisibility[x+Woff][y+Hoff];
//}
int CMapHandler::getCost(int3 &a, int3 &b, const CGHeroInstance *hero)
{
int ret=-1;
@ -1470,7 +1603,7 @@ std::vector < std::string > CMapHandler::getObjDescriptions(int3 pos)
if (objs[g].first->state)
ret.push_back(objs[g].first->state->hoverText(objs[g].first));
else
ret.push_back(CGI->objh->objects[objs[g].first->defInfo->id].name);
ret.push_back(CGI->objh->objects[objs[g].first->ID].name);
}
}
return ret;
@ -1505,7 +1638,10 @@ CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos)
}
nobj->ID = id;
nobj->subID = subid;
nobj->defInfo = new CGDefInfo;
nobj->defInfo = CGI->dobjinfo->gobjs[id][subid];
if(!nobj->defInfo)
std::cout <<"No def declaration for " <<id <<" "<<subid<<std::endl;
/*new CGDefInfo;
int defObjInfoNumber = -1;
for(int f=0; f<CGI->dobjinfo->objs.size(); ++f)
{
@ -1519,8 +1655,8 @@ CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos)
for(int g=0; g<6; ++g)
nobj->defInfo->blockMap[g] = CGI->dobjinfo->objs[defObjInfoNumber].blockMap[g];
for(int g=0; g<6; ++g)
nobj->defInfo->visitMap[g] = CGI->dobjinfo->objs[defObjInfoNumber].visitMap[g];
nobj->defInfo->printPriority = CGI->dobjinfo->objs[defObjInfoNumber].priority;
nobj->defInfo->visitMap[g] = CGI->dobjinfo->objs[nobj->defObjInfoNumber].visitMap[g];
nobj->defInfo->printPriority = CGI->dobjinfo->objs[nobj->defObjInfoNumber].priority;*/
nobj->pos = pos;
//nobj->state = NULL;//new CLuaObjectScript();
nobj->tempOwner = 254;
@ -1549,11 +1685,9 @@ CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos)
std::string CMapHandler::getDefName(int id, int subid)
{
for(int i=0; i<CGI->dobjinfo->objs.size(); ++i)
{
if(CGI->dobjinfo->objs[i].type==id && CGI->dobjinfo->objs[i].subtype==subid)
return CGI->dobjinfo->objs[i].defName;
}
CGDefInfo* temp = CGI->dobjinfo->gobjs[id][subid];
if(temp)
return temp->name;
throw new std::exception("Def not found.");
}
@ -1571,7 +1705,7 @@ bool CMapHandler::printObject(CGObjectInstance *obj)
cr.y = fy*32;
std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> toAdd = std::make_pair(obj, std::make_pair(cr, std::vector<std::list<int3>>()));
///initializing places that will be coloured by blitting (flag colour / player colour positions)
if(toAdd.first->defInfo->isVisitable())
if(CGI->dobjinfo->gobjs[toAdd.first->ID][toAdd.first->subID]->isVisitable())
{
toAdd.second.second.resize(toAdd.first->defInfo->handler->ourImages.size());
for(int no = 0; no<toAdd.first->defInfo->handler->ourImages.size(); ++no)
@ -1637,342 +1771,6 @@ bool CMapHandler::hideObject(CGObjectInstance *obj)
std::string CMapHandler::getRandomizedDefName(CGDefInfo *di, CGObjectInstance * obj)
{
if(di->id==76) //random resource
{
std::vector<std::string> resDefNames;
//resDefNames.push_back("AVTRNDM0.DEF");
resDefNames.push_back("AVTWOOD0.DEF");
resDefNames.push_back("AVTMERC0.DEF");
resDefNames.push_back("AVTORE0.DEF");
resDefNames.push_back("AVTSULF0.DEF");
resDefNames.push_back("AVTCRYS0.DEF");
resDefNames.push_back("AVTGEMS0.DEF");
resDefNames.push_back("AVTGOLD0.DEF");
resDefNames.push_back("ZMITHR.DEF");
return resDefNames[rand()%resDefNames.size()];
}
else if(di->id==72 || di->id==73 || di->id==74 || di->id==75 || di->id==162 || di->id==163 || di->id==164 || di->id==71) //random monster
{
std::vector<std::string> creDefNames;
for(int dd=0; dd<140; ++dd) //we do not use here WoG units
{
creDefNames.push_back(CGI->dobjinfo->objs[dd+1184].defName);
}
switch(di->id)
{
case 72: //level 1
return creDefNames[14*(rand()%9)+rand()%2];
case 73: //level 2
return creDefNames[14*(rand()%9)+rand()%2+2];
case 74: //level 3
return creDefNames[14*(rand()%9)+rand()%2+4];
case 75: //level 4
return creDefNames[14*(rand()%9)+rand()%2+6];
case 162: //level 5
return creDefNames[14*(rand()%9)+rand()%2+8];
case 163: //level 6
return creDefNames[14*(rand()%9)+rand()%2+10];
case 164: //level 7
return creDefNames[14*(rand()%9)+rand()%2+12];
case 71: // any level
return creDefNames[rand()%126];
}
}
else if(di->id==65) //random artifact (any class)
{
std::vector<std::string> artDefNames;
for(int bb=0; bb<162; ++bb)
{
if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass!=EartClass::SartClass)
artDefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
}
return artDefNames[rand()%artDefNames.size()];
}
else if(di->id==66) //random artifact (treasure)
{
std::vector<std::string> art1DefNames;
for(int bb=0; bb<162; ++bb)
{
if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::TartClass)
art1DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
}
return art1DefNames[rand()%art1DefNames.size()];
}
else if(di->id==67) //random artifact (minor)
{
std::vector<std::string> art2DefNames;
for(int bb=0; bb<162; ++bb)
{
if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::NartClass)
art2DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
}
return art2DefNames[rand()%art2DefNames.size()];
}
else if(di->id==68) //random artifact (major)
{
std::vector<std::string> art3DefNames;
for(int bb=0; bb<162; ++bb)
{
if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::JartClass)
art3DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
}
return art3DefNames[rand()%art3DefNames.size()];
}
else if(di->id==69) //random artifact (relic)
{
std::vector<std::string> art4DefNames;
for(int bb=0; bb<162; ++bb)
{
if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::RartClass)
art4DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
}
return art4DefNames[rand()%art4DefNames.size()];
}
else if(di->id==77) //random town
{
if(!obj)
return std::string(); //obj is necessary!
std::vector<std::string> town0DefNames; //without fort
town0DefNames.push_back("AVCCAST0.DEF");
town0DefNames.push_back("AVCRAMP0.DEF");
town0DefNames.push_back("AVCTOWR0.DEF");
town0DefNames.push_back("AVCINFT0.DEF");
town0DefNames.push_back("AVCNECR0.DEF");
town0DefNames.push_back("AVCDUNG0.DEF");
town0DefNames.push_back("AVCSTRO0.DEF");
town0DefNames.push_back("AVCFTRT0.DEF");
town0DefNames.push_back("AVCHFOR0.DEF");
std::vector<std::string> town1DefNames; //with fort
for(int dd=0; dd<F_NUMBER; ++dd)
{
town1DefNames.push_back(CGI->dobjinfo->objs[dd+384].defName);
}
std::vector<std::string> town2DefNames; //with capitol
for(int dd=0; dd<F_NUMBER; ++dd)
{
town2DefNames.push_back(CGI->dobjinfo->objs[dd+384].defName);
}
for(int b=0; b<town2DefNames.size(); ++b)
{
for(int q=0; q<town2DefNames[b].size(); ++q)
{
if(town2DefNames[b][q]=='x' || town2DefNames[b][q]=='X')
town2DefNames[b][q] = 'Z';
}
}
//TODO: use capitol defs
//variables initialized
if(obj->tempOwner==0xff) //no preselected preferentions
{
if(((CCastleObjInfo*)obj->info)->hasFort)
return town1DefNames[rand()%town1DefNames.size()];
else
return town0DefNames[rand()%town0DefNames.size()];
}
else
{
if(CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)obj->info)->player).castle>-1) //castle specified in start options
{
int defnr = CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)obj->info)->player).castle;
if(((CCastleObjInfo*)obj->info)->hasFort)
return town1DefNames[defnr];
else
return town0DefNames[defnr];
}
else //no castle specified
{
int defnr = rand()%F_NUMBER;
if(((CCastleObjInfo*)obj->info)->hasFort)
return town1DefNames[defnr];
else
return town0DefNames[defnr];
}
}
}
else if(di->id==70) //random hero
{
std::stringstream nm;
nm<<"AH";
nm<<std::setw(2);
nm<<std::setfill('0');
nm<<rand()%18; //HARDCODED VALUE! TODO: REMOVE IN FUTURE
nm<<"_.DEF";
return nm.str();
}
else if(di->id==217) //random dwelling with preset level
{
std::vector< std::vector<std::string> > creGenNames;
creGenNames.resize(F_NUMBER);
for(int ff=0; ff<F_NUMBER-1; ++ff)
{
for(int dd=0; dd<7; ++dd)
{
creGenNames[ff].push_back(CGI->dobjinfo->objs[394+7*ff+dd].defName);
}
}
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[456].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[451].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[454].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[453].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[452].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[457].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[458].defName);
if(((CCreGenObjInfo*)obj->info)->asCastle)
{
int fraction = -1;
for(int vv=0; vv<CGI->objh->objInstances.size(); ++vv)
{
if(CGI->objh->objInstances[vv]->defInfo->id==98) //is a town
{
if( //check if it is this one we want
((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[0]==((CCreGenObjInfo*)obj->info)->bytes[0]
&& ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[1]==((CCreGenObjInfo*)obj->info)->bytes[1]
&& ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[2]==((CCreGenObjInfo*)obj->info)->bytes[2]
&& ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[3]==((CCreGenObjInfo*)obj->info)->bytes[3])
{
fraction = CGI->objh->objInstances[vv]->subID; //TODO: is typeID what we really want?
}
}
}
if(fraction == -1)
{
fraction = rand()%F_NUMBER; //TODO: check it more
}
int lvl = atoi(di->name.substr(7, 8).c_str()) - 1;
return creGenNames[fraction][lvl];
}
else
{
std::vector<int> possibleTowns;
for(int bb=0; bb<8; ++bb)
{
if(((CCreGenObjInfo*)obj->info)->castles[0] & (1<<bb))
{
possibleTowns.push_back(bb);
}
}
if(((CCreGenObjInfo*)obj->info)->castles[1])
possibleTowns.push_back(8);
int fraction = possibleTowns[rand()%possibleTowns.size()];
int lvl = atoi(di->name.substr(7, 8).c_str()) - 1;
return creGenNames[fraction][lvl];
}
}
else if(di->id==216) //random dwelling
{
std::vector< std::vector<std::string> > creGenNames;
creGenNames.resize(F_NUMBER);
for(int ff=0; ff<F_NUMBER-1; ++ff)
{
for(int dd=0; dd<7; ++dd)
{
creGenNames[ff].push_back(CGI->dobjinfo->objs[394+7*ff+dd].defName);
}
}
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[456].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[451].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[454].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[453].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[452].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[457].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[458].defName);
if(((CCreGenObjInfo*)obj->info)->asCastle)
{
int faction = -1;
for(int vv=0; vv<CGI->objh->objInstances.size(); ++vv)
{
if(CGI->objh->objInstances[vv]->defInfo->id==98) //is a town
{
if( //check if it is this one we want
((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[0]==((CCreGenObjInfo*)obj->info)->bytes[0]
&& ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[1]==((CCreGenObjInfo*)obj->info)->bytes[1]
&& ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[2]==((CCreGenObjInfo*)obj->info)->bytes[2]
&& ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[3]==((CCreGenObjInfo*)obj->info)->bytes[3])
{
faction = CGI->objh->objInstances[vv]->subID; //TODO: is typeID what we really want?
}
}
}
int lvl=-1;
if((((CCreGen2ObjInfo*)obj->info)->maxLevel - ((CCreGen2ObjInfo*)obj->info)->minLevel)!=0)
lvl = rand()%(((CCreGen2ObjInfo*)obj->info)->maxLevel - ((CCreGen2ObjInfo*)obj->info)->minLevel) + ((CCreGen2ObjInfo*)obj->info)->minLevel;
else lvl = 0;
return creGenNames[faction][lvl];
}
else
{
std::vector<int> possibleTowns;
for(int bb=0; bb<8; ++bb)
{
if(((CCreGenObjInfo*)obj->info)->castles[0] & (1<<bb))
{
possibleTowns.push_back(bb);
}
}
if(((CCreGenObjInfo*)obj->info)->castles[1])
possibleTowns.push_back(8);
int faction = possibleTowns[rand()%possibleTowns.size()];
int lvl=-1;
if((((CCreGen2ObjInfo*)obj->info)->maxLevel - ((CCreGen2ObjInfo*)obj->info)->minLevel)!=0)
lvl = rand()%(((CCreGen2ObjInfo*)obj->info)->maxLevel - ((CCreGen2ObjInfo*)obj->info)->minLevel) + ((CCreGen2ObjInfo*)obj->info)->minLevel;
else lvl = 0;
return creGenNames[faction][lvl];
}
}
else if(di->id==218) //random creature generators with preset alignment
{
std::vector< std::vector<std::string> > creGenNames;
creGenNames.resize(F_NUMBER);
for(int ff=0; ff<F_NUMBER-1; ++ff)
{
for(int dd=0; dd<7; ++dd)
{
creGenNames[ff].push_back(CGI->dobjinfo->objs[394+7*ff+dd].defName);
}
}
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[456].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[451].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[454].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[453].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[452].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[457].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[458].defName);
int faction = atoi(di->name.substr(7, 8).c_str());
int lvl = -1;
CCreGen3ObjInfo * ct = (CCreGen3ObjInfo*)obj->info;
if(ct->maxLevel>7)
ct->maxLevel = 7;
if(ct->minLevel<1)
ct->minLevel = 1;
if((ct->maxLevel - ct->minLevel)!=0)
lvl = rand()%(ct->maxLevel - ct->minLevel) + ct->minLevel;
else
lvl = ct->maxLevel;
return creGenNames[faction][lvl];
}
return std::string();
}

View File

@ -72,6 +72,7 @@ public:
std::vector<CDefHandler *> staticRiverDefs;
std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
std::map<int, CGDefInfo*> villages, forts, capitols;
PseudoV< PseudoV< PseudoV<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
@ -91,6 +92,8 @@ public:
bool recalculateHideVisPos(int3& pos); //recalculates position for hidden / visitable positions
bool recalculateHideVisPosUnderObj(CGObjectInstance * obj, bool withBorder = false); //recalculates position for hidden / visitable positions under given object
void init();
std::pair<int,int> pickObject(CGObjectInstance *obj);
void randomizeObject(CGObjectInstance *cur);
void calculateBlockedPos();
void initObjectRects();
void borderAndTerrainBitmapInit();