forked from jwvhewitt/gearhead-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathghguard.pp
207 lines (167 loc) · 6.02 KB
/
ghguard.pp
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
unit ghguard;
{ This unit is meant to handle Shields and External Armor. }
{
GearHead: Arena, a roguelike mecha CRPG
Copyright (C) 2005 Joseph Hewitt
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
The full text of the LGPL can be found in license.txt.
This library 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 Lesser
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
interface
uses gears;
{ *** SHIELD FORMAT *** }
{ G = GG_Shield }
{ S = Shield Type }
{ V = Armor Rating }
{ *** EXARMOR FORMAT *** }
{ G = GG_ExArmor }
{ S = Module Fit }
{ V = Armor Rating }
const
STAT_ShieldBonus = 1; { Bonus to defense roll when using this shield. }
NumShieldType = 2;
GS_PhysicalShield = 0;
GS_EnergyShield = 1;
Function ShieldName( Part: GearPtr ): String;
Function ShieldBaseMass( Part: GearPtr ): Integer;
Function ShieldValue( Part: GearPtr ): LongInt;
Procedure CheckShieldRange( Part: GearPtr );
Function IsLegalShieldSub( Part, Equip: GearPtr ): Boolean;
Function ArmorName( Part: GearPtr ): String;
Function ArmorBaseMass( Part: GearPtr ): Integer;
Function ArmorValue( Part: GearPtr ): LongInt;
Procedure CheckArmorRange( Part: GearPtr );
Function IsLegalArmorSub( Part, Equip: GearPtr ): Boolean;
Function ArmorFitsMaster( Armor,Master: GearPtr ): Boolean;
implementation
uses ghchars,ghmecha,ghmodule,texutil;
Function ShieldName( Part: GearPtr ): String;
{ Return a name for this particular shield. }
begin
if Part^.S = GS_PhysicalShield then begin
ShieldName := 'Class '+BStr( Part^.V ) + ' Shield';
end else begin
ShieldName := 'Class '+BStr( Part^.V ) + ' Beam Shield';
end;
end;
Function ShieldBaseMass( Part: GearPtr ): Integer;
{ Return the weight of this shield. }
{ Regular shields are heavy; Energy shields are almost weightless. }
var
it: Integer;
begin
{ The base weight of a shield is its PV + Bonus. }
{ Easier to defend with shields tend to be larger, so they are heavier. }
if Part^.S = GS_PhysicalShield then begin
it := Part^.V + Part^.Stat[ STAT_ShieldBonus ];
if it < 1 then it := 1;
end else begin
{ Energy shields weigh 1 unit for the emitter. }
it := 1;
end;
ShieldBaseMass := it;
end;
Function ShieldValue( Part: GearPtr ): LongInt;
{ Calculate the value of this shield, ignoring for the moment }
{ its subcomponents. }
var
it: LongInt;
begin
if Part^.S = GS_EnergyShield then it := Part^.V * 75
else it := Part^.V * 25;
{ Modify the cost for the shield's defense bonus. }
if Part^.Stat[ STAT_ShieldBonus ] > 0 then begin
{ +25% per positive point. }
it := it * ( 4 + Part^.Stat[ STAT_ShieldBonus ] ) div 4;
end else if Part^.Stat[ STAT_ShieldBonus ] < 0 then begin
{ -10% per negative point. }
it := it * ( 10 + Part^.Stat[ STAT_ShieldBonus ] ) div 10;
end;
ShieldValue := it;
end;
Procedure CheckShieldRange( Part: GearPtr );
{ Examine this sensor to make sure everything is legal. }
begin
{ Check S - Shield Type }
if Part^.S < 0 then Part^.S := 0
else if Part^.S >= NumShieldType then Part^.S := 0;
{ Check V - Armor Value }
if Part^.V < 1 then Part^.V := 1
else if Part^.V > 10 then Part^.V := 10;
{ Check Stats - Stat 1 = Shield Bonus. }
if Part^.Stat[ STAT_ShieldBonus ] < -5 then Part^.Stat[ STAT_ShieldBonus ] := -5
else if Part^.Stat[ STAT_ShieldBonus ] > 5 then Part^.Stat[ STAT_ShieldBonus ] := 5;
end;
Function IsLegalShieldSub( Part, Equip: GearPtr ): Boolean;
{ TRUE if EQUIP can be installed in the shield, FALSE otherwise. }
begin
if Part^.S = GS_PhysicalShield then begin
if Equip^.G = GG_Weapon then IsLegalShieldSub := True
else IsLegalShieldSub := False;
end else IsLegalShieldSub := False;
end;
Function ArmorName( Part: GearPtr ): String;
{ Return a name for this particular armor. }
begin
ArmorName := 'Class ' + BStr( Part^.V ) + ' ' + CModule[Part^.S].Name + ' Armor';
end;
Function ArmorBaseMass( Part: GearPtr ): Integer;
{ Return the weight of this armor. }
begin
ArmorBaseMass := Part^.V * 2;
end;
Function ArmorValue( Part: GearPtr ): LongInt;
{ Return the cost of this armor. }
begin
ArmorValue := Part^.V * Part^.V * Part^.V * 5 + Part^.V * Part^.V * 10 + Part^.V * 35;
end;
Procedure CheckArmorRange( Part: GearPtr );
{ Examine this sensor to make sure everything is legal. }
begin
{ Check S - Shield Type }
if Part^.S < 1 then Part^.S := GS_Storage
else if Part^.S > NumModule then Part^.S := GS_Storage;
{ Check V - Armor Value }
{ Note that PV-0 armor may represent normal clothing. }
if Part^.V < 0 then Part^.V := 0
else if Part^.V > 10 then Part^.V := 10;
{ Check Stats - No Stats Defined. }
end;
Function IsLegalArmorSub( Part, Equip: GearPtr ): Boolean;
{ Return TRUE if EQUIP can be mounted in PART, FALSE otherwise. }
begin
case Equip^.G of
GG_Weapon: IsLegalArmorSub := True;
GG_MoveSys: IsLegalArmorSub := True;
GG_Electronics: IsLegalArmorSub := True;
else IsLegalArmorSub := False
end;
end;
Function ArmorFitsMaster( Armor,Master: GearPtr ): Boolean;
{ Determine whether or not ARMOR fits MASTER, based upon the }
{ armor's FITS string. }
var
ADesc,MDesc: String;
begin
ADesc := SATTValue( Armor^.SA , 'FITS' );
if Master = Nil then begin
MDesc := '';
end else begin
case Master^.G of
GG_Mecha: MDesc := MechaTraitDesc( Master );
GG_Character: MDesc := NPCTraitDesc( Master );
else MDesc := '';
end;
end;
ArmorFitsMaster := PartMatchesCriteria( MDesc , ADesc );
end;
end.