Announcement

Collapse
No announcement yet.

City Surroundings Explained

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • City Surroundings Explained

    Another thing I always found hard to understand (squared radius?!) and hard to keep in mind when modding DB-files used to be "city surroundings data". To overcome this annoyance I created a small image as a memory card:

    Click image for larger version

Name:	CitySurroundings.png
Views:	80
Size:	15.0 KB
ID:	9490830

    The image shows the city radii as the city grows. The numbers indicate the following:
    • first number: the INT-radius
    • second number (T): number of tiles the radius comprises
    • third number (SQ): the SQUARED radius. You shalt count diagonally from the center tile to the edge tile of the respective radius, which from int-radius 2 onwards already belongs to the next radius (to no mans land for the last radius), then you shalt multiply this number by 4 (not by 3, except you proceed to the 4 -- 5 is right out).
    In the hopes this might be helpful for someone -- cheers Bert
    The modding knowledgebase: CTP2 Bureau (with CTP2 AE Modding Wiki). Modern Times Mod (work in progress): MoT-Mod for CTP2.

  • #2
    Hello again,

    I have used my "memory card" above to write a "GetSurroundings"-function which allows to store the "city sized" surroundings of any location (not only city locations!) in a global variable, which may then be used obtain information about any desired portion of these surrounding tiles, build tile improvements, give armies the order to move there, etc.

    For this purpose I had to extend my graphical tools a bit:

    Click image for larger version  Name:	CitySurroundings+.png Views:	1 Size:	9.7 KB ID:	9492287

    This enabled me to write the following (long but easily understandable) function -- you will probably want to skip some lines :

    PHP Code:
    void_f GetSurroundings(location_t theLoc) {
        location_t surBaseLoc;
        location_t surCheckLoc00;
        location_t surCheckLoc01;
        location_t surCheckLoc02;
        location_t surCheckLoc03;
        location_t surCheckLoc04;
        location_t surCheckLoc05;
        location_t surCheckLoc06;
        location_t surCheckLoc07;
        location_t surCheckLoc08;
        location_t surCheckLoc09;
        location_t surCheckLoc10;
        location_t surCheckLoc11;
        location_t surCheckLoc12;
        location_t surCheckLoc13;
        location_t surCheckLoc14;
        location_t surCheckLoc15;
        location_t surCheckLoc16;
        location_t surCheckLoc17;
        location_t surCheckLoc18;
        location_t surCheckLoc19;
        location_t surCheckLoc20;
        location_t surCheckLoc21;
        location_t surCheckLoc22;
        location_t surCheckLoc23;
        location_t surCheckLoc24;
        location_t surCheckLoc25;
        location_t surCheckLoc26;
        location_t surCheckLoc27;
        location_t surCheckLoc28;
        location_t surCheckLoc29;
        location_t surCheckLoc30;
        location_t surCheckLoc31;
        location_t surCheckLoc32;
        location_t surCheckLoc33;
        location_t surCheckLoc34;
        location_t surCheckLoc35;
        location_t surCheckLoc36;
        location_t surCheckLoc37;
        location_t surCheckLoc38;
        location_t surCheckLoc39;
        location_t surCheckLoc40;
        location_t surCheckLoc41;
        location_t surCheckLoc42;
        location_t surCheckLoc43;
        location_t surCheckLoc44;
        location_t surCheckLoc45;
        location_t surCheckLoc46;
        location_t surCheckLoc47;
        location_t surCheckLoc48;
        location_t surCheckLoc49;
        location_t surCheckLoc50;
        location_t surCheckLoc51;
        location_t surCheckLoc52;
        location_t surCheckLoc53;
        location_t surCheckLoc54;
        location_t surCheckLoc55;
        location_t surCheckLoc56;
        location_t surCheckLoc57;
        location_t surCheckLoc58;
        location_t surCheckLoc59;
        location_t surCheckLoc60;
        location_t surCheckLoc61;
        location_t surCheckLoc62;
        location_t surCheckLoc63;
        location_t surCheckLoc64;
        location_t surCheckLoc65;
        location_t surCheckLoc66;
        location_t surCheckLoc67;
        location_t surCheckLoc68;
        location_t surCheckLoc69;
        location_t surCheckLoc70;
        location_t surCheckLoc71;
        location_t surCheckLoc72;
        location_t surCheckLoc73;
        location_t surCheckLoc74;
        location_t surCheckLoc75;
    
        surBaseLoc = theLoc;
        
        // collect first radius
        if(GetNeighbor(surBaseLoc, 3, surCheckLoc00)) {
            MOD_SurroundingTiles[0] = surCheckLoc00;
        }
        if(GetNeighbor(surBaseLoc, 0, surCheckLoc01)) {
            MOD_SurroundingTiles[1] = surCheckLoc01;
        }
        if(GetNeighbor(surBaseLoc, 1, surCheckLoc02)) {
            MOD_SurroundingTiles[2] = surCheckLoc02;
        }
        if(GetNeighbor(surBaseLoc, 2, surCheckLoc03)) {
            MOD_SurroundingTiles[3] = surCheckLoc03;
        }
        if(GetNeighbor(surBaseLoc, 4, surCheckLoc04)) {
            MOD_SurroundingTiles[4] = surCheckLoc04;
        }
        if(GetNeighbor(surBaseLoc, 7, surCheckLoc05)) {
            MOD_SurroundingTiles[5] = surCheckLoc05;
        }
        if(GetNeighbor(surBaseLoc, 6, surCheckLoc06)) {
            MOD_SurroundingTiles[6] = surCheckLoc06;
        }
        if(GetNeighbor(surBaseLoc, 5, surCheckLoc07)) {
            MOD_SurroundingTiles[7] = surCheckLoc07;
        }
        // collect second radius
        if(GetNeighbor(surCheckLoc00, 0, surCheckLoc08)) {
            MOD_SurroundingTiles[8] = surCheckLoc08;
        }
        if(GetNeighbor(surCheckLoc01, 0, surCheckLoc09)) {
            MOD_SurroundingTiles[9] = surCheckLoc09;
        }
        if(GetNeighbor(surCheckLoc02, 0, surCheckLoc10)) {
            MOD_SurroundingTiles[10] = surCheckLoc10;
        }
        if(GetNeighbor(surCheckLoc02, 2, surCheckLoc11)) {
            MOD_SurroundingTiles[11] = surCheckLoc11;
        }
        if(GetNeighbor(surCheckLoc03, 2, surCheckLoc12)) {
            MOD_SurroundingTiles[12] = surCheckLoc12;
        }
        if(GetNeighbor(surCheckLoc04, 2, surCheckLoc13)) {
            MOD_SurroundingTiles[13] = surCheckLoc13;
        }
        if(GetNeighbor(surCheckLoc04, 7, surCheckLoc14)) {
            MOD_SurroundingTiles[14] = surCheckLoc14;
        }
        if(GetNeighbor(surCheckLoc05, 7, surCheckLoc15)) {
            MOD_SurroundingTiles[15] = surCheckLoc15;
        }
        if(GetNeighbor(surCheckLoc06, 7, surCheckLoc16)) {
            MOD_SurroundingTiles[16] = surCheckLoc16;
        }
        if(GetNeighbor(surCheckLoc06, 5, surCheckLoc17)) {
            MOD_SurroundingTiles[17] = surCheckLoc17;
        }
        if(GetNeighbor(surCheckLoc07, 5, surCheckLoc18)) {
            MOD_SurroundingTiles[18] = surCheckLoc18;
        }
        if(GetNeighbor(surCheckLoc00, 5, surCheckLoc19)) {
            MOD_SurroundingTiles[19] = surCheckLoc19;
        }
        // collect third radius
        if(GetNeighbor(surCheckLoc08, 3, surCheckLoc20)) {
            MOD_SurroundingTiles[20] = surCheckLoc20;
        }
        if(GetNeighbor(surCheckLoc08, 0, surCheckLoc21)) {
            MOD_SurroundingTiles[21] = surCheckLoc21;
        }
        if(GetNeighbor(surCheckLoc09, 0, surCheckLoc22)) {
            MOD_SurroundingTiles[22] = surCheckLoc22;
        }
        if(GetNeighbor(surCheckLoc10, 0, surCheckLoc23)) {
            MOD_SurroundingTiles[23] = surCheckLoc23;
        }
        if(GetNeighbor(surCheckLoc10, 1, surCheckLoc24)) {
            MOD_SurroundingTiles[24] = surCheckLoc24;
        }
        if(GetNeighbor(surCheckLoc10, 2, surCheckLoc25)) {
            MOD_SurroundingTiles[25] = surCheckLoc25;
        }
        if(GetNeighbor(surCheckLoc11, 1, surCheckLoc26)) {
            MOD_SurroundingTiles[26] = surCheckLoc26;
        }
        if(GetNeighbor(surCheckLoc11, 2, surCheckLoc27)) {
            MOD_SurroundingTiles[27] = surCheckLoc27;
        }
        if(GetNeighbor(surCheckLoc12, 2, surCheckLoc28)) {
            MOD_SurroundingTiles[28] = surCheckLoc28;
        }
        if(GetNeighbor(surCheckLoc13, 2, surCheckLoc29)) {
            MOD_SurroundingTiles[29] = surCheckLoc29;
        }
        if(GetNeighbor(surCheckLoc13, 4, surCheckLoc30)) {
            MOD_SurroundingTiles[30] = surCheckLoc30;
        }
        if(GetNeighbor(surCheckLoc13, 7, surCheckLoc31)) {
            MOD_SurroundingTiles[31] = surCheckLoc31;
        }
        if(GetNeighbor(surCheckLoc14, 4, surCheckLoc32)) {
            MOD_SurroundingTiles[32] = surCheckLoc32;
        }
        if(GetNeighbor(surCheckLoc14, 7, surCheckLoc33)) {
            MOD_SurroundingTiles[33] = surCheckLoc33;
        }
        if(GetNeighbor(surCheckLoc15, 7, surCheckLoc34)) {
            MOD_SurroundingTiles[34] = surCheckLoc34;
        }
        if(GetNeighbor(surCheckLoc16, 7, surCheckLoc35)) {
            MOD_SurroundingTiles[35] = surCheckLoc35;
        }
        if(GetNeighbor(surCheckLoc16, 6, surCheckLoc36)) {
            MOD_SurroundingTiles[36] = surCheckLoc36;
        }
        if(GetNeighbor(surCheckLoc16, 5, surCheckLoc37)) {
            MOD_SurroundingTiles[37] = surCheckLoc37;
        }
        if(GetNeighbor(surCheckLoc17, 6, surCheckLoc38)) {
            MOD_SurroundingTiles[38] = surCheckLoc38;
        }
        if(GetNeighbor(surCheckLoc17, 5, surCheckLoc39)) {
            MOD_SurroundingTiles[39] = surCheckLoc39;
        }
        if(GetNeighbor(surCheckLoc18, 5, surCheckLoc40)) {
            MOD_SurroundingTiles[40] = surCheckLoc40;
        }
        if(GetNeighbor(surCheckLoc19, 5, surCheckLoc41)) {
            MOD_SurroundingTiles[41] = surCheckLoc41;
        }
        if(GetNeighbor(surCheckLoc19, 3, surCheckLoc42)) {
            MOD_SurroundingTiles[42] = surCheckLoc42;
        }
        if(GetNeighbor(surCheckLoc19, 0, surCheckLoc43)) {
            MOD_SurroundingTiles[43] = surCheckLoc43;
        }
        // collect fourth radius
        if(GetNeighbor(surCheckLoc20, 3, surCheckLoc44)) {
            MOD_SurroundingTiles[44] = surCheckLoc44;
        }
        if(GetNeighbor(surCheckLoc20, 0, surCheckLoc45)) {
            MOD_SurroundingTiles[45] = surCheckLoc45;
        }
        if(GetNeighbor(surCheckLoc21, 0, surCheckLoc46)) {
            MOD_SurroundingTiles[46] = surCheckLoc46;
        }
        if(GetNeighbor(surCheckLoc22, 0, surCheckLoc47)) {
            MOD_SurroundingTiles[47] = surCheckLoc47;
        }
        if(GetNeighbor(surCheckLoc23, 0, surCheckLoc48)) {
            MOD_SurroundingTiles[48] = surCheckLoc48;
        }
        if(GetNeighbor(surCheckLoc24, 0, surCheckLoc49)) {
            MOD_SurroundingTiles[49] = surCheckLoc49;
        }
        if(GetNeighbor(surCheckLoc24, 1, surCheckLoc50)) {
            MOD_SurroundingTiles[50] = surCheckLoc50;
        }
        if(GetNeighbor(surCheckLoc24, 2, surCheckLoc51)) {
            MOD_SurroundingTiles[51] = surCheckLoc51;
        }
        if(GetNeighbor(surCheckLoc26, 1, surCheckLoc52)) {
            MOD_SurroundingTiles[52] = surCheckLoc52;
        }
        if(GetNeighbor(surCheckLoc26, 2, surCheckLoc53)) {
            MOD_SurroundingTiles[53] = surCheckLoc53;
        }
        if(GetNeighbor(surCheckLoc27, 2, surCheckLoc54)) {
            MOD_SurroundingTiles[54] = surCheckLoc54;
        }
        if(GetNeighbor(surCheckLoc28, 2, surCheckLoc55)) {
            MOD_SurroundingTiles[55] = surCheckLoc55;
        }
        if(GetNeighbor(surCheckLoc29, 2, surCheckLoc56)) {
            MOD_SurroundingTiles[56] = surCheckLoc56;
        }
        if(GetNeighbor(surCheckLoc30, 2, surCheckLoc57)) {
            MOD_SurroundingTiles[57] = surCheckLoc57;
        }
        if(GetNeighbor(surCheckLoc30, 4, surCheckLoc58)) {
            MOD_SurroundingTiles[58] = surCheckLoc58;
        }
        if(GetNeighbor(surCheckLoc30, 7, surCheckLoc59)) {
            MOD_SurroundingTiles[58] = surCheckLoc59;
        }
        if(GetNeighbor(surCheckLoc32, 4, surCheckLoc60)) {
            MOD_SurroundingTiles[60] = surCheckLoc60;
        }
        if(GetNeighbor(surCheckLoc32, 7, surCheckLoc61)) {
            MOD_SurroundingTiles[61] = surCheckLoc61;
        }
        if(GetNeighbor(surCheckLoc33, 7, surCheckLoc62)) {
            MOD_SurroundingTiles[62] = surCheckLoc62;
        }
        if(GetNeighbor(surCheckLoc34, 7, surCheckLoc63)) {
            MOD_SurroundingTiles[63] = surCheckLoc63;
        }
        if(GetNeighbor(surCheckLoc35, 7, surCheckLoc64)) {
            MOD_SurroundingTiles[64] = surCheckLoc64;
        }
        if(GetNeighbor(surCheckLoc36, 7, surCheckLoc65)) {
            MOD_SurroundingTiles[65] = surCheckLoc65;
        }
        if(GetNeighbor(surCheckLoc36, 6, surCheckLoc66)) {
            MOD_SurroundingTiles[66] = surCheckLoc66;
        }
        if(GetNeighbor(surCheckLoc36, 5, surCheckLoc67)) {
            MOD_SurroundingTiles[67] = surCheckLoc67;
        }
        if(GetNeighbor(surCheckLoc38, 6, surCheckLoc68)) {
            MOD_SurroundingTiles[68] = surCheckLoc68;
        }
        if(GetNeighbor(surCheckLoc38, 5, surCheckLoc69)) {
            MOD_SurroundingTiles[69] = surCheckLoc69;
        }
        if(GetNeighbor(surCheckLoc39, 5, surCheckLoc70)) {
            MOD_SurroundingTiles[70] = surCheckLoc70;
        }
        if(GetNeighbor(surCheckLoc40, 5, surCheckLoc71)) {
            MOD_SurroundingTiles[71] = surCheckLoc71;
        }
        if(GetNeighbor(surCheckLoc41, 5, surCheckLoc72)) {
            MOD_SurroundingTiles[72] = surCheckLoc72;
        }
        if(GetNeighbor(surCheckLoc42, 5, surCheckLoc73)) {
            MOD_SurroundingTiles[73] = surCheckLoc73;
        }
        if(GetNeighbor(surCheckLoc42, 3, surCheckLoc74)) {
            MOD_SurroundingTiles[74] = surCheckLoc74;
        }
        if(GetNeighbor(surCheckLoc42, 0, surCheckLoc75)) {
            MOD_SurroundingTiles[75] = surCheckLoc75;
        }
    }​ 
    

    And here's an example for the usage of this function. We want to know if there is a good in the range of two city radii around the location in question:

    PHP Code:
    // first we store the entire "city-sized" surroundings into MOD_SurroundingTiles[]
    GetSurroundings(colsiteLoc);
    // then we search the portion of MOD_SurroundingTiles[]
    // we are interested in: <= 19 means two city radii
    for(colsiteNeighborCount = 0; colsiteNeighborCount <= 19; colsiteNeighborCount = colsiteNeighborCount + 1) {
        colsiteNeighborCheck = MOD_SurroundingTiles[colsiteNeighborCount];
        // aaand checkit!
        if(HasGood(colsiteNeighborCheck) > -1) {
                    colsiteTmpScore = colsiteTmpScore + 70;
        }
    }​ 
    

    I am pretty sure that someone with better mathematical skills and imagination could have done this in a much shorter way (and actually it has been done by others for similar purposes). But hey: It works -- and although it's not exactly "elegant" to the human eye it's not "long" in terms of SLIC-execution. And (using the "Tile Indices" memory card ) you may pick any portion of surrounding tiles from MOD_SurroundingTiles[] you are interested in -- so it may be useable for very special situations (where you e.g. only want to examine the "north" and "south" tiles of the second ring -- which would be 8-10 and 14-16 -- or something like that ...).

    However, in the hopes this might be helpful for someone,
    Cheers Bert
    The modding knowledgebase: CTP2 Bureau (with CTP2 AE Modding Wiki). Modern Times Mod (work in progress): MoT-Mod for CTP2.

    Comment

    Working...
    X