-
Notifications
You must be signed in to change notification settings - Fork 1
/
CalcAvailablePassengers.py
executable file
·407 lines (346 loc) · 9.88 KB
/
CalcAvailablePassengers.py
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#!/usr/bin/env python3
import click
import random
import math
import itertools
passenger_rates = [
{
"high": 6000,
"middle": 3000,
"low": 1000
},
{
"high": 12000,
"middle": 6000,
"low": 1200
},
{
"high": 20000,
"middle": 10000,
"low": 1400
},
{
"high": 30000,
"middle": 15000,
"low": 1600
},
{
"high": 40000,
"middle": 20000,
"low": 1800
},
{
"high": 50000,
"middle": 25000,
"low": 2000
}
]
passenger_traffic = {
"agricultural": {
"current": 0,
"destination": 0
},
"asteroid": {
"current": 1,
"destination": -1
},
"barren": {
"current": -5,
"destination": -5
},
"dessert": {
"current": -1,
"destination": -1
},
"fluid oceans": {
"current": 0,
"destination": 0
},
"garden": {
"current": 2,
"destination": 2
},
"high population": {
"current": 0,
"destination": 4
},
"ice-capped": {
"current": 1,
"destination": -1
},
"industrial": {
"current": 2,
"destination": 1
},
"low population": {
"current": 0,
"destination": -4
},
"non-agricultural": {
"current": 0,
"destination": 0
},
"poor": {
"current": -2,
"destination": -1
},
"rich": {
"current": -1,
"destination": 2
},
"water world": {
"current": 0,
"destination": 0
},
"amber zone": {
"current": 2,
"destination": -2
},
"red zone": {
"current": 4,
"destination": -4
},
"no classification": {
"current": 0,
"destination": 0
},
}
availiable_passengers = {
0: {
"low": lambda: 0,
"med": lambda: 0,
"high": lambda: 0
},
1: {
"low": lambda: roll(2, -6),
"med": lambda: roll(1, -6),
"high": lambda: 0
},
2: {
"low": lambda: roll(2),
"med": lambda: roll(1),
"high": lambda: roll(1, -roll(1))
},
3: {
"low": lambda: roll(2),
"med": lambda: roll(2, -roll(1)),
"high": lambda: roll(2, -roll(2))
},
4: {
"low": lambda: roll(3, -6),
"med": lambda: roll(2, -roll(1)),
"high": lambda: roll(2, -roll(1))
},
5: {
"low": lambda: roll(3, -roll(1)),
"med": lambda: roll(3, -roll(2)),
"high": lambda: roll(2, -roll(1))
},
6: {
"low": lambda: roll(3),
"med": lambda: roll(3, -roll(2)),
"high": lambda: roll(3, -roll(2))
},
7: {
"low": lambda: roll(3),
"med": lambda: roll(3, -roll(1)),
"high": lambda: roll(3, -roll(2))
},
8: {
"low": lambda: roll(4),
"med": lambda: roll(3, -roll(1)),
"high": lambda: roll(3, -roll(1))
},
9: {
"low": lambda: roll(4),
"med": lambda: roll(3),
"high": lambda: roll(3, -roll(1))
},
10: {
"low": lambda: roll(5),
"med": lambda: roll(3),
"high": lambda: roll(3, -roll(1))
},
11: {
"low": lambda: roll(5),
"med": lambda: roll(4),
"high": lambda: roll(3)
},
12: {
"low": lambda: roll(6),
"med": lambda: roll(4),
"high": lambda: roll(3)
},
13: {
"low": lambda: roll(6),
"med": lambda: roll(4),
"high": lambda: roll(4)
},
14: {
"low": lambda: roll(7),
"med": lambda: roll(5),
"high": lambda: roll(4)
},
15: {
"low": lambda: roll(8),
"med": lambda: roll(5),
"high": lambda: roll(4)
},
16: {
"low": lambda: roll(9),
"med": lambda: roll(6),
"high": lambda: roll(5)
}
}
def calc_effect(roll):
return roll - 8
def roll(num_dice, mod=0):
s = sum([ random.randint(1,6) for x in range(num_dice) ])
return s + mod
@click.group()
def cli(): pass
@click.command()
@click.option('--distance', default=1)
@click.option('--dm', default=0)
@click.option('--current', default=None, help="The types of the current world, comma separated")
@click.option('--destination', default=None, help="The types of the destination world, comma separated")
@click.option("--staterooms", default=None)
@click.option("--low-berths", default=None)
@click.option("--steward-level", default=0)
def passengers(distance, dm, current, destination, staterooms, low_berths, steward_level):
"""
Helps calculate the number of passengers availiable for ferrying between two planets.
"""
if not current:
click.echo("ERROR: current must be provided. See 'trav passengers --help' for details")
exit()
current = current.lower().replace(", ", ",")
if not destination:
click.echo("ERROR: destination must be provided. See 'trav passengers --help' for details")
exit()
destination = destination.lower().replace(", ", ",")
streetwise_check = roll(2, dm)
click.echo("Streetwise/Carouse Check (2d6 + {0}):".format(dm))
click.echo("|-> Roll:{0}".format(streetwise_check))
effect = calc_effect(streetwise_check)
click.echo("|-> Calculated Effect: {0}".format(effect))
click.echo("")
click.echo("World Modifiers:")
current_mod_total = 0
click.echo("|-> Current:")
for wtype in current.split(","):
current_mod = passenger_traffic[wtype]["current"]
current_mod_total += current_mod
click.echo("| |-> {0}{1}: {2}".format(
wtype[0].upper(),
wtype[1:],
current_mod))
click.echo("| |-> TOTAL: {0}".format(current_mod_total))
click.echo("|")
dest_mod_total = 0
click.echo("|-> Destination:")
for wtype in destination.split(","):
dest_mod = passenger_traffic[wtype]["destination"]
dest_mod_total += dest_mod
click.echo("| |-> {0}{1}: {2}".format(
wtype[0].upper(),
wtype[1:],
dest_mod))
click.echo("| |-> TOTAL: {0}".format(dest_mod_total))
click.echo("")
click.echo("Total Modifiers:")
effect = math.floor(effect/2)
click.echo("|-> Effect Modifier (half of effect): {0}".format(effect))
click.echo("|-> Current World Modifier: {0}".format(current_mod_total))
click.echo("|-> Destination World Modifier: {0}".format(dest_mod_total))
mod = effect + current_mod_total + dest_mod_total
click.echo("|-> TOTAL: {0}".format(dest_mod_total))
# keep mod in sane bounds for availiablity table
mod = mod if mod > 0 else 0
mod = mod if mod <= 16 else 16
avail= availiable_passengers[mod]
high = avail["high"]()
med = avail["med"]()
low = avail["low"]()
# correct for negatives
high = high if high > 0 else 0
med = med if med > 0 else 0
low = low if low > 0 else 0
click.echo("")
click.echo("Availiable Passengers:")
click.echo("|-> High: {0}".format(high))
click.echo("|-> Medium: {0}".format(med))
click.echo("|-> Low Berth: {0}".format(low))
optimize = False
optimized_staterooms = False
optimized_low_berths = False
steward_level += 1 # account for lvl 0 counting as well
rates = passenger_rates[distance - 1]
high_rate = rates["high"]
med_rate = rates["middle"]
low_rate = rates["low"]
if staterooms is not None:
staterooms = int(staterooms)
optimize = True
optimized_staterooms = True
taken = 0
high_taken = 0
med_taken = 0
best_option = {
"high": 0,
"med": 0,
"income": 0
}
for combo in itertools.combinations_with_replacement("hm ", steward_level):
m_count = combo.count("m") * 5
h_count = combo.count("h") * 2
if(m_count > med ): # if m*5 is more than there are, take all availiable
m_count = med
if(h_count > high):
h_count = high
income = (m_count * med_rate) + (h_count * high_rate)
if(best_option["income"] < income):
best_option["income"] = income
best_option["high"] = h_count
best_option["med"] = m_count
high_taken = best_option["high"]
med_taken = best_option["med"]
if low_berths is not None:
low_berths = int(low_berths)
optimize = True
optimized_low_berths = True
low_taken = 0
taken = 0
while(taken < low_berths):
if(low_taken < low):
low_taken += 1
taken += 1
else:
# no more low berths left
break
if optimize:
click.echo("")
click.echo("Passenger Optimization:")
if optimized_staterooms:
high_sum = high_taken * high_rate
click.echo("|-> High Passengers: {0} * {1} = {2} CR".format(
high_taken, high_rate, high_sum ))
med_sum = med_taken * med_rate
click.echo("|-> Medium Passengers: {0} * {1} = {2} CR".format(
med_taken, med_rate, med_sum))
else:
high_sum = 0
med_sum = 0
click.echo("|-> High Passengers: no staterooms availiable")
click.echo("|-> Medium Passengers: no staterooms availiable")
if optimized_low_berths:
low_sum = low_taken * low_rate
click.echo("|-> Low Berth Passengers: {0} * {1} = {2} CR".format(
low_taken, low_rate, low_sum))
else:
low_sum = 0
click.echo("|-> Low Berth Passengers: no low berth pods availiable")
click.echo("|-> TOTAL INCOME: {0} CR".format(low_sum + med_sum + high_sum))
cli.add_command(passengers)
if __name__ == "__main__":
cli()