OpenXcom Forum
Contributions => Programming => Topic started by: davide on July 27, 2014, 10:36:48 am
-
I do not understand the decision algorithm ...
On wiki there is this definition:
roadTypeOdds Odds as a % of generating each type of road (E-W Road, N-S Road, Crossing) odds for crossing are: 100 - EW - NS.
but the source code is much complex:
BattlescapeGenerator::generateMap [line:1250 about]
std::vector<int> roadChances = _terrain->getRoadTypeOdds();
int roadStyle = RNG::generate(0,99);
bool EWRoad = roadStyle < roadChances.at(0);
bool NSRoad = !EWRoad && roadStyle < roadChances.at(0) + roadChances.at(1);
bool TwoRoads = !EWRoad && !NSRoad;
....
if (TwoRoads)
{
https:// put a crossing on the X,Y position and fill the rest with roads
EWRoad = true;
NSRoad = true;
}
from wiki definition I expected something to simple:
std::vector<int> roadChances = _terrain->getRoadTypeOdds();
bool EWRoad = roadChances.at(0) > RNG::generate(0,99);
bool NSRoad = roadChances.at(1) > RNG::generate(0,99);
bool TwoRoads = EWRoad && NSRoad;
Someone could explain to me ?
Thanks
-
It's an exclusive set of conditions. For example if EW is 30% and NS is 40%, the odds would be:
EWRoad = [0,30[ https:// 30%
NSRoad = [30,70[ https:// 40%
TwoRoads = [70,100[ https:// 30%
Or in psuedocode:
int roadStyle = RNG::generate(0, 99);
if (roadStyle >= 0 && roadStyle < EWOdds)
EWRoad = true;
else if (roadStyle >= EWOdds && roadStyle < EWOdds + NSOdds)
NSRoad = true;
else
TwoRoads = true;
-
Thanks I understand
The streets are mandatory,
with my simple approuch there are the probability that there are not any street.
-
Would it be possible to apply this code to terrains other than city?
The idea is simple: forest/jungle creeks. Possibly on farm terrain too.
-
I think that it is sufficient remark the line that check the mission type and check the existence of street maps
/* determine positioning of the urban terrain roads */
https://REMARK if (_save->getMissionType() == "STR_TERROR_MISSION")
{
std::vector<int> roadChances = _terrain->getRoadTypeOdds();
int roadStyle = RNG::generate(0,99);
bool EWRoad = roadStyle < roadChances.at(0);
bool NSRoad = !EWRoad && roadStyle < roadChances.at(0) + roadChances.at(1);
bool TwoRoads = !EWRoad && !NSRoad;
int roadX = RNG::generate(0, (_mapsize_x/10)- 1);
int roadY = RNG::generate(0, (_mapsize_y/10)- 1);
https:// make sure the road(s) are not crossing the craft/ufo landing site
while (
(_craft != 0 && craftMap && ((roadX >= _craftX && roadX < _craftX + (craftMap->getSizeX() / 10)) || (roadY >= _craftY && roadY < _craftY + (craftMap->getSizeY() / 10))))
||
(_ufo != 0 && ufoMap && ((roadX >= ufoX && roadX < ufoX + (ufoMap->getSizeX() / 10)) || (roadY >= ufoY && roadY < ufoY + (ufoMap->getSizeY() / 10))))
)
{
roadX = RNG::generate(0, (_mapsize_x/10)- 1);
roadY = RNG::generate(0, (_mapsize_y/10)- 1);
}
if (TwoRoads)
{
https:// put a crossing on the X,Y position and fill the rest with roads
MapBlock* m = _terrain->getRandomMapBlock(10, MT_CROSSING);
if (m)
{
blocks[roadX][roadY] = m;
blocksToDo--;
EWRoad = true;
NSRoad = true;
}
}
if (EWRoad)
{
while (x < (_mapsize_x / 10))
{
if (blocks[x][roadY] == 0)
{
MapBlock* m = _terrain->getRandomMapBlock(10, MT_EWROAD);
if (m)
{
blocks[x][roadY] = m;
blocksToDo--;
}
}
x++;
}
}
if (NSRoad)
{
while (y < (_mapsize_y / 10))
{
if (blocks[roadX][y] == 0)
{
MapBlock* m = _terrain->getRandomMapBlock(10, MT_NSROAD);
if (m)
{
blocks[roadX][y] = m;
blocksToDo--;
}
}
y++;
}
}
}
}
-
Soo..? What you're saying is that with barely an added condition to the "if", we could generate rivers by defining roads to be blue tiles? (And presumably setting some of those to being impassable, which would occur in the map design, not in the generation?)
-
Soo..? What you're saying is that with barely an added condition to the "if", we could generate rivers by defining roads to be blue tiles? (And presumably setting some of those to being impassable, which would occur in the map design, not in the generation?)
Well, it'd require new tiles, so a new MCD version... But yeah, something like that. Though impassable tiles would cause problems, like being unable to reach the UFO; I thought about making them slow to cross, like 8 points per step (normally 4, in wheat 6).
-
Sounds promising then! Rivers would be an interesting addition. I can't wait to shoot some chrysalis as it is trying to cross the river 8)
-
Well, it'd require new tiles, so a new MCD version... But yeah, something like that. Though impassable tiles would cause problems, like being unable to reach the UFO; I thought about making them slow to cross, like 8 points per step (normally 4, in wheat 6).
cant you force the map generator to include at least one bridge tile?
-
cant you force the map generator to include at least one bridge tile?
Hmm, an interesting idea!
Yes, it appears to me that it can be forced through a ruleset.