summaryrefslogtreecommitdiffstats
path: root/game/color.go
blob: 7cd7bf7c1a25ab7c0b3025aae2faaa0f31ff1895 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package game

import "fmt"

func (ctx *Context) HasColorMonopoly(playerID PlayerID, targetGroup ColorGroup) bool {
	var ownedCount int32
	for _, prop := range ctx.Properties.Owners {
		ownerID := prop.OwnerID

		if ownerID != playerID {
			continue
		}

		spaceID := prop.SpaceID
		space := BoardSpaces[spaceID.Index()]

		propType := space.PropertyType
		if propType != TypeColor {
			continue
		}

		colorID := space.SubIndexID
		if ColorProperties[colorID].GroupID != targetGroup {
			continue
		}

		// the property belongs to player, is a color property and has the right color
		ownedCount++
	}

	return ownedCount == ColorGroupSizes[targetGroup]
}

func (ctx *Context) ProcessOwnedColors() {
	for {
		oCV, done := QueuePop(&ctx.Visitors.Color)
		if done {
			break
		}

		visitorID := oCV.VisitorID
		ownerID := oCV.OwnerID
		colorID := oCV.ColorID

		prop := ColorProperties[colorID]
		prices := ColorPropertyRents[colorID]

		ctx.Turn.Log = append(ctx.Turn.Log, fmt.Sprintf(LogLandColor, prop.Name))

		var rent int32 = prices[prop.Houses]

		if prop.Houses == 0 && ctx.HasColorMonopoly(ownerID, prop.GroupID) {
			rent *= 2
		}

		ctx.AdjustPlayerMoney(visitorID, -rent)
		ctx.AdjustPlayerMoney(ownerID, rent)
	}
}