Skip to content

Commit

Permalink
Catch and fix map random terrain problems (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 authored Mar 18, 2024
1 parent 9b53ff4 commit f000f15
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion data/maps/Coastline.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"+": 1,
"-": 50,
"^": 6,
"r": 2,
"o": 2,
"t": 14,
"~": 20
},
Expand Down
2 changes: 1 addition & 1 deletion data/maps/Desert Valley.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"+": 40,
"-": 15,
"^": 1,
"r": 3,
"o": 3,
"t": 4,
"~": 4
},
Expand Down
2 changes: 1 addition & 1 deletion data/maps/Great Plains.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"terrains": {
"-": 250,
"^": 3,
"r": 3,
"o": 3,
"t": 20,
"~": 2
},
Expand Down
2 changes: 1 addition & 1 deletion data/maps/River Delta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"terrains": {
"-": 50,
"^": 4,
"r": 1,
"o": 1,
"t": 12,
"~": 10
},
Expand Down
2 changes: 1 addition & 1 deletion data/maps/River.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"+": 1,
"-": 20,
"^": 4,
"r": 1,
"o": 1,
"t": 6,
"~": 6
},
Expand Down
2 changes: 1 addition & 1 deletion data/maps/Rolling Hills.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"terrains": {
"-": 50,
"^": 20,
"r": 1,
"o": 1,
"t": 20,
"~": 6
},
Expand Down
2 changes: 1 addition & 1 deletion data/maps/Swamp Forest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"terrains": {
"-": 40,
"^": 1,
"r": 1,
"o": 1,
"t": 25,
"~": 6
},
Expand Down
15 changes: 15 additions & 0 deletions game/save/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/mlange-42/arche/ecs"
"github.com/mlange-42/tiny-world/game/comp"
"github.com/mlange-42/tiny-world/game/maps"
"github.com/mlange-42/tiny-world/game/terr"
)

func LoadWorld(world *ecs.World, folder, name string) error {
Expand Down Expand Up @@ -70,6 +71,20 @@ func ParseMap(mapStr string) (maps.Map, error) {
return maps.Map{}, fmt.Errorf("symbols must be single runes. Got '%s'", tStr)
}
sym := rn[0]
t, ok := terr.SymbolToTerrain[sym]
if !ok {
return maps.Map{}, fmt.Errorf("symbol not found: '%s'", tStr)
}
var ter terr.Terrain
if t.LandUse != terr.Air {
ter = t.LandUse
} else {
ter = t.Terrain
}
props := &terr.Properties[ter]
if props.TerrainBits.Contains(terr.CanBuy) || !props.TerrainBits.Contains(terr.CanBuild) {
return maps.Map{}, fmt.Errorf("terrain '%s' ('%s') is not a natural feature", props.Name, tStr)
}
for i := 0; i < cnt; i++ {
terrains = append(terrains, sym)
}
Expand Down

0 comments on commit f000f15

Please sign in to comment.