aliens

Author Topic: Street generations and wiki definition  (Read 7118 times)

Offline davide

  • Commander
  • *****
  • Posts: 565
    • View Profile
Street generations and wiki definition
« 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]
Code: [Select]
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:

Code: [Select]
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

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2162
    • View Profile
Re: Street generations and wiki definition
« Reply #1 on: July 27, 2014, 09:04:02 pm »
It's an exclusive set of conditions. For example if EW is 30% and NS is 40%, the odds would be:
Code: [Select]
EWRoad =   [0,30[    https:// 30%
NSRoad =   [30,70[   https:// 40%
TwoRoads = [70,100[  https:// 30%

Or in psuedocode:
Code: [Select]
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;

Offline davide

  • Commander
  • *****
  • Posts: 565
    • View Profile
Re: Street generations and wiki definition
« Reply #2 on: July 27, 2014, 11:11:15 pm »
Thanks I understand

The streets are mandatory,
with my simple approuch there are the probability that there are not any street.

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11730
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: Street generations and wiki definition
« Reply #3 on: July 28, 2014, 12:00:21 am »
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.

Offline davide

  • Commander
  • *****
  • Posts: 565
    • View Profile
Re: Street generations and wiki definition
« Reply #4 on: July 28, 2014, 12:11:35 am »
I think that it is sufficient remark the line that check the mission type and check the existence of street maps

Code: [Select]
/* 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++;
}
}
}
}

« Last Edit: July 28, 2014, 12:51:55 am by davide »

Offline Arthanor

  • Commander
  • *****
  • Posts: 2488
  • XCom Armoury Quartermaster
    • View Profile
Re: Street generations and wiki definition
« Reply #5 on: August 05, 2014, 12:23:56 am »
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?)

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11730
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: Street generations and wiki definition
« Reply #6 on: August 05, 2014, 12:30:40 am »
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).

Offline Arthanor

  • Commander
  • *****
  • Posts: 2488
  • XCom Armoury Quartermaster
    • View Profile
Re: Street generations and wiki definition
« Reply #7 on: August 05, 2014, 04:18:14 am »
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)

Offline Falko

  • Commander
  • *****
  • Posts: 802
    • View Profile
Re: Street generations and wiki definition
« Reply #8 on: August 05, 2014, 09:40:45 am »
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?

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11730
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: Street generations and wiki definition
« Reply #9 on: August 05, 2014, 04:16:16 pm »
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.