1//**************************************************************************
2//**
3//**    ##   ##    ##    ##   ##   ####     ####   ###     ###
4//**    ##   ##  ##  ##  ##   ##  ##  ##   ##  ##  ####   ####
5//**     ## ##  ##    ##  ## ##  ##    ## ##    ## ## ## ## ##
6//**     ## ##  ########  ## ##  ##    ## ##    ## ##  ###  ##
7//**      ###   ##    ##   ###    ##  ##   ##  ##  ##       ##
8//**       #    ##    ##    #      ####     ####   ##       ##
9//**
10//**    $Id: BasicArmor.vc 2989 2008-01-06 13:27:01Z dj_jl $
11//**
12//**    Copyright (C) 1999-2006 Jānis Legzdiņš
13//**
14//**    This program is free software; you can redistribute it and/or
15//**  modify it under the terms of the GNU General Public License
16//**  as published by the Free Software Foundation; either version 2
17//**  of the License, or (at your option) any later version.
18//**
19//**    This program is distributed in the hope that it will be useful,
20//**  but WITHOUT ANY WARRANTY; without even the implied warranty of
21//**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22//**  GNU General Public License for more details.
23//**
24//**************************************************************************
25
26class BasicArmor : Armor;
27
28float			SavePercent;
29
30//==========================================================================
31//
32//	CreateCopy
33//
34//==========================================================================
35
36Inventory CreateCopy(EntityEx Toucher)
37{
38	//	I don't see why we need this, but for compatibility purposes it's
39	// here.
40	BasicArmor Copy = Spawn(BasicArmor,,,, false);
41	Copy.Amount = Amount;
42	Copy.MaxAmount = MaxAmount;
43	Copy.SavePercent = SavePercent ? SavePercent : 1.0 / 3.0;
44	Copy.IconName = IconName;
45	GoAwayAndDie();
46	return Copy;
47}
48
49//==========================================================================
50//
51//	HandlePickup
52//
53//==========================================================================
54
55bool HandlePickup(Inventory Item)
56{
57	if (Item.Class == Class)
58	{
59		//	You shouldn't be picking up BasicArmor anyway.
60		return true;
61	}
62	if (Inventory)
63	{
64		return Inventory.HandlePickup(Item);
65	}
66	return false;
67}
68
69//==========================================================================
70//
71//	AbsorbDamage
72//
73//==========================================================================
74
75void AbsorbDamage(int damage, name DmgType, out int NewDamage)
76{
77	if (DmgType != 'Drowning')
78	{
79		int saved = ftoi(itof(damage) * SavePercent);
80		if (Amount <= saved)
81		{
82			saved = Amount;
83		}
84		Amount -= saved;
85		NewDamage -= saved;
86		if (Amount == 0)
87		{
88			// armor is used up
89			SavePercent = 0.0;
90			// Try to use some inventory armor
91			EntityEx(Owner).AutoUseArmor();
92		}
93		damage = NewDamage;
94	}
95	if (Inventory)
96	{
97		Inventory.AbsorbDamage(damage, DmgType, NewDamage);
98	}
99}
100
101defaultproperties
102{
103	bKeepDepleted = true;
104}
105