Skip to content

Commit

Permalink
MapEd objects brush: added 3 more tree age types, refactoring and sim…
Browse files Browse the repository at this point in the history
…plification
  • Loading branch information
reyandme committed Apr 18, 2021
1 parent a0297d5 commit 76896f2
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 229 deletions.
10 changes: 8 additions & 2 deletions KM_TextIDs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,18 @@ TX_MAPED_OBJECTS_BRUSH_DENSITY_HINT = 1482; //Objects / forest density
TX_MAPED_OBJECTS_BRUSH_AGE = 1483; //Forest age
TX_MAPED_OBJECTS_BRUSH_CLEAN = 1484; //Cleaning brush, removes all objects
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL = 1485; //All
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_YOUNG = 1486; //Young
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_MEDIUM = 1487; //Medium
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_YOUNG = 1486; //1
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_MEDIUM = 1487; //2
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_BIG = 1506; //3
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_STOMP = 1508; //Stomp
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL_BUT_STOMP = 1510; //All-
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_RDY_2CHOP = 1488; //Chop
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL_HINT = 1489; //All ages
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_YOUNG_HINT = 1490; //Young trees
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_MEDIUM_HINT = 1491; //Medium trees
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_BIG_HINT = 1507; //Big trees
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_STOMP_HINT = 1509; //Stomps
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL_BUT_STOMP_HINT = 1511; //All ages, except stomps
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_RDY_2CHOP_HINT = 1492; //Trees ready to chop
TX_MAPED_OBJECTS_BRUSH_OVERRIDE_OBJECTS = 1503; //Override Objects
TX_MAPED_OBJECTS_BRUSH_OVERRIDE_OBJECTS_HINT = 1504; //Objects will be replaced by other objects or deleted
Expand Down
8 changes: 7 additions & 1 deletion data/text/text.eng.libx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
0:Sawmill
0:Sawmill
1:Iron smithy
2:Weapon smithy
3:Coal mine
Expand Down Expand Up @@ -1453,3 +1453,9 @@
1503:Override Objects
1504:Objects will be replaced by other objects or deleted
1505:Gradient mask - use automatically created transitions
1506:Big
1507:Big trees
1508:Stomps
1509:Stomps
1510:All-
1511:All ages, except stomps
8 changes: 7 additions & 1 deletion data/text/text.rus.libx
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@
1485:Все
1486:Молод.
1487:Средн.
1488:Макс.
1488:Макс
1489:Все возраста
1490:Молодые деревья
1491:Деревья среднего возраста
Expand All @@ -1453,3 +1453,9 @@
1503:Перезаписывать объекты
1504:Объекты могут быть заменены на другие или удалены
1505:Градиентная маска - используются автоматически генерируемые тайлы для переходов между разными типами ландшафта
1506:Больш.
1507:Большие деревья
1508:Пни
1509:Пеньки
1510:Все-
1511:Все возраста, кроме пеньков
47 changes: 34 additions & 13 deletions src/gui/pages_maped/terrain/KM_GUIMapEdTerrainObjects.pas
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ implementation
KM_ResTypes, KM_TerrainTypes;

type
TKMObjBrushForestAge = (faAll, faYoung, faMedium, faChop);
TKMObjBrushForestAge = (faAll, faAllButStomps, faYoung, faMedium, faBig, faChop, faStomp);

const
OBJECTS_PALETTE_MAX_COLS_CNT = 17;
Expand All @@ -113,9 +113,37 @@ implementation
OBJECT_MAX_DENSITY = 30;


FOREST_AGE_THUMB_TX: array[TKMObjBrushForestAge] of Integer = (TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL_BUT_STOMP,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_YOUNG,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_MEDIUM,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_BIG,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_RDY_2CHOP,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_STOMP);

FOREST_AGE_HINT_TX: array[TKMObjBrushForestAge] of Integer = (TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL_HINT,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL_BUT_STOMP_HINT,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_YOUNG_HINT,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_MEDIUM_HINT,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_BIG_HINT,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_RDY_2CHOP_HINT,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_STOMP_HINT);


{ TKMMapEdTerrainObjects }
constructor TKMMapEdTerrainObjects.Create(aParent: TKMPanel; aHideAllPages: TEvent);

function GetForestAgeThumbWidth(aFont: TKMFont): Integer;
var
BFA: TKMObjBrushForestAge;
begin
Result := 0;
for BFA := Low(FOREST_AGE_THUMB_TX) to High(FOREST_AGE_THUMB_TX) do
Result := Max(Result, gRes.Fonts[aFont].GetTextSize(gResTexts[FOREST_AGE_THUMB_TX[BFA]]).X);

Inc(Result, TKMTrackBar.THUMB_WIDTH_ADD);
end;

var
top: Integer;

Expand All @@ -131,6 +159,7 @@ constructor TKMMapEdTerrainObjects.Create(aParent: TKMPanel; aHideAllPages: TEve
//For brushes
rxIndex, K: Integer;
objectsHint: String;

begin
inherited Create;

Expand Down Expand Up @@ -332,7 +361,10 @@ constructor TKMMapEdTerrainObjects.Create(aParent: TKMPanel; aHideAllPages: TEve
ForestAge.OnChange := ObjectsBrushChange;
ForestAge.ThumbText := gResTexts[TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL];
ForestAge.Hint := GetHintWHotKey(TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL_HINT, gResTexts[TX_KEY_SHIFT_MOUSEWHEEL]);
ForestAge.AutoThumbWidth := True; // Auto calc thumb width

ForestAge.FixedThumbWidth := True;
ForestAge.ThumbWidth := GetForestAgeThumbWidth(ForestAge.Font);
// ForestAge.AutoThumbWidth := True; // Auto calc thumb width

Label_ForestAge := TKMLabel.Create(Panel_Objects, 9, NextTop(20) - 8, Panel_Objects.Width - 18, 20,
gResTexts[TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL_HINT], fntGrey, taRight);
Expand Down Expand Up @@ -607,17 +639,6 @@ procedure TKMMapEdTerrainObjects.ObjPalette_ClickShift(Sender: TObject; Shift: T


procedure TKMMapEdTerrainObjects.ObjectsBrushChange(Sender: TObject);
const
FOREST_AGE_THUMB_TX: array[TKMObjBrushForestAge] of Integer = (TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_YOUNG,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_MEDIUM,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_RDY_2CHOP);

FOREST_AGE_HINT_TX: array[TKMObjBrushForestAge] of Integer = (TX_MAPED_OBJECTS_BRUSH_TREES_AGE_ALL_HINT,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_YOUNG_HINT,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_MEDIUM_HINT,
TX_MAPED_OBJECTS_BRUSH_TREES_AGE_RDY_2CHOP_HINT);

var
I, treeAgeHintTX: Integer;
begin
Expand Down
20 changes: 15 additions & 5 deletions src/terrain/KM_Terrain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ TKMTerrain = class
Boolean; out FishPoint: TKMPointDir): Boolean;
function FindBestTreeType(const aLoc: TKMPoint): TKMTreeType;
function CanFindFishingWater(const aLoc: TKMPoint; aRadius: Integer): Boolean;

function ChooseTreeToPlant(const aLoc: TKMPoint): Integer;
function ChooseTreeToPlace(const aLoc: TKMPoint; aTreeAge: TKMChopableAge; aAlwaysPlaceTree: Boolean): Integer;

procedure GetHouseMarks(const aLoc: TKMPoint; aHouseType: TKMHouseType; aList: TKMPointTagList);

function WaterHasFish(const aLoc: TKMPoint): Boolean;
Expand Down Expand Up @@ -2838,10 +2841,16 @@ function TKMTerrain.FindBestTreeType(const aLoc: TKMPoint): TKMTreeType;


function TKMTerrain.ChooseTreeToPlant(const aLoc: TKMPoint): Integer;
begin
Result := ChooseTreeToPlace(aLoc, caAge1, True); // Default plant age is caAge1
end;


function TKMTerrain.ChooseTreeToPlace(const aLoc: TKMPoint; aTreeAge: TKMChopableAge; aAlwaysPlaceTree: Boolean): Integer;
var
bestTreeType: TKMTreeType;
begin
Result := 0;
Result := OBJ_NONE;
//This function randomly chooses a tree object based on the terrain type. Values matched to KaM, using all soil tiles.
case Land^[aLoc.Y,aLoc.X].BaseLayer.Terrain of
0..3,5,6,8,9,11,13,14,18,19,56,57,66..69,72..74,84..86,93..98,180,188: bestTreeType := ttOnGrass;
Expand All @@ -2852,10 +2861,11 @@ function TKMTerrain.ChooseTreeToPlant(const aLoc: TKMPoint): Integer;
end;

case bestTreeType of
ttNone: Result := ChopableTrees[1 + KaMRandom(Length(ChopableTrees), 'TKMTerrain.ChooseTreeToPlant 4'), caAge1]; //If it isn't one of those soil types then choose a random tree
ttOnGrass: Result := ChopableTrees[1 + KaMRandom(7, 'TKMTerrain.ChooseTreeToPlant'), caAge1]; //Grass (oaks, etc.)
ttOnYellowGrass: Result := ChopableTrees[7 + KaMRandom(2, 'TKMTerrain.ChooseTreeToPlant 2'), caAge1]; //Yellow dirt
ttOnDirt: Result := ChopableTrees[9 + KaMRandom(5, 'TKMTerrain.ChooseTreeToPlant 3'), caAge1]; //Brown dirt (pine trees)
ttNone: if aAlwaysPlaceTree then
Result := ChopableTrees[1 + KaMRandom(Length(ChopableTrees), 'TKMTerrain.ChooseTreeToPlant 4'), aTreeAge]; //If it isn't one of those soil types then choose a random tree
ttOnGrass: Result := ChopableTrees[1 + KaMRandom(7, 'TKMTerrain.ChooseTreeToPlant'), aTreeAge]; //Grass (oaks, etc.)
ttOnYellowGrass: Result := ChopableTrees[7 + KaMRandom(2, 'TKMTerrain.ChooseTreeToPlant 2'), aTreeAge]; //Yellow dirt
ttOnDirt: Result := ChopableTrees[9 + KaMRandom(5, 'TKMTerrain.ChooseTreeToPlant 3'), aTreeAge]; //Brown dirt (pine trees)
end;
end;

Expand Down
Loading

0 comments on commit 76896f2

Please sign in to comment.