From f9ab2cfdb25eb3fcd85868a2e375326a9c8b6022 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 15 Feb 2023 13:13:06 +0100 Subject: intermediate commit * fix a lot of target and action bugs * check target selection before adding it to the prompt * use the store view for stores on the map * fix card highlighting in CardGrid * Only prompt for Upkeep-/DiscardActions if appropriate * Add helper for areaEffects granting new FullActions * Add Target() helper selecting the first target to the Action interface * Fix BuyAction and DiscardAction targets * Remember the stores a player has seen --- go/game/tile.go | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'go/game/tile.go') 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() { -- cgit v1.2.3