-
Notifications
You must be signed in to change notification settings - Fork 18
/
ghmodule.pp
445 lines (379 loc) · 12.4 KB
/
ghmodule.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
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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
unit ghmodule;
{This unit holds modules- arms, legs, pods... body}
{parts, basically. Both mecha and living creatures}
{use the same module descriptions.}
{
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,ghmecha;
Type
ModuleDesc = Record
name: String;
MHP: Byte; {Module Hit Points}
end;
Const
NumModule = 8;
GS_Body = 1;
GS_Head = 2;
GS_Arm = 3;
GS_Leg = 4;
GS_Wing = 5;
GS_Tail = 6;
GS_Turret = 7;
GS_Storage = 8;
STAT_Armor = 1;
STAT_Resizable = 2; { if =1, part resizes on BODY change. }
STAT_InfoTier = 3; { if in range 1..3, sets part's location in module display }
{ This array tells which modules are usable by which forms. }
{ Some systems ( movers, sensors, cockpits ) will function no matter where they are mounted. }
{ Others ( weapons, shields, hands ) will not function if placed in a bad module. }
FORMxMODULE: Array [0..NumForm-1, 1..NumModule] of Boolean = (
{ Body Head Arm Leg Wing Tail Turret Storage }
{Battroid} ( True, True, True, True, True, True, False, True ),
{Zoanoid} ( True, True, False, True, True, True, False, True ),
{GroundHugger} ( True, False, False, False, False, False, True, True ),
{Arachnoid} ( True, True, False, True, False, True, True, True ),
{AeroFighter} ( True, False, False, False, True, False, False, True ),
{Ornithoid} ( True, True, False, True, True, True, False, True ),
{Gerwalk} ( True, True, True, True, True, True, False, True ),
{HoverFighter} ( True, False, False, False, True, False, True, True ),
{GroundCar} ( True, False, False, False, False, False, True, True )
);
{ MODULE HIT POINT DEFINITIONS }
{All these definitions are based on the module's size.}
MHP_NoHP = 0; {Used for storage pods. All dmg passed on to SubMods.}
MHP_HalfSize = 4; { HP = ( Size + 1 ) div 2 }
MHP_EqualSize = 1; { HP = Size }
MHP_SizePlusOne = 2; { HP = Size + 1 }
MHP_SizeTimesTwo = 3; { HP = Size * 2 }
CModule: Array [1..NumModule] of ModuleDesc = (
( name: 'Body';
MHP: MHP_SizeTimesTwo;
),
( name: 'Head';
MHP: MHP_HalfSize;
),
( name: 'Arm';
MHP: MHP_EqualSize;
),
( name: 'Leg';
MHP: MHP_SizePlusOne;
),
( name: 'Wing';
MHP: MHP_HalfSize;
),
( name: 'Tail';
MHP: MHP_EqualSize;
),
( name: 'Turret';
MHP: MHP_HalfSize;
),
( name: 'Storage';
MHP: MHP_NoHP;
)
);
{ MODIFIER GEAR }
{ G = GG_Modifier }
{ S = Modification Type }
{ V = Cybernetic Trauma Value }
GS_StatModifier = 1;
GS_SkillModifier = 2;
{ Only one gear with a given 'cyberslot' type should be installed }
{ at any given time. Attempting to install another should result }
{ in the first being deleted. }
{ Without a cyberslot, the modifier won't interfere with other }
{ modifier gears at all. }
{ Sample slot names: EYE, EAR, MUSCULAR, SKELETON, HEART, etc. }
SATT_CyberSlot = 'CYBERSLOT';
STAT_SkillToModify = 1;
STAT_SkillModBonus = 2;
Function LookupModuleCode(const name_in: String): Integer;
Procedure InitModule(Part: GearPtr);
Function ModuleBaseDamage(Part: GearPtr): Integer;
Function ModuleComplexity( Part: GearPtr ): Integer;
Function ModuleName(Part: GearPtr): String;
Function ModuleBaseMass(Part: GearPtr): Integer;
Procedure CheckModuleRange( Part: GearPtr );
Function IsLegalModuleInv( Slot, Equip: GearPtr ): Boolean;
Function IsLegalModuleSub( Slot, Equip: GearPtr ): Boolean;
Function ModifierCost( Part: GearPtr ): LongInt;
Procedure CheckModifierRange( Part: GearPtr );
implementation
uses ghholder,texutil;
Function LookupModuleCode(const name_In: String): Integer;
{Locate the module code which corresponds to the name}
{provided. If no such module type exists return a -1.}
var
T,M: Integer;
Name: String;
begin
M := -1;
{Set the NAME to upper case.}
Name := UpCase(Name_In);
for t := 1 to NumModule do begin
if UpCase(CModule[T].Name) = Name then M := T;
end;
LookupModuleCode := M;
end;
Procedure InitModule(Part: GearPtr);
{PART is a newly created module record.}
{Initialize its stuff.}
begin
{ Modules inherit GearOps/Material from their parent. }
if Part^.Parent <> Nil then begin
SetNAtt( Part^.NA , NAG_GearOps , NAS_Material , NAttValue( Part^.Parent^.NA , NAG_GearOps , NAS_Material ) );
end;
end;
Function ModuleBaseDamage(Part: GearPtr): Integer;
{For module PART, calculate the unscaled amount of}
{damage that it can take before being destroyed.}
var
it: Integer;
begin
{Error check - make sure we actually have a Module.}
if Part = Nil then Exit(0);
if Part^.G <> GG_Module then Exit(0);
if (Part^.S < 1) or (Part^.S > NumModule) then Exit(0);
Case CModule[Part^.S].MHP of
MHP_NoHP: it := -1;
MHP_HalfSize: it := ( Part^.V + 1 ) div 2;
MHP_EqualSize: it := Part^.V;
MHP_SizePlusOne: it := Part^.V + 1;
MHP_SizeTimesTwo: it := Part^.V * 2;
else it := 0;
end;
ModuleBaseDamage := it;
end;
Function ModuleComplexity( Part: GearPtr ): Integer;
{ Return the complexity value for this part. }
begin
if ( Part^.S = GS_Body ) or ( Part^.S = GS_Storage ) then begin
ModuleComplexity := ( Part^.V + 1 ) * 2;
end else begin
ModuleComplexity := Part^.V + 1;
end;
end;
Function ModuleName(Part: GearPtr): String;
{Determine the geneic name for this particular module.}
begin
{Eliminate all error cases first off...}
if (Part = Nil) or (Part^.G <> GG_Module) or (Part^.S < 1) or (Part^.S > NumModule) then Exit('Unknown');
ModuleName := CModule[Part^.S].Name;
end;
Function ModuleBaseMass(Part: GearPtr): Integer;
{For module PART, calculate the unscaled mass.}
var
it: Integer;
begin
{Error check - make sure we actually have a Module.}
if Part = Nil then Exit(0);
if Part^.G <> GG_Module then Exit(0);
if (Part^.S < 1) or (Part^.S > NumModule) then Exit(0);
Case CModule[Part^.S].MHP of
MHP_NoHP: it := 0;
MHP_EqualSize,MHP_Halfsize: it := Part^.V;
MHP_SizePlusOne: it := Part^.V + 1;
MHP_SizeTimesTwo: it := Part^.V * 2;
else it := 0;
end;
{Armor also adds weight to a module.}
it := it + Part^.Stat[ STAT_Armor ];
ModuleBaseMass := it;
end;
Procedure CheckModuleRange( Part: GearPtr );
{ Check a MODULE gear to make sure all values are within appropriate }
{ range. }
var
InAMek: Boolean;
T: Integer;
begin
{ Check S - Module Type }
if Part^.S < 1 then Part^.S := GS_Storage
else if Part^.S > NumModule then Part^.S := GS_Storage;
if ( Part^.Parent = Nil ) then InAMek := False
else if Part^.Parent^.G = GG_Mecha then InAMek := True
else InAMek := False;
{ Check V - Module Size }
{ If this module is installed in a Mecha, there'll be a }
{ limit on its size. }
if InAMek then begin
if Part^.S = GS_Body then Part^.V := Part^.Parent^.V
else if Part^.V > ( Part^.Parent^.V + 1 ) then Part^.V := ( Part^.Parent^.V + 1 );
end;
if Part^.V > 10 then Part^.V := 10;
{ Check Stats }
{ Stat 1 - Armor }
if Part^.Stat[1] < 0 then Part^.Stat[1] := 0
else if InAMek then begin
{ Armor rating may not exceed the size of the mecha. }
if Part^.Stat[1] > Part^.Parent^.V then Part^.Stat[1] := Part^.Parent^.V;
end else begin
if Part^.Stat[1] > 10 then Part^.Stat[1] := 10;
end;
{ Stat 3 - InfoTier }
if Part^.Stat[ STAT_InfoTier ] < 0 then Part^.Stat[ STAT_InfoTier ] := 0
else if Part^.Stat[ STAT_InfoTier ] > 3 then Part^.Stat[ STAT_InfoTier ] := 3;
for t := 4 to NumGearStats do Part^.Stat[ T ] := 0;
end;
Function IsLegalModuleInv( Slot, Equip: GearPtr ): Boolean;
{ Check EQUIP to see if it can be stored in SLOT. }
{ INPUTS: Slot and Equip must both be properly allocated gears. }
{ See therules.txt for a list of acceptable equipment. }
var
it: Boolean;
begin
if Slot^.S = GS_Arm then begin
Case Equip^.G of
GG_ExArmor: begin
it := Slot^.S = Equip^.S;
end;
GG_Shield: it := true;
else it := False;
end;
end else if Slot^.S = GS_Tail then begin
Case Equip^.G of
GG_ExArmor: begin
it := Slot^.S = Equip^.S;
end;
GG_Shield: it := true;
else it := False;
end;
end else begin
Case Equip^.G of
GG_ExArmor: begin
it := Slot^.S = Equip^.S;
end;
else it := False;
end;
end;
{ If the item is of a different scale than the holder, }
{ it can't be held. }
if Equip^.Scale <> Slot^.Scale then it := False;
IsLegalModuleInv := it;
end;
Function IsLegalModuleSub( Slot, Equip: GearPtr ): Boolean;
{ Return TRUE if EQUIP can be installed in SLOT, }
{ FALSE otherwise. }
begin
if Slot^.S = GS_Body then begin
case Equip^.G of
GG_Cockpit: IsLegalModuleSub := True;
GG_Weapon: IsLegalModuleSub := True;
GG_MoveSys: IsLegalModuleSub := True;
GG_Holder: begin
if Equip^.S = GS_Hand then IsLegalModuleSub := False
else IsLegalModuleSub := True;
end;
GG_Sensor: IsLegalModuleSub := True;
GG_Electronics: IsLegalModuleSub := True;
GG_Support: IsLegalModuleSub := True;
else IsLegalModuleSub := False
end;
end else begin
case Equip^.G of
GG_Cockpit: IsLegalModuleSub := True;
GG_Weapon: IsLegalModuleSub := True;
GG_MoveSys: IsLegalModuleSub := True;
GG_Holder: begin
if ( Equip^.S = GS_Hand ) and ( Slot^.S <> GS_Arm ) then IsLegalModuleSub := False
else IsLegalModuleSub := True;
end;
GG_Sensor: IsLegalModuleSub := True;
GG_Electronics: IsLegalModuleSub := True;
else IsLegalModuleSub := False
end;
end;
end;
Function ModifierCost( Part: GearPtr ): LongInt;
{ The cost of a modifier part will depend upon how many +s it }
{ gives versus how many -s it imparts. }
const
BasePrice: Array [1..5] of Byte = (10,25,45,70,100);
PriceFactor = 2000;
var
plusses,minuses,T: Integer;
it: LongInt;
begin
{ Initialize our counters. }
plusses := 0;
minuses := 0;
{ Count up the plusses and minuses. }
if Part^.S = GS_StatModifier then begin
for t := 1 to NumGearStats do begin
if Part^.Stat[ T ] > 0 then begin
plusses := plusses + Part^.Stat[ T ];
end else if Part^.Stat[ T ] < 0 then begin
minuses := minuses - Part^.Stat[ T ];
end;
end;
end else if Part^.S = GS_SkillModifier then begin
Plusses := Part^.Stat[ STAT_SkillModBonus ];
end;
it := 0;
if Plusses > 5 then begin
it := it + ( PriceFactor * 50 * ( Plusses - 5 ) );
Plusses := 5;
end;
if Plusses > 0 then begin
it := BasePrice[ Plusses ] * PriceFactor + it;
end;
if Minuses > 0 then begin
it := it - PriceFactor * 5 * Minuses;
end else begin
{ If no minuses, a 50% increase in price. }
it := ( it * 3 ) div 2;
end;
{ Reduce cost by the trauma value of the system. }
if AStringHasBString( SAttValue( Part^.SA , 'TYPE' ) , 'CHARA' ) then begin
it := ( it * ( 100 - Part^.V ) ) div 100;
end else begin
{ Non-character modifiers are considerably cheaper. }
it := it div 2;
end;
{ Reduce cost for a non-combat skillmodifier. }
if ( Part^.S = GS_SkillModifier ) and ( Part^.Stat[ STAT_SkillToModify ] > 10 ) then it := it div 2;
{ Make sure the cost doesn't fall below the minimum value. }
if it < PriceFactor then it := PriceFactor;
{ Return the calculated value. }
ModifierCost := it;
end;
Procedure CheckModifierRange( Part: GearPtr );
{ Make sure that this modification gear is within the accepted }
{ range bands. }
var
T: Integer;
begin
{ S = Modifier Type, must be 1 or 2. }
if Part^.S < 1 then Part^.S := 1
else if Part^.S > 2 then Part^.S := 2;
{ V = Trauma Value, may be from 0 to 80 }
if Part^.V < 0 then Part^.V := 0
else if Part^.V > 100 then Part^.V := 80;
{ Scale - Must be 0! }
if Part^.Scale <> 0 then Part^.Scale := 0;
{ Check the stats for range. }
if Part^.S = GS_StatModifier then begin
for t := 1 to NumGearStats do begin
if Part^.Stat[ T ] > 10 then Part^.Stat[ T ] := 10
else if Part^.Stat[ T ] < -5 then Part^.Stat[ T ] := -5;
end;
end else if Part^.S = GS_SkillModifier then begin
if Part^.Stat[ 2 ] < 1 then Part^.Stat[ 2 ] := 1
else if Part^.Stat[ 2 ] > 10 then Part^.Stat[ 2 ] := 10;
end;
end;
end.