Script: Regions' terrain, movement cost, and coast?

Moderator: Pocus

Post Reply
kronenblatt
General - Carrier
General - Carrier
Posts: 4691
Joined: Mon Jun 03, 2019 4:17 pm
Location: Stockholm, SWEDEN

Script: Regions' terrain, movement cost, and coast?

Post by kronenblatt »

How can I script wise check a land region's:

1. terrain type,
2. number of movement points needed to enter it,
3. and whether it's a coastal region, i.e., adjacent to a Coastal Water non-land region.
kronenblatt's campaign and tournament thread hub:

https://www.slitherine.com/forum/viewtopic.php?t=108643
Pocus
Ageod
Ageod
Posts: 7115
Joined: Tue Oct 02, 2012 3:05 pm

Re: Regions' terrain, movement cost, and coast?

Post by Pocus »

1.
Region_GetTerrain(regionID)

2.
Region_LandCost(regionID)
that's an absolute cost, not relative to a given group though, the alternate possibility would be
Group_LandCost(groupID, regionID, weatherID)

3.
Region_IsAdjacentToWater(regionID, bOnlyNonFrozenWater)
will accept a dual terrain though like a swamp, alternate possibility
Region_IsAdjacentToPureWater(regionID, bOnlyNonFrozenWater)

I don't know by heart all functions in the code, so to find easily stuff, I use notepad++. Now I know where things are generally, so I knew it was in the region.bsf file, but you can also find stuff by doing a search in the file or with a multi files search. With some preparation Notepad++ can look like this when coding. Notice I typed 'cost' in the function list and results are rather interesting.

Image
AGEOD Team - Makers of Kingdoms, Empires, ACW2, WON, EAW, PON, AJE, RUS, ROP, WIA.
SuitedQueens
Master Sergeant - Bf 109E
Master Sergeant - Bf 109E
Posts: 479
Joined: Fri Mar 12, 2021 3:09 pm

Re: Script: Regions' terrain, movement cost, and coast?

Post by SuitedQueens »

Nice to see someone using Notepad++ exactly like me :)

I wonder why do you need it kronenblatt. Some new functionality for your mod that can be integrated in Europa Barbarorum will be great.
kronenblatt
General - Carrier
General - Carrier
Posts: 4691
Joined: Mon Jun 03, 2019 4:17 pm
Location: Stockholm, SWEDEN

Re: Regions' terrain, movement cost, and coast?

Post by kronenblatt »

Pocus wrote: Thu Apr 29, 2021 7:43 am 1.
Region_GetTerrain(regionID)

2.
Region_LandCost(regionID)
that's an absolute cost, not relative to a given group though, the alternate possibility would be
Group_LandCost(groupID, regionID, weatherID)

3.
Region_IsAdjacentToWater(regionID, bOnlyNonFrozenWater)
will accept a dual terrain though like a swamp, alternate possibility
Region_IsAdjacentToPureWater(regionID, bOnlyNonFrozenWater)

Thanks, Pocus! Then I can dig deeper into this. A few quick follow-up questions along the way though:

1. Would I then get a result corresponding to the ID value in TERRAINS.CSV?
(EDIT: I now see e.g. Region_GetTerrain(regionID) == $ID_TER_ARIDHILL, which answers my question.)

