-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shipyard.cs
245 lines (191 loc) · 9.1 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
/*******************************************************************************
*
* Space Trader for Windows 1.00
*
* Copyright (C) 2016 Keith Banner, All Rights Reserved
*
* Port to Windows by David Pierron & Jay French
* 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 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
// 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 => DESIGN_FEE[(int)ShipSpec.Size] * CostAdjustment / ADJUST_SIZE_DEFAULT;
public int AdjustedPenaltyCost => PenaltyCost * CostAdjustment / ADJUST_SIZE_DEFAULT;
public int AdjustedPrice => 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 => BASE_FUEL[(int)ShipSpec.Size] + modFuel;
public int BaseHull => BASE_HULL[(int)ShipSpec.Size];
public int BasePrice => 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 => COST_FUEL[(int)ShipSpec.Size];
public int CostHull => COST_HULL[(int)ShipSpec.Size];
public string Engineer => Strings.ShipyardEngineers[(int)Id];
public ShipyardId Id { get; }
public int MaxUnits => MAX_UNITS[(int)ShipSpec.Size];
public string Name => 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 => UnitsUsed * 100 / MaxUnits;
public int PerUnitFuel => PER_UNIT_FUEL[(int)ShipSpec.Size];
public int PerUnitHull => PER_UNIT_HULL[(int)ShipSpec.Size] + modHull;
public int PricePerUnit => PRICE_PER_UNIT[(int)ShipSpec.Size];
public ShipSpec ShipSpec => Consts.ShipSpecs[(int)ShipType.Custom];
public ShipyardSkill Skill { get; }
public Size SpecialtySize { get; }
public int TotalCost => AdjustedPrice + AdjustedPenaltyCost + AdjustedDesignFee - TradeIn;
public int TradeIn => Game.CurrentGame.Commander.Ship.Worth(false);
public int UnitsCrew => UNITS_CREW[(int)ShipSpec.Size] - modCrew;
public int UnitsFuel => UNITS_FUEL[(int)ShipSpec.Size];
public int UnitsGadgets => UNITS_GADGET[(int)ShipSpec.Size];
public int UnitsHull => UNITS_HULL[(int)ShipSpec.Size];
public int UnitsShields => UNITS_SHIELD[(int)ShipSpec.Size] - modShield;
public int UnitsWeapons => UNITS_WEAPON[(int)ShipSpec.Size] - modWeapon;
public int UnitsUsed => 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
}
}