Skip to content

Commit

Permalink
Codechange: Don't store tree counter in the map array
Browse files Browse the repository at this point in the history
  • Loading branch information
ldpl committed Sep 10, 2022
1 parent 0355299 commit 6c3f351
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 197 deletions.
2 changes: 0 additions & 2 deletions docs/landscape.html
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,6 @@ <h3><a name="Landscape">Landscape</a></h3>
</table>
</li>
<li>m2 bits 5..4: ground density</li>
<li>m2 bits 3..0: update counter, incremented on every periodic processing.<br>
on wraparound the growth status is updated (or, if it's <tt>3</tt>, a random action is taken)</li>
<li>m3 bits 7..0: type of trees:
<table>
<tr>
Expand Down
282 changes: 141 additions & 141 deletions regression/regression/result.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@
abs( 21): 21

--AIBase--
Rand(): -54346916
Rand(): -937374575
Rand(): 823953997
Rand(): -1077739811
Rand(): -1179776610
Rand(): -497449144
RandRange(0): 0
RandRange(0): 0
RandRange(0): 0
RandRange(1): 0
RandRange(1): 0
RandRange(1): 0
RandRange(2): 0
RandRange(2): 1
RandRange(2): 1
RandRange(2): 1
RandRange(1000000): 966676
RandRange(1000000): 289525
RandRange(1000000): 170283
Chance(1, 2): false
RandRange(1000000): 191841
RandRange(1000000): 925095
RandRange(1000000): 99057
Chance(1, 2): true
Chance(1, 2): true
Chance(1, 2): false

Expand Down Expand Up @@ -420,144 +420,144 @@
1098 => 46116
1099 => 46158
Randomize ListDump:
1 => -200078348
2 => -29799264
1000 => 1630721656
1001 => 959306175
1002 => 1527421791
1003 => 1259692483
1004 => -1289244298
1005 => -1572996668
1006 => -2069479746
1007 => -1819131606
1008 => -1007163964
1009 => -1185394870
1010 => -1471365065
1011 => 364354366
1012 => -1478084253
1013 => 405281367
1014 => -11170062
1015 => 156767750
1016 => 1288924796
1017 => 1796884876
1018 => -1947073702
1019 => -1999614238
1020 => -231292809
1021 => 966621566
1022 => -606766557
1023 => -1138727825
1024 => -749544262
1025 => 2004771271
1026 => 686734186
1027 => 923274744
1028 => -1672035149
1029 => -1642064950
1030 => 1363389551
1031 => -559500928
1032 => 1656196991
1033 => 1655354425
1034 => -1027156689
1035 => 1952644328
1036 => 1217870217
1037 => 242274100
1038 => 201816080
1039 => 2127464758
1040 => 446043650
1041 => -319728455
1042 => 204701002
1043 => -571265398
1044 => -1422217131
1045 => -391208397
1046 => -1822628371
1047 => -1499755350
1048 => -1422137641
1049 => 1621693134
1051 => -1428728134
1052 => -147587573
1053 => 681719500
1054 => 1172011190
1055 => -1834344882
1056 => 1157634586
1057 => 1902133676
1058 => -1967780161
1059 => -1618025531
1060 => -810220453
1061 => 1582854921
1062 => -410004643
1063 => 1159917159
1064 => -1377804984
1065 => -738843914
1066 => -1578756103
1067 => -464090986
1068 => 1711504679
1069 => 545330655
1070 => 379462570
1071 => 514511099
1072 => -1813251176
1073 => 1424958266
1074 => -825255131
1075 => 539054595
1076 => -1764192010
1077 => -1243277769
1078 => 2017874281
1079 => -1972353607
1080 => 1879761467
1081 => 1638986560
1082 => -1832287507
1083 => -492411882
1084 => 658940812
1085 => -1044199400
1086 => 1586504918
1087 => -125492611
1088 => -1562883174
1089 => -1013778441
1090 => 1560228607
1091 => -550265689
1092 => 524767105
1093 => -713387661
1094 => 1425927738
1095 => 942653932
1096 => 1233220698
1097 => 1313602368
1098 => -140318584
1099 => 1199179892
1 => 1473447397
2 => -1572091528
1000 => -1461894323
1001 => -1966513355
1002 => -143123078
1003 => 1243503816
1004 => 731361243
1005 => -110249379
1006 => 1652302684
1007 => -1959331369
1008 => -200078348
1009 => -29799264
1010 => 1630721656
1011 => 959306175
1012 => 1527421791
1013 => 1259692483
1014 => -1289244298
1015 => -1572996668
1016 => -2069479746
1017 => -1819131606
1018 => -1007163964
1019 => -1185394870
1020 => -1471365065
1021 => 364354366
1022 => -1478084253
1023 => 405281367
1024 => -11170062
1025 => 156767750
1026 => 1288924796
1027 => 1796884876
1028 => -1947073702
1029 => -1999614238
1030 => -231292809
1031 => 966621566
1032 => -606766557
1033 => -1138727825
1034 => -749544262
1035 => 2004771271
1036 => 686734186
1037 => 923274744
1038 => -1672035149
1039 => -1642064950
1040 => 1363389551
1041 => -559500928
1042 => 1656196991
1043 => 1655354425
1044 => -1027156689
1045 => 1952644328
1046 => 1217870217
1047 => 242274100
1048 => 201816080
1049 => 2127464758
1051 => 446043650
1052 => -319728455
1053 => 204701002
1054 => -571265398
1055 => -1422217131
1056 => -391208397
1057 => -1822628371
1058 => -1499755350
1059 => -1422137641
1060 => 1621693134
1061 => -1428728134
1062 => -147587573
1063 => 681719500
1064 => 1172011190
1065 => -1834344882
1066 => 1157634586
1067 => 1902133676
1068 => -1967780161
1069 => -1618025531
1070 => -810220453
1071 => 1582854921
1072 => -410004643
1073 => 1159917159
1074 => -1377804984
1075 => -738843914
1076 => -1578756103
1077 => -464090986
1078 => 1711504679
1079 => 545330655
1080 => 379462570
1081 => 514511099
1082 => -1813251176
1083 => 1424958266
1084 => -825255131
1085 => 539054595
1086 => -1764192010
1087 => -1243277769
1088 => 2017874281
1089 => -1972353607
1090 => 1879761467
1091 => 1638986560
1092 => -1832287507
1093 => -492411882
1094 => 658940812
1095 => -1044199400
1096 => 1586504918
1097 => -125492611
1098 => -1562883174
1099 => -1013778441
KeepTop(10):
1 => -200078348
2 => -29799264
1000 => 1630721656
1001 => 959306175
1002 => 1527421791
1003 => 1259692483
1004 => -1289244298
1005 => -1572996668
1006 => -2069479746
1007 => -1819131606
1 => 1473447397
2 => -1572091528
1000 => -1461894323
1001 => -1966513355
1002 => -143123078
1003 => 1243503816
1004 => 731361243
1005 => -110249379
1006 => 1652302684
1007 => -1959331369
KeepBottom(8):
1000 => 1630721656
1001 => 959306175
1002 => 1527421791
1003 => 1259692483
1004 => -1289244298
1005 => -1572996668
1006 => -2069479746
1007 => -1819131606
1000 => -1461894323
1001 => -1966513355
1002 => -143123078
1003 => 1243503816
1004 => 731361243
1005 => -110249379
1006 => 1652302684
1007 => -1959331369
RemoveBottom(2):
1000 => 1630721656
1001 => 959306175
1002 => 1527421791
1003 => 1259692483
1004 => -1289244298
1005 => -1572996668
1000 => -1461894323
1001 => -1966513355
1002 => -143123078
1003 => 1243503816
1004 => 731361243
1005 => -110249379
RemoveTop(2):
1002 => 1527421791
1003 => 1259692483
1004 => -1289244298
1005 => -1572996668
1002 => -143123078
1003 => 1243503816
1004 => 731361243
1005 => -110249379
RemoveList({1003, 1004}):
1002 => 1527421791
1005 => -1572996668
1002 => -143123078
1005 => -110249379
KeepList({1003, 1004, 1005}):
1005 => -1572996668
1005 => -110249379
AddList({1005, 4000, 4001, 4002}):
1005 => 1005
4000 => 8000
Expand Down Expand Up @@ -588,7 +588,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
SetName(): false
GetLastErrorString(): ERR_NAME_IS_NOT_UNIQUE
GetName(): Regression
GetPresidentName(): E. McAlpine
GetPresidentName(): D. Watkins
SetPresidentName(): true
GetPresidentName(): Regression AI
GetBankBalance(): 100000
Expand Down
16 changes: 6 additions & 10 deletions src/tree_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ static void PlaceTree(TileIndex tile, uint32 r)
if (ground != TREE_GROUND_SNOW_DESERT && ground != TREE_GROUND_ROUGH_SNOW && ground != TREE_GROUND_SHORE) {
SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 3);
}

/* Set the counter to a random start value */
SetTreeCounter(tile, (TreeGround)GB(r, 24, 4));
}
}

Expand Down Expand Up @@ -707,10 +704,13 @@ static void TileLoop_Trees(TileIndex tile)

AmbientSoundEffect(tile);

uint treeCounter = GetTreeCounter(tile);
/* _tick_couter is incremented by 256 between each call, so ignore lower 8 bits.
* Also, we add tile % 31 to spread the updates evenly over the map,
* where 31 is just some prime number that looks ok. */
uint32 cycle = (uint32)tile % 31 + (_tick_counter >> 8);

/* Handle growth of grass (under trees/on MP_TREES tiles) at every 8th processings, like it's done for grass on MP_CLEAR tiles. */
if ((treeCounter & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) {
if ((cycle & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) {
uint density = GetTreeDensity(tile);
if (density < 3) {
SetTreeGroundDensity(tile, TREE_GROUND_GRASS, density + 1);
Expand All @@ -720,11 +720,7 @@ static void TileLoop_Trees(TileIndex tile)

if (_settings_game.construction.extra_tree_placement == ETP_NO_GROWTH_NO_SPREAD) return;

if (GetTreeCounter(tile) < 15) {
AddTreeCounter(tile, 1);
return;
}
SetTreeCounter(tile, 0);
if ((cycle & 15) < 15) return;

switch (GetTreeGrowth(tile)) {
case 3: // regular sized tree
Expand Down

0 comments on commit 6c3f351

Please sign in to comment.