2. Excellent: so Region_LandCost(regionID) seems to be the one to use. Would the result then be the movement point costs as shown in the picture from the in-game Movement Overlay (and with, as examples, the numbers marked in green)?
(EDIT: int result in combination with result = Region_LandCost(regionID)(and // includes roads if non directional road rule FALSE) indicate that this is the case, but would appreciate confirmation. And that it doesn't include river crossings or straits, since that would be only between regions?)

Image

Image

3. Yes, would be Region_IsAdjacentToPureWater(regionID, bOnlyNonFrozenWater) here. Will result in a TRUE or FALSE only, I guess?
(EDIT: found this one, Region_IsAdjacentToPureWater(regionID, FALSE) == TRUE, answering this question of mine too, also to use FALSE for bOnlyNonFrozenWater.)

I'm using NP++ too, and the Find in Files extensively. Although I got curious about the Archon user-defined language. I've got an older version already, so where can I find the latest?
Last edited by kronenblatt on Thu Apr 29, 2021 12:15 pm, edited 6 times in total.
kronenblatt's campaign and tournament thread hub:

https://www.slitherine.com/forum/viewtopic.php?t=108643
kronenblatt
General - Carrier
General - Carrier
Posts: 4691
Joined: Mon Jun 03, 2019 4:17 pm
Location: Stockholm, SWEDEN

Re: Script: Regions' terrain, movement cost, and coast?

Post by kronenblatt »

SuitedQueens wrote: Thu Apr 29, 2021 9:08 am I wonder why do you need it kronenblatt. Some new functionality for your mod that can be integrated in Europa Barbarorum will be great.
Yes, I'm considering introducing a small multiplicative adjustment to the distances in the Remote Regions mod, based on e.g. the region's terrain type and/or movement point cost and whether the region is in fact has a coast or is landlocked. Very simple adjustments then, but nevertheless. But I need to understand how to script it to result in multiplicative factors of say 0.9, 1.1, 1.2, etc.

These adjustments could make sense, since empires historically tended to expand along the coasts and over seas to other coastal regions where transports could be faster and communication more efficient, and not necessary into rough inland territories with deserts (read: Sahara), high mountains (read: Caucasus), and deep forests (read: Germania), especially if far-away from imperial centre. Simply too much of an effort and wouldn't really pay off.
kronenblatt's campaign and tournament thread hub:

https://www.slitherine.com/forum/viewtopic.php?t=108643
kronenblatt
General - Carrier
General - Carrier
Posts: 4691
Joined: Mon Jun 03, 2019 4:17 pm
Location: Stockholm, SWEDEN

Re: Script: Regions' terrain, movement cost, and coast?

Post by kronenblatt »

Furthermore, if I'd like to check for whether a region is adjacent to a river, I'd use:

Region_IsAdjacentToRiver_Strait(regionID, bCheckRivers, bCheckStrait) == TRUE

and more specifically:

Region_IsAdjacentToRiver_Strait(regionID, TRUE, FALSE) = TRUE ?

The reason being that communication and administration and thus natural expansion can also be assumed to take its way via routes along the rivers.
kronenblatt's campaign and tournament thread hub:

https://www.slitherine.com/forum/viewtopic.php?t=108643
kronenblatt
General - Carrier
General - Carrier
Posts: 4691
Joined: Mon Jun 03, 2019 4:17 pm
Location: Stockholm, SWEDEN

Re: Script: Regions' terrain, movement cost, and coast?

Post by kronenblatt »

The idea is to have a region's distance to the capital, multiplied with one of the following factors, depending on its terrain:

PLAIN: 100%
STEPPES: 103%
HILL: 106%
FOREST: 109%
DESERT: 112%
MARSH: 115%
MOUNTAIN: 118%
ALPINE: 121%

And then also multiplied with one of the following factors:
If COAST region: 100%
If not COAST region but adjacent to RIVER: 108%
If not COAST region and not adjacent to RIVER: 116%

Thus a faraway ALPINE region with neither COAST nor RIVER of original distance of say 100 000 would obtain a modified distance of 100 000 x 121% x 116% = 140 360 applied when determining its Remote Region modifier of I-V.
kronenblatt's campaign and tournament thread hub:

https://www.slitherine.com/forum/viewtopic.php?t=108643
SuitedQueens
Master Sergeant - Bf 109E
Master Sergeant - Bf 109E
Posts: 479
Joined: Fri Mar 12, 2021 3:09 pm

Re: Script: Regions' terrain, movement cost, and coast?

Post by SuitedQueens »

That's good to hear. I will be able to reduce penalty distance and increase or decrease percentages based on the terrain. I play my Burgundi Suicidal using your mod with modified penalty values, but not distance right now.
kronenblatt
General - Carrier
General - Carrier
Posts: 4691
Joined: Mon Jun 03, 2019 4:17 pm
Location: Stockholm, SWEDEN

Re: Script: Regions' terrain, movement cost, and coast?

Post by kronenblatt »

SuitedQueens wrote: Fri Apr 30, 2021 5:42 am That's good to hear. I will be able to reduce penalty distance and increase or decrease percentages based on the terrain. I play my Burgundi Suicidal using your mod with modified penalty values, but not distance right now.
Excellent! Yep, it's quite straightforward for players to make adjustments in the mod to suit personal preferences.
kronenblatt's campaign and tournament thread hub:

https://www.slitherine.com/forum/viewtopic.php?t=108643
Pocus
Ageod
Ageod
Posts: 7115
Joined: Tue Oct 02, 2012 3:05 pm

Re: Script: Regions' terrain, movement cost, and coast?

Post by Pocus »

yes to your remaining questions :D

I will though issue a warning about using too extensive calculations frequently. Coding things which are not too demanding is still a significant part of the decision about a game feature and how detailed it is.
AGEOD Team - Makers of Kingdoms, Empires, ACW2, WON, EAW, PON, AJE, RUS, ROP, WIA.
kronenblatt
General - Carrier
General - Carrier
Posts: 4691
Joined: Mon Jun 03, 2019 4:17 pm
Location: Stockholm, SWEDEN

Re: Script: Regions' terrain, movement cost, and coast?

Post by kronenblatt »

Pocus wrote: Fri Apr 30, 2021 2:29 pm I will though issue a warning about using too extensive calculations frequently. Coding things which are not too demanding is still a significant part of the decision about a game feature and how detailed it is.
True, good to keep in mind. This is just a number of if's and else if's, but sure it all adds up in the end.

Code: Select all

#define EVTCUSTOM_REMOTEREGION_TERRAIN_PLAIN 100
#define EVTCUSTOM_REMOTEREGION_TERRAIN_STEPPES 103
#define EVTCUSTOM_REMOTEREGION_TERRAIN_HILL 106
#define EVTCUSTOM_REMOTEREGION_TERRAIN_FOREST 109
#define EVTCUSTOM_REMOTEREGION_TERRAIN_DESERT 112
#define EVTCUSTOM_REMOTEREGION_TERRAIN_MARSH 115
#define EVTCUSTOM_REMOTEREGION_TERRAIN_MOUNTAIN 118
#define EVTCUSTOM_REMOTEREGION_TERRAIN_ALPINE 121
#define EVTCUSTOM_REMOTEREGION_TERRAIN_COAST 100
#define EVTCUSTOM_REMOTEREGION_TERRAIN_RIVER 108
#define EVTCUSTOM_REMOTEREGION_TERRAIN_LANDLOCKED 116

...

capitalID = Faction_Politic_NearestCapitalID(factionID, regionID); 

// gResult is the distance value received from Faction_Politic_NearestCapitalID
// ADDING MULTIPLICATIVE MODIFIERS FOR TERRAIN, COAST, AND RIVER

// TERRAIN
// DIVIDE FIRST BY 100 TO GET THE SIZES RIGHT, SINCE gRESULT IS THEN MULTIPLIED BY 100 OR MORE
gResult = DivideAndRound (gResult, 100);

if ( Region_GetTerrain(regionID) == $ID_TER_PLAIN )
{
gResult *= EVTCUSTOM_REMOTEREGION_TERRAIN_PLAIN;
}
else if ( Region_GetTerrain(regionID) == $ID_TER_STEPPES || Region_GetTerrain(regionID) == $ID_TER_ARIDSTEPPES )
{
gResult *= EVTCUSTOM_REMOTEREGION_TERRAIN_STEPPES;
}
else if ( Region_GetTerrain(regionID) == $ID_TER_HILL || Region_GetTerrain(regionID) == $ID_TER_ARIDHILL )
{
gResult *= EVTCUSTOM_REMOTEREGION_TERRAIN_HILL;
}
else if ( Region_GetTerrain(regionID) == $ID_TER_FOREST )
{
gResult *= EVTCUSTOM_REMOTEREGION_TERRAIN_FOREST;
}
else if ( Region_GetTerrain(regionID) == $ID_TER_DESERT )
{
gResult *= EVTCUSTOM_REMOTEREGION_TERRAIN_DESERT;
}
else if ( Region_GetTerrain(regionID) == $ID_TER_MARSH )
{
gResult *= EVTCUSTOM_REMOTEREGION_TERRAIN_MARSH;
}
else if ( Region_GetTerrain(regionID) == $ID_TER_MOUNTAIN )
{
gResult *= EVTCUSTOM_REMOTEREGION_TERRAIN_MOUNTAIN;
}
else if ( Region_GetTerrain(regionID) == $ID_TER_ALPINE )
{
gResult *= EVTCUSTOM_REMOTEREGION_TERRAIN_ALPINE;
}
// COASTS AND RIVERS
// DIVIDE FIRST BY 100 TO GET THE SIZES RIGHT, SINCE gRESULT IS THEN MULTIPLIED BY 100 OR MORE
gResult = DivideAndRound (gResult, 100);

if ( Region_IsAdjacentToPureWater(regionID, FALSE) == TRUE )
{
gResult *= EVTCUSTOM_REMOTEREGION_TERRAIN_COAST;
}
else if ( Region_IsAdjacentToPureWater(regionID, FALSE) == FALSE && Region_IsAdjacentToRiver_Strait(regionID, TRUE, FALSE) == TRUE )
{
gResult *= EVTCUSTOM_REMOTEREGION_TERRAIN_RIVER;
}
else if ( Region_IsAdjacentToPureWater(regionID, FALSE) == FALSE && Region_IsAdjacentToRiver_Strait(regionID, TRUE, FALSE) == FALSE )
{
gResult *= EVTCUSTOM_REMOTEREGION_TERRAIN_LANDLOCKED;
}

...

kronenblatt's campaign and tournament thread hub:

https://www.slitherine.com/forum/viewtopic.php?t=108643
Pocus
Ageod
Ageod
Posts: 7115
Joined: Tue Oct 02, 2012 3:05 pm

Re: Script: Regions' terrain, movement cost, and coast?

Post by Pocus »

If only a region was checked that would be fine, but you are doing that for hundreds of regions! That's the issue. You should try to trim upstream as many regions as possible: don't check water regions, don't check regions which are under a world nation control (we don't care...), don't even check regions under the control of a tribal which is not a player perhaps, or a nation with only 5 or less regions, who cares? They are small, let's cut them some slack. This way 90% of your regions are skipped. As a game developer, I had to learn where to draw the line between (pseudo)-realism and efficiency.

As for the actual code, if you don't mind a remark or two.

if ( Region_GetTerrain(regionID) == $ID_TER_PLAIN )
etc.

Don't repeat the call to GetTerrain, calculate it before any if and use the value for quicker evaluation
Test common terrains before rare terrains
Same remark for Region_IsAdjacentToPureWater, only one calculation necessary, not three
AGEOD Team - Makers of Kingdoms, Empires, ACW2, WON, EAW, PON, AJE, RUS, ROP, WIA.
kronenblatt
General - Carrier
General - Carrier
Posts: 4691
Joined: Mon Jun 03, 2019 4:17 pm
Location: Stockholm, SWEDEN

Re: Script: Regions' terrain, movement cost, and coast?

Post by kronenblatt »

Pocus wrote: Sat May 01, 2021 5:39 pm If only a region was checked that would be fine, but you are doing that for hundreds of regions! That's the issue. You should try to trim upstream as many regions as possible: don't check water regions, don't check regions which are under a world nation control (we don't care...), don't even check regions under the control of a tribal which is not a player perhaps, or a nation with only 5 or less regions, who cares? They are small, let's cut them some slack. This way 90% of your regions are skipped. As a game developer, I had to learn where to draw the line between (pseudo)-realism and efficiency.

As for the actual code, if you don't mind a remark or two.

if ( Region_GetTerrain(regionID) == $ID_TER_PLAIN )
etc.

Don't repeat the call to GetTerrain, calculate it before any if and use the value for quicker evaluation
Test common terrains before rare terrains
Same remark for Region_IsAdjacentToPureWater, only one calculation necessary, not three
I I don't mind at all. Thanks for advice!

How do I calculate GetTerrain()?

Simply: x = Region_GetTerrain(regionID)? Then what type of variable do I have to declare x as?

And with: y = Region_IsAdjacentToPureWater(). I guess then that y is boolean type of variable?

And when it comes to which regions and states to apply this on, I'm leaning in the end to only apply it on players and not AI.

Which function would be the appropriate for that?
kronenblatt's campaign and tournament thread hub:

https://www.slitherine.com/forum/viewtopic.php?t=108643
kronenblatt
General - Carrier
General - Carrier
Posts: 4691
Joined: Mon Jun 03, 2019 4:17 pm
Location: Stockholm, SWEDEN

Re: Script: Regions' terrain, movement cost, and coast?

Post by kronenblatt »

How do I apply a function only on players and not AI, without having to iterate over all factions?

i.e., NOT this:
facCount = GetNumFactions();
for (facIndex = 0; facIndex < facCount; facIndex++)
{
factionID = GetFactionID(facIndex);
bIsHuman = IsHumanFaction(factionID);
if ( bIsHuman == TRUE )
{
}
}
kronenblatt's campaign and tournament thread hub:

https://www.slitherine.com/forum/viewtopic.php?t=108643
Pocus
Ageod
Ageod
Posts: 7115
Joined: Tue Oct 02, 2012 3:05 pm

Re: Script: Regions' terrain, movement cost, and coast?

Post by Pocus »

Archon only supports integers as return value in functions, so you are safe here :-)
when you need to get a string result, that's a global string that will be valued within the function, typical example gString in many functions.
any function named 'Is' will return a boolean, which is either 0 or 1. You can replace these values by FALSE and TRUE respectively. You can even skip TRUE for a more natural language approach, e.g.:

if (Region_IsAdjacentToPureWater())
{
DoThis
}

I second your idea, apply only that to human. That's what some players don't get, AIs and human are not equivalent and will never be, at least in the domain of video games. There is no point in trying to have them follow completely the same rules, as the fundamental premise is wrong, they are not equivalent, they don't think alike and a so called AI is only a mere few thousands lines of code.

Back to the question!

the function to use is
Faction_AI_IsHumanPlayer(factionID)

you can call it directly and shave a few microseconds with

if (Faction_AI_IsHumanPlayer(factionID))
{

}

----------

A note on $XXXX variables. They are integers. This is just a redirection/renaming of an integer.
AGEOD Team - Makers of Kingdoms, Empires, ACW2, WON, EAW, PON, AJE, RUS, ROP, WIA.
kronenblatt
General - Carrier
General - Carrier
Posts: 4691
Joined: Mon Jun 03, 2019 4:17 pm
Location: Stockholm, SWEDEN

Re: Script: Regions' terrain, movement cost, and coast?

Post by kronenblatt »

Pocus wrote: Mon May 03, 2021 7:58 am ...
Thanks for advice, Pocus!
kronenblatt's campaign and tournament thread hub:

https://www.slitherine.com/forum/viewtopic.php?t=108643
Post Reply

Return to “MOD”