Changing map starting positions

Discussion in 'Modding' started by Ftoomsh, Jan 31, 2020.

  1. Ftoomsh

    Ftoomsh Well-Known Member

    Has anyone done any work on changing map starting positions via changing parameters and processing in the dogenerate.inc file? Is it even possible by changing this file?

    I have changed the radius of mines from the peasant start positions via this file for larger maps. What I mean is I can bring the furthest outlier mines (when using rich mines) in a bit closer on a 4X map for example. I thought the far away mines were just a bit too far away from the peasant start on the 4x map so I brought these mines a bit closer.

    It's one thing to change geographic distribution and distance of mines. That's easy enough. It's another thing to change the peasant start position (and then following on from that the "center of the ellipse" start positions for all the procedures that distribute stone, wood and mines.

    I tried messing with this;

    procedure CreateStartPointPeasants(plInd : Integer; pointx, pointy : Float; spcount : Integer); // Ftoomsh adds spcount
    [*] = ;begin
    [*] = ; var cid : Integer = gMap.players[plInd].cid;
    [*] = ; if (cid>=0) and (gMap.players[plInd].bexists) then
    [*] = ; begin
    [*] = ; var peasantBaseName : String;
    [*] = ; var id : Integer;
    [*] = ; for id:=1 to gc_country_maxmembers-1 do
    [*] = ; begin
    [*] = ; var member : String = gCountry[cid].members[id];
    [*] = ; if (member<>'') then
    [*] = ; begin
    [*] = ; if (gObjProp[cid][id].usage=gc_obj_usage_peasant) then
    [*] = ; begin
    [*] = ; peasantBaseName := member;
    [*] = ; break;
    [*] = ; end;
    [*] = ; end;
    [*] = ; end;
    [*] = ; if (peasantBaseName<>'') then
    [*] = ; begin
    [*] = ; var plHnd : Integer = GetPlayerHandleByIndex(plInd);
    [*] = ; var goHnd : Integer;
    [*] = ; var px, py, pz : Float;
    [*] = ; var count : Integer = 18; // Ftoomsh note starting number of peasants
    [*] = ; px := pointx; // Ftoomsh needs to change?
    [*] = ; pz := pointy;
    [*] = ; if (spcount<=4) and (gMap.settings.gen.mapsize=2) then // Ftoomsh start new experimental section
    [*] = ; begin
    [*] = ; if (px<maphW) then px := px/2;
    [*] = ; if (pz<maphH) then pz := pz/2;
    [*] = ; end; // Ftoomsh end new experimental section

    This code attempts to move the lower left start point for just the peasants as an experiment for 4 player, 4x random maps and move it closer to the corner. It doesn't work. I just get a blank defeat screen. I have probably done a hundred things wrong here. Comments welcome if anyone has looked at this issue (starting points). I don't want to believe it can only be changed in the random map templates.

    It is a bit of mystery to me as to where the dogenerate.inc file gets the initial values for pointx and pointy. I assume they come from the random map templates. Then I assumed I could move them around to change the point the peasants are dropped in and then change the point where the other routines start and sort of spiral out to place mines, stone and wood at different angles on different spiral radii. This is my mental picture of how it works. Of course, I might be completely mistaken in all this.
     
    Johny likes this.
  2. Ebel

    Ebel Moderator Staff Member

    I have made new map templates (including start positions) and changed start positions on existing map templates for the earlier versions of my mod. The templates are no longer part of it (the mod), since GSC included my river, lake and coastal templates in the base game.

    Anyway, the start position is defined on the .tga template by a white dot.
    [​IMG]

    https://i.imgur.com/Cp6clrQ.png

    Some notes:

    - .tga format probably can't be opened by simple image programs such as Paint, you'll need something slightly more advanced. Ideally Photoshop, but if its just to view you could get Irfanview, it will also show you the thumbnails then. I'd get both. Don't pay for photoshop, it is too expensive, either torrent it, get a free trial, or, get a free alternative, like gimp ,....

    - File naming is important. The game will look at the format here to determine which file(s) to use. For example , 4pl_mask_rivers_2_gauss.tga refers to the 2nd template for river maps for 4 players. This means, this map will have (at least) 4 white dots on the image. You can't name it 4player_mynewrivermap_1337_banana.tga, it won't work this way. You can add new templates and/or terraintypes, but I think thats beyond the scope of your question.

    - Gauss in the name refers to gaussian blur, a type of post processing used in Photoshop for example to smooth out curvy edges etc to make it look better, otherwise you would have jagged river edges/jagged coast lines. For your question I don't think you will have to apply gaussian blur, unless for some reason you redo a template completely.
    They already have gaussian blur applied to them.

    - The start points themselves are pure white. Terrain is pure black. Water is pure blue. When I say 'pure', i'm referring to RGB values. So,
    White R 255 G 255 B 255
    Black R 0 G 0 B 0
    Blue R 0 G 0 B 255

    If you struggle to create them (the white dots) yourself, zoom in on an existing point , and copy it, then paste where you want it. Remember if you want to remove the previously existing point, copy a section of pure black and paste it over the old start point.
    The game can also handle pure Green for trees, but these aren't use in the random terrain generation, only in the campaign maps it is used. I think it can handle red aswell for mountains.

    - Maybe obvious but, a map for 8 players needs 8 white dots. Cossacks 1 had multiple dots per player and it would pick randomly from one of them, this doesn't work in Cossacks 3, there is no code for it, at least, to prevent 2 players spawning too close to each other in case the dots where nearby.

    - Distances to each other: (between start points)

    Some original maps have their start points too close to each other which leads to situations under certain start settings on normal maps that are almost unplayable:

    Eg; Start option : 18th century barracks ; nation: ukraine, turkey, Algeria; This would put blockhouses and 17th barracks which these nations receive on start in odd places such as in water or outside of the map.

    Because of this, the minimum distance to water/corners/edges has to be at least 0,7 cm for each start point.(East-West) Relative to each other at least 1,5 cm; but preferably a lot more or 0 pt games with these start options will lead to blockhouses killing another players peasants right at start of game. I strongly suggest minimum 2 cm between start points.
    This is also depends on the map size, as the same template is used for all map sizes. A smaller map suffers more from this type situation, where as a larger map doesn't.

    Keep this in mind when placing the start point, if any or all peasants spawn outside of the map because of this, it's a guaranteed defeat.

    - File format: tga type 10 , 24 bits, rle compressed format. ( Options when saving the .tga)




    Now, you could code the changes, but at the very least you need to know where the normal start positions are and how they roughly work as I sorta explained above.

    Changing startpoints on the .tga : easy, but a lot of work.
    Changing startpoints by code: more complex, less work.

    Edit: I forgot to say, you could probably search in the code for values such as 255, you will eventually end up with where the code picks up the white color, blue, black etc to determine terrain, start points and what not. I remember searching for it when I made my mod, I just don't remember where it was.

    Edit2: they are in /data/gen/terrainmasks/ (obvious but not if you haven't ever seen them)
     
    Johny likes this.
  3. Ftoomsh

    Ftoomsh Well-Known Member

    Ebel, Thank you. Useful information. I will do a few more experiments to see if dogenerate.inc can move the peasants and the whole epicenter of the start x,y point to another position. This is probably futile but I haven't quite tested it properly yet. Certainly peasants can be placed off-center relative to the map x,y point because the 18 starting peasants are lined up in two lines by this code:

    First, some variables are set;

    [*] = ; var count : Integer = 18; // Ftoomsh: note starting number of peasants
    [*] = ; px := pointx;
    [*] = ; pz := pointy;

    I suspect that pointx and pointy come from the map file template which is two-dimenional, hence the x and y. The file dogenerate.inc sets px and pz equal to them. The reason the second one is pz is to avoid confusion because the actual landscape being created is 3D and in 3D in C3 the y axis is the vertical axis.

    Then, the program uses this following code to place peasants, otherwise they would all be placed on the same spot;

    [*] = ; var i : Integer;
    [*] = ; for i:=0 to count-1 do
    [*] = ; begin
    [*] = ; px := px+(i div 3)*cUnitR+(0.5-RandomExt)*0.25-(((count div 3)*cUnitR)/2);
    [*] = ; pz := pz+(i mod 3)*cUnitR+(0.5-RandomExt)*0.25-(((count mod 3)*cUnitR)/2);
    [*] = ; gint_unit_parentcid := cid;
    [*] = ; goHnd := CreatePlayerGameObjectHandleByHandle(plHnd, gc_racename_units, peasantBaseName, px, py, pz);
    [*] = ; SetGameObjectRollAngleByHandle(goHnd, 180);
    [*] = ; end;

    So, in principle, these peasants could be shifted somewhere else except if they end up off-map and cause instant defeat which might be my problem in my tests to date.
    Then of course, all the other generation (mines, wood, stone) would have to be moved to have the new peasant center location as its epicenter too. It's all theory though and my theory is shaky.
     
  4. Ebel

    Ebel Moderator Staff Member

    Just move the white dot on the .tga if you want to move the start point. It's much simpler than messing around with code to move it.

    The problem you will keep running into with trying to code it is the following: if you want to move start peasants closer to the corner as you say, consider that every map template has different start point positions. What works for one won't work for another.
     
  5. Ftoomsh

    Ftoomsh Well-Known Member

    Ebel,

    I take your point but being stubborn I am going to play with the code a little more. But I have a question. Do the .tga maps count the x,y point of 0,0 as being at the center of the map? One of the results of my experiments seems to suggest this is the case.

    The code below works but it moves all the x,y points south-east and not towards the corners.

    [*] = ; newpointx := pointx; // Ftoomsh
    [*] = ; newpointy := pointy; // Ftoomsh
    [*] = ; if (gMap.settings.gen.mapsize<3) then // Ftoomsh start experimental section (spcount<=4?)
    [*] = ; begin
    [*] = ; if (newpointx<maphW) then newpointx := newpointx + maphW/8.0;
    [*] = ; if (newpointx>maphW) then newpointx := newpointx - maphW/8.0;
    [*] = ; if (newpointy<maphH) then newpointy := newpointy + maphH/8.0;
    [*] = ; if (newpointy>maphH) then newpointy := newpointy - maphH/8.0;
    [*] = ; end; // Ftoomsh end experimental section
    [*] = ;
    [*] = ; const cUnitR = 0.75;
    [*] = ; var i : Integer;
    [*] = ; for i:=0 to count-1 do
    [*] = ; begin
    [*] = ; px := newpointx+(i div 3)*cUnitR+(0.5-RandomExt)*0.25-(((count div 3)*cUnitR)/2); // Ftoomsh
    [*] = ; pz := newpointy+(i mod 3)*cUnitR+(0.5-RandomExt)*0.25-(((count mod 3)*cUnitR)/2); // Ftoomsh
    [*] = ; gint_unit_parentcid := cid;
    [*] = ; goHnd := CreatePlayerGameObjectHandleByHandle(plHnd, gc_racename_units, peasantBaseName, px, py, pz);
    [*] = ; SetGameObjectRollAngleByHandle(goHnd, 180);
    [*] = ; end;

    In the third line I think I could nominate just the maps I want to change like this;

    if (spcount<=4) and (gMap.settings.gen.mapsize=2) then // Only maps with 4 or less players and only 4x maps

    But there are a lot of other issues as you say. I can't move them too much towards the corner or a start that is already close to the corner will go over the edge of the map and then Defeat! Also the peasants can end up 1/3rd on lowland, 1/3rd on impassable ground and 1/3 rd on upland, for example. That test was funny but the peasants on the impassable ground still walked off it okay. I believe units can walk off impassable ground but not on to it. Walking off impassable ground is how they come out of buildings from what I can tell. But this would still be an unfair start for that player.

    And off course, now my peasants start elsewhere but the mines, wood and stone fields are all still in the old places so I would have to move all them too.

    I've resisted doing map work but maybe I will have to bite the bullet soon.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice