-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.go
More file actions
278 lines (257 loc) · 8.71 KB
/
board.go
File metadata and controls
278 lines (257 loc) · 8.71 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
package mbg
import "math/rand"
// res: 0: 正常; 1: 减为零; 2: 加满
func (c * City) ChangeHP (dhp float32) (real_dhp float32, res int) {
php := c.hp + dhp
if php < 1 {
real_dhp = - c.hp
res = 1
} else if php >= c.hpmax {
real_dhp = c.hpmax - c.hp
res = 2
} else {
real_dhp = dhp
res = 0
}
c.hp += real_dhp
if c.hp < 1 {c.hp = 0}
return
}
func (c * City) GetHPPlus (d * Driver) float32 {
var hpplus float32
if c.mayor == -1 {
hpplus = 0
} else {
hpplus = d.people[c.mayor].GetProp(Zheng) * HPPLUS_SCALE
}
return hpplus
}
func (c * City) GetEarn (d * Driver) float32 {
var mplus, scale, value float32
if c.treasurer == -1 {
value = MIN_EARN
} else {
if d.people[c.treasurer].lst != 0 {
value = MIN_EARN
} else {
value = d.people[c.treasurer].GetProp(Jing)
if value < MIN_EARN {
value = MIN_EARN
}
}
}
scale = 1.5 + float32(c.scope) * 0.5 + c.fengshui
mplus = value * scale
return mplus
}
// 研发回合结算
func (d * Driver) RoundInst (iind int) {
inst := &(d.insts[iind])
for i := 0; i < d.nrole; i ++ {
r := &(d.roles[i])
if inst.mos[i] != -1 {
pind := inst.mos[i]
study_item := inst.on_study[i]
p := &(d.people[pind])
value := p.GetProp (Mou)
if p.lst == 0 {
old_ip := inst.point[i]
inst.point[i] -= value * STUDY_SCALE
if inst.point[i] <= 0 {
r.tech.SetLabel (inst.on_study[i], true)
inst.point[i] = 0
inst.on_study[i] = -1
inst.mos[i] = -1
d.oi[i].NoteFinishStudy (iind, pind, study_item)
d.POutInst (pind, true)
}
real_dm, _ := r.ChangeMoney (inst.point[i] - old_ip)
d.oi[i].NotePayInst (real_dm)
} else {
d.oi[i].NoteLYStudy (iind, pind)
}
}
}
}
// 训练回合结算
func (d * Driver) RoundTrain (tind int) {
train := &(d.trains[tind])
for i := 0; i < d.nrole; i ++ {
if train.mos[i] != -1 {
pind := train.mos[i]
p := &(d.people[pind])
if p.lst == 0 {
train.round[i] --
if train.round[i] <= 0 {
train.mos[i] = -1
train.round[i] = 0
value := float32(rand.Intn (TRAIN_PLUS) + 1)
if p.prop[train.item] + value > 100 {value = 100 - p.prop[train.item]}
p.prop[train.item] += value
d.oi[i].NoteFinishTrain (pind, train.item, value)
d.POutTrain (pind, true)
}
} else {
d.oi[i].NoteLYTrain (tind, pind)
}
}
}
}
// 城市回合结算
func (d * Driver) RoundCity (cind int) {
c := &(d.cities[cind])
c.ChangeHP (c.hpmax * DEF_PLUS_SCALE)
if c.mayor != -1 {
if d.people[c.mayor].lst != 0 {
if c.role != -1 { d.oi[c.role].NoteLYMayor (c.mayor, cind) }
} else {
hplus := d.people[c.mayor].GetProp(Zheng)
for _, pind := range c.mos.GetAllLabel() {
d.people[pind].ChangeHP (hplus)
}
if c.role != -1 { d.oi[c.role].NoteCityRecover(cind, hplus) }
}
}
if c.role != -1 {
if c.treasurer != -1 && d.people[c.treasurer].lst != 0 {
d.oi[c.role].NoteLYTreasurer (c.treasurer, cind)
}
mplus := c.GetEarn (d)
d.roles[c.role].ChangeMoney (mplus)
d.oi[c.role].NoteCityEarn (cind, mplus)
}
// 重置风水
if d.turn % FENGSHUI_ROUND == 0 {
c.fengshui = rand.Float32() * 0.5
}
}
func (d * Driver) CityOccupy (rind int, cind int) {
c := &(d.cities[cind])
if c.role != -1 {return}
splist := d.roles[rind].mos.GetAllLabel()
mos := d.oi[rind].SelCityMos(splist, cind)
if len (mos) == 0 {
d.oi[rind].OccuCityFail (cind)
} else {
c.role = rind
d.roles[rind].mcs.SetLabel (cind, true)
d.uv.NoteRoleOccupyCity (rind, cind)
for _, i := range mos {
d.PInCity (splist[i], cind, false)
}
splist := c.mos.GetAllLabel()
mayor := d.oi[rind].SelMayor (cind, splist, c.mayor, c.treasurer)
if mayor != -1 {
d.PAsMayer(splist[mayor], true)
}
splist = c.mos.GetAllLabel()
trea := d.oi[rind].SelTreasurer (cind, splist, c.mayor, c.treasurer)
if trea != -1 {
d.PAsTreasurer(splist[trea], true)
}
}
}
func (d * Driver) CityDrop (rind int, cind int) {
r := &(d.roles[rind])
c := &(d.cities[cind])
if c.role != rind {return}
for _, pind := range c.mos.GetAllLabel() {
d.POutCity (pind, false)
}
r.mcs.SetLabel (cind, false)
c.role = -1
d.uv.NoteRoleDropCity (rind, cind)
}
func (d * Driver) CityAction (rind int, cind int) {
r := &(d.roles[rind])
c := &(d.cities[cind])
if c.role == rind {
tax := c.GetEarn(d) * OWN_TAX_SCALE
r.ChangeMoney (tax)
d.uv.NoteCollectTax (rind, cind, tax)
return
}
if c.role == -1 {
if d.oi[rind].IsOccuCity(cind) { d.CityOccupy (rind, cind) }
} else {
tax := c.GetEarn(d) * TAX_SCALE
r.ChangeMoney (- tax)
d.uv.NotePayTax (rind, c.role, cind, tax)
if r.ast == c.role {
d.oi[rind].SkipBattleByAlign (c.role)
return
}
bs := d.oi[rind].IsAttackCity(cind)
if bs == -1 {
if r.ast == -2 {
d.oi[rind].ForceBattle (c.role)
bs = 0
}
if d.roles[c.role].ast == -2 {
d.oi[c.role].ForceBattle (rind)
bs = 0
}
}
if bs >= 0 {
bres := d.Battle (rind, -1, c.role, cind, bs)
if bres == 1 {
d.CityDrop (c.role, cind)
d.CityOccupy (rind, cind)
}
}
}
}
func (d * Driver) SaloonAction (rind int) {
r := &(d.roles[rind])
var pind []int
var price []float32
for k := 0; k < 3; k ++ {
nl := d.lpset[k].GetNLabel()
if nl == 0 {continue}
i := d.lpset[k].GetAllLabel()[rand.Intn (nl)]
pind = append (pind, i)
price = append (price, d.people[i].GetPrice())
}
for {
sel_ind := d.oi[rind].SaloonSelPeople (pind[:], price[:])
if sel_ind == -1 {break}
if r.money > price[sel_ind] {
r.ChangeMoney (- price[sel_ind])
d.PJoin(pind[sel_ind], rind, true)
break
} else { d.oi[rind].RecruitFail (pind[sel_ind]) }
}
}
func (d * Driver) InstAction (rind int, iind int) {
r := &(d.roles[rind])
inst := &(d.insts[iind])
if inst.mos[rind] == -1 {
var tl []int
for _, tind := range inst.tech {
if !r.tech.GetLabel (tind) {
tl = append (tl, tind)
}
}
pl := r.mos.GetAllLabel()
sp, st := d.oi[rind].SelStudy (iind, pl, tl)
if sp != -1 && st != -1 {
d.PInInst (pl[sp], iind, tl[st], true)
}
}
}
func (d * Driver) TrainAction (rind int, tind int) {
r := &(d.roles[rind])
train := &(d.trains[tind])
if train.mos[rind] == -1 {
pl := r.mos.GetAllLabel()
sp := d.oi[rind].SelTrain (tind, pl, train.item)
if sp != -1 { d.PInTrain (pl[sp], tind, true) }
}
}
func (d * Driver) ChanceAction (rind int) {
r := &(d.roles[rind])
nc := len (cards)
sc_id := rand.Intn (nc)
r.cards[sc_id] ++
d.uv.NoteGetCard (rind, sc_id)
}