summaryrefslogtreecommitdiffstats
path: root/game/utility.go
blob: 1b50553c4742bba70d3c272f48f2547f04ea6a14 (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
package game

import "fmt"

func (ctx *Context) NumUtilities(playerID PlayerID) int32 {
	var ownedCount int32 = 0
	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 != TypeUtility {
			continue
		}

		ownedCount++

	}

	return ownedCount
}

func (ctx *Context) ProcessOwnedUtility() {
	for {
		oUV, done := QueuePop(&ctx.Visitors.Utility)
		if done {
			break
		}
		visitorID := oUV.VisitorID
		ownerID := oUV.OwnerID
		utilityID := oUV.UtilityID
		diceRoll := oUV.DiceRoll

		ctx.Turn.Log = append(ctx.Turn.Log, fmt.Sprintf(LogLandUtility, UtilityProperties[utilityID].Name))

		var rent int32 = 0

		if !ctx.Turn.Modifier.UtilityForceRentMultiplier {
			rent = UtilityRentMult[ctx.NumUtilities(ownerID)] * diceRoll
		} else {
			rent = 10 * diceRoll
		}

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

		ctx.Turn.Modifier.UtilityForceRentMultiplier = false
	}
}