qzdoom/wadsrc/static/zscript/inventory/health.txt

193 lines
5.1 KiB
Text
Raw Normal View History

2017-01-15 00:02:38 +00:00
/*
** a_health.cpp
** All health items
**
**---------------------------------------------------------------------------
** Copyright 2000-2016 Randy Heit
2018-11-26 16:15:40 +00:00
** Copyright 2006-2017 Christoph Oelckers
2017-01-15 00:02:38 +00:00
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
*/
class Health : Inventory
2017-01-15 00:02:38 +00:00
{
transient int PrevHealth;
meta int LowHealth;
meta String LowHealthMessage;
property LowMessage: LowHealth, LowHealthMessage;
2017-01-15 00:02:38 +00:00
Default
{
+INVENTORY.ISHEALTH
2017-01-15 00:02:38 +00:00
Inventory.Amount 1;
Inventory.MaxAmount 0;
Inventory.PickupSound "misc/health_pkup";
}
//===========================================================================
//
// AHealth :: PickupMessage
//
//===========================================================================
override String PickupMessage ()
{
if (PrevHealth < LowHealth)
{
String message = LowHealthMessage;
if (message.Length() != 0)
{
return message;
}
}
return Super.PickupMessage();
}
//===========================================================================
//
// TryPickup
//
//===========================================================================
override bool TryPickup (in out Actor other)
{
PrevHealth = other.player != NULL ? other.player.health : other.health;
// P_GiveBody adds one new feature, applied only if it is possible to pick up negative health:
// Negative values are treated as positive percentages, ie Amount -100 means 100% health, ignoring max amount.
if (other.GiveBody(Amount, MaxAmount))
{
GoAwayAndDie();
return true;
}
return false;
}
}
2017-01-15 00:02:38 +00:00
class MaxHealth : Health
{
//===========================================================================
//
// TryPickup
//
//===========================================================================
override bool TryPickup (in out Actor other)
{
bool success = false;
int savedAmount = MaxAmount;
let player = PlayerPawn(other);
MaxAmount = Health;
if (player)
{
if (player.BonusHealth < savedAmount)
{
player.BonusHealth = min(player.BonusHealth + Amount, savedAmount);
success = true;
}
MaxAmount += player.BonusHealth;
}
success |= Super.TryPickup(other);
MaxAmount = savedAmount;
if (success) GoAwayAndDie();
return success;
}
2017-01-15 00:02:38 +00:00
}
2017-01-15 17:46:40 +00:00
class HealthPickup : Inventory
2017-01-15 00:02:38 +00:00
{
2017-01-15 17:46:40 +00:00
int autousemode;
property AutoUse: autousemode;
2017-01-15 00:02:38 +00:00
Default
{
Inventory.DefMaxAmount;
+INVENTORY.INVBAR
+INVENTORY.ISHEALTH
2017-01-15 00:02:38 +00:00
}
//===========================================================================
//
// CreateCopy
//
//===========================================================================
override Inventory CreateCopy (Actor other)
{
Inventory copy = Super.CreateCopy (other);
copy.health = health;
return copy;
}
//===========================================================================
//
// CreateTossable
//
//===========================================================================
override Inventory CreateTossable (int amount)
2017-01-15 00:02:38 +00:00
{
Inventory copy = Super.CreateTossable (-1);
2017-01-15 00:02:38 +00:00
if (copy != NULL)
{
copy.health = health;
}
return copy;
}
//===========================================================================
//
// HandlePickup
//
//===========================================================================
override bool HandlePickup (Inventory item)
{
// HealthPickups that are the same type but have different health amounts
// do not count as the same item.
if (item.health == health)
{
return Super.HandlePickup (item);
}
return false;
}
//===========================================================================
//
// Use
//
//===========================================================================
override bool Use (bool pickup)
{
return Owner.GiveBody (health, 0);
}
}