aboutsummaryrefslogtreecommitdiff
path: root/go/game/tile.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-08 17:50:10 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:50:10 +0200
commit45df9bf319d38db916ca983b8c92bb912f5ce9ee (patch)
treed7966002dad4a20bc3ef385bd152554fe278a6df /go/game/tile.go
parenteb10f6f4940ecd09fd7d881fe5e1735ff146f919 (diff)
downloadmuhqs-game-45df9bf319d38db916ca983b8c92bb912f5ce9ee.tar.gz
muhqs-game-45df9bf319d38db916ca983b8c92bb912f5ce9ee.zip
intermediate commit
Diffstat (limited to 'go/game/tile.go')
-rw-r--r--go/game/tile.go37
1 files changed, 34 insertions, 3 deletions
diff --git a/go/game/tile.go b/go/game/tile.go
index 510497f8..ce7518cb 100644
--- a/go/game/tile.go
+++ b/go/game/tile.go
@@ -71,6 +71,15 @@ var TileNames = map[string]TileType{
"store": store,
}
+var farmEffect areaEffect = newGrantFullActionEffect("misc/farmer",
+ func(a Action) ActionResolveFunc {
+ u := a.Source().(*Unit)
+ return func(s *State) {
+ controller := u.Controller()
+ controller.gainResource(3)
+ }
+ }, "gain 3 resource", "farmAction")
+
type Tile struct {
Position Position
Permanent Permanent
@@ -88,8 +97,8 @@ func INVALID_TILE() Tile {
return Tile{Position: INVALID_POSITION()}
}
-func NewTileFromString(t string, pos Position) (Tile, error) {
- tile := strings.ToLower(t)
+func NewTileFromString(raw string, pos Position) (Tile, error) {
+ tile := strings.ToLower(raw)
tokens := strings.Split(tile, " ")
tileType, found := TileNames[tokens[0]]
if !found {
@@ -98,7 +107,14 @@ func NewTileFromString(t string, pos Position) (Tile, error) {
}
}
water := strings.Contains(tile, "water")
- return Tile{Position: pos, Type: tileType, Water: water, Raw: t}, nil
+
+ t := Tile{Position: pos, Type: tileType, Water: water, Raw: raw}
+
+ if tileType == TileTypes.Farm {
+ t.effects = append(t.effects, farmEffect)
+ }
+
+ return t, nil
}
func (t *Tile) IsFree() bool {
@@ -139,6 +155,11 @@ func (t *Tile) OnDiagonal(other *Tile) bool {
func (t *Tile) entering(p Permanent) {
t.Permanent = p
+
+ if t.Type == TileTypes.Store {
+ p.Controller().addKnownStore(t.Position)
+ }
+
for _, effect := range t.effects {
effect.onEntering(p)
}
@@ -153,6 +174,11 @@ func (t *Tile) leaving(p Permanent) {
func (t *Tile) addEffect(effect areaEffect) {
t.effects = append(t.effects, effect)
+
+ // Apply effect to the current Permanent
+ if t.Permanent != nil {
+ effect.onEntering(t.Permanent)
+ }
}
func (t *Tile) removeEffect(effect areaEffect) {
@@ -163,6 +189,11 @@ func (t *Tile) removeEffect(effect areaEffect) {
break
}
}
+
+ // Remove effect from the current Permanent
+ if t.Permanent != nil {
+ effect.onLeaving(t.Permanent)
+ }
}
func (t *Tile) neutralize() {