-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathShipyard.cs
416 lines (362 loc) · 8.92 KB
/
Shipyard.cs
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
408
409
410
411
412
413
414
415
416
/*******************************************************************************
*
* Space Trader for Windows 2.01
*
* Copyright (C) 2008 Jay French, All Rights Reserved
*
* Additional coding by David Pierron
* Original coding by Pieter Spronck, Sam Anderson, Samuel Goldstein, Matt Lee
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* If you'd like a copy of the GNU General Public License, go to
* http://www.gnu.org/copyleft/gpl.html.
*
* You can contact the author at [email protected]
*
******************************************************************************/
using System;
using System.Collections;
namespace Fryz.Apps.SpaceTrader
{
/// <summary>
/// Represents a shipyard orbiting a solar system in the universe.
/// In a shipyard, the player can design his own ship and have it constructed, for a fee.
/// </summary>
public class Shipyard
{
#region Constants
public static int[] COST_FUEL = new int[] { 1, 1, 1, 3, 5, 10 };
public static int[] COST_HULL = new int[] { 1, 5, 10, 15, 20, 40 };
public static int[] BASE_FUEL = new int[] { 15, 14, 13, 12, 11, 10 };
public static int[] BASE_HULL = new int[] { 10, 25, 50, 100, 150, 200 };
public static int[] DESIGN_FEE = new int[] { 2000, 5000, 10000, 20000, 40000, 100000 };
public static int[] MAX_UNITS = new int[] { 50, 100, 150, 200, 250, 999 };
public static int[] PER_UNIT_FUEL = new int[] { 3, 2, 1, 1, 1, 1 };
public static int[] PER_UNIT_HULL = new int[] { 35, 30, 25, 20, 15, 10 };
public static int[] PRICE_PER_UNIT = new int[] { 75, 250, 500, 750, 1000, 1200 };
public static int[] UNITS_CREW = new int[] { 20, 20, 20, 20, 20, 20 };
public static int[] UNITS_FUEL = new int[] { 1, 1, 1, 5, 10, 15 };
public static int[] UNITS_GADGET = new int[] { 5, 5, 5, 5, 5, 5 };
public static int[] UNITS_HULL = new int[] { 1, 2, 3, 4, 5, 6 };
public static int[] UNITS_SHIELD = new int[] { 10, 10, 10, 8, 8, 8 };
public static int[] UNITS_WEAPON = new int[] { 15, 15, 15, 10, 10, 10 };
// Fee and Price Per Unit 10% less for the specialty size, and 10% more for sizes more than 1 away
// from the specialty size.
public static int ADJUST_SIZE_DEFAULT = 100;
public static int ADJUST_SIZE_SPECIALTY = 90;
public static int ADJUST_SIZE_WEAKNESS = 110;
// One of the costs will be adjusted based on the shipyard's skill.
public static int ADJUST_SKILL_CREW = 2;
public static int ADJUST_SKILL_FUEL = 2;
public static int ADJUST_SKILL_HULL = 5;
public static int ADJUST_SKILL_SHIELD = 2;
public static int ADJUST_SKILL_WEAPON = 2;
// There is a crowding penalty for coming too close to the maximum. A modest penalty is imposed at
// one level, and a more severe penalty at a higher level.
public static int PENALTY_FIRST_PCT = 80;
public static int PENALTY_FIRST_FEE = 25;
public static int PENALTY_SECOND_PCT = 90;
public static int PENALTY_SECOND_FEE = 75;
#endregion
#region Member Variables
private ShipyardId _id;
private Size _specialtySize;
private ShipyardSkill _skill;
// Internal Variables
private int modCrew = 0;
private int modFuel = 0;
private int modHull = 0;
private int modShield = 0;
private int modWeapon = 0;
#endregion
#region Methods
public Shipyard(ShipyardId id, Size specialtySize, ShipyardSkill skill)
{
_id = id;
_specialtySize = specialtySize;
_skill = skill;
switch (Skill)
{
case ShipyardSkill.CrewQuarters:
modCrew = ADJUST_SKILL_CREW;
break;
case ShipyardSkill.FuelBase:
modFuel = ADJUST_SKILL_FUEL;
break;
case ShipyardSkill.HullPerUnit:
modHull = ADJUST_SKILL_HULL;
break;
case ShipyardSkill.ShieldSlotUnits:
modShield = ADJUST_SKILL_SHIELD;
break;
case ShipyardSkill.WeaponSlotUnits:
modWeapon = ADJUST_SKILL_WEAPON;
break;
}
}
// Calculate the ship's price (worth here, not the price paid), the fuel cost, and the repair cost.
public void CalculateDependantVariables()
{
ShipSpec.Price = BasePrice + PenaltyCost;
ShipSpec.FuelCost = CostFuel;
ShipSpec.RepairCost = CostHull;
}
#endregion
#region Properties
public int AdjustedDesignFee
{
get
{
return DESIGN_FEE[(int)ShipSpec.Size] * CostAdjustment / ADJUST_SIZE_DEFAULT;
}
}
public int AdjustedPenaltyCost
{
get
{
return PenaltyCost * CostAdjustment / ADJUST_SIZE_DEFAULT;
}
}
public int AdjustedPrice
{
get
{
return BasePrice * CostAdjustment / ADJUST_SIZE_DEFAULT;
}
}
public ArrayList AvailableSizes
{
get
{
ArrayList list = new ArrayList(6);
int begin = Math.Max((int)Size.Tiny, (int)SpecialtySize - 2);
int end = Math.Min((int)Size.Gargantuan, (int)SpecialtySize + 2);
for (int index = begin; index <= end; index++)
list.Add((Size)index);
return list;
}
}
public int BaseFuel
{
get
{
return BASE_FUEL[(int)ShipSpec.Size] + modFuel;
}
}
public int BaseHull
{
get
{
return BASE_HULL[(int)ShipSpec.Size];
}
}
public int BasePrice
{
get
{
return UnitsUsed * PricePerUnit;
}
}
public int CostAdjustment
{
get
{
int adjustment;
switch (Math.Abs((int)SpecialtySize - (int)ShipSpec.Size))
{
case 0:
adjustment = ADJUST_SIZE_SPECIALTY;
break;
case 1:
adjustment = ADJUST_SIZE_DEFAULT;
break;
default:
adjustment = ADJUST_SIZE_WEAKNESS;
break;
}
return adjustment;
}
}
public int CostFuel
{
get
{
return COST_FUEL[(int)ShipSpec.Size];
}
}
public int CostHull
{
get
{
return COST_HULL[(int)ShipSpec.Size];
}
}
public string Engineer
{
get
{
return Strings.ShipyardEngineers[(int)Id];
}
}
public ShipyardId Id
{
get
{
return _id;
}
}
public int MaxUnits
{
get
{
return MAX_UNITS[(int)ShipSpec.Size];
}
}
public string Name
{
get
{
return Strings.ShipyardNames[(int)Id];
}
}
public int PenaltyCost
{
get
{
int penalty = 0;
if (PercentOfMaxUnits >= PENALTY_SECOND_PCT)
penalty = PENALTY_SECOND_FEE;
else if (PercentOfMaxUnits >= PENALTY_FIRST_PCT)
penalty = PENALTY_FIRST_FEE;
return BasePrice * penalty / 100;
}
}
public int PercentOfMaxUnits
{
get
{
return UnitsUsed * 100 / MaxUnits;
}
}
public int PerUnitFuel
{
get
{
return PER_UNIT_FUEL[(int)ShipSpec.Size];
}
}
public int PerUnitHull
{
get
{
return PER_UNIT_HULL[(int)ShipSpec.Size] + modHull;
}
}
public int PricePerUnit
{
get
{
return PRICE_PER_UNIT[(int)ShipSpec.Size];
}
}
public ShipSpec ShipSpec
{
get
{
return Consts.ShipSpecs[(int)ShipType.Custom];
}
}
public ShipyardSkill Skill
{
get
{
return _skill;
}
}
public Size SpecialtySize
{
get
{
return _specialtySize;
}
}
public int TotalCost
{
get
{
return AdjustedPrice + AdjustedPenaltyCost + AdjustedDesignFee - TradeIn;
}
}
public int TradeIn
{
get
{
return Game.CurrentGame.Commander.Ship.Worth(false);
}
}
public int UnitsCrew
{
get
{
return UNITS_CREW[(int)ShipSpec.Size] - modCrew;
}
}
public int UnitsFuel
{
get
{
return UNITS_FUEL[(int)ShipSpec.Size];
}
}
public int UnitsGadgets
{
get
{
return UNITS_GADGET[(int)ShipSpec.Size];
}
}
public int UnitsHull
{
get
{
return UNITS_HULL[(int)ShipSpec.Size];
}
}
public int UnitsShields
{
get
{
return UNITS_SHIELD[(int)ShipSpec.Size] - modShield;
}
}
public int UnitsWeapons
{
get
{
return UNITS_WEAPON[(int)ShipSpec.Size] - modWeapon;
}
}
public int UnitsUsed
{
get
{
return ShipSpec.CargoBays +
ShipSpec.CrewQuarters * UnitsCrew +
(int)Math.Ceiling((double)(ShipSpec.FuelTanks - BaseFuel) / PerUnitFuel * UnitsFuel) +
ShipSpec.GadgetSlots * UnitsGadgets +
(ShipSpec.HullStrength - BaseHull) / PerUnitHull * UnitsHull +
ShipSpec.ShieldSlots * UnitsShields +
ShipSpec.WeaponSlots * UnitsWeapons;
}
}
#endregion
}
}