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

import "fmt"

func (ctx *Context) numRailroadOwned(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 != TypeRailroad {
			continue
		}

		ownedCount++

	}

	return ownedCount
}

func (ctx *Context) ProcessOwnedRailroad() {
	for {
		oRV, done := QueuePop(&ctx.Visitors.Railroad)
		if done {
			break
		}
		visitorID := oRV.VisitorID
		ownerID := oRV.OwnerID
		railroadID := oRV.RailroadID

		ctx.Turn.Log = append(ctx.Turn.Log, fmt.Sprintf(LogLandRailroad, RailroadProperties[railroadID].Name))

		var rent int32 = RailroadRent[ctx.numRailroadOwned(ownerID)]

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

		// reset railroad rent mod after payment
		ctx.Turn.Modifier.RailroadRentMultiplier = 1
	}
}