forked from Mirrors/openclonk
added Rule_EnergyBarsAboveStructures and adjusted Krakatoa to use that
parent
8970913fc7
commit
50fd0ebc39
|
@ -2,10 +2,21 @@
|
|||
Structure Library
|
||||
Basic library for structures, handles:
|
||||
* Damage
|
||||
* Energy bar if rule active
|
||||
|
||||
@author Maikel
|
||||
*/
|
||||
|
||||
func Initialize()
|
||||
{
|
||||
if (ObjectCount(Find_ID(Rule_EnergyBarsAboveStructures)) > 0)
|
||||
{
|
||||
if (this.HitPoints != nil)
|
||||
AddEnergyBar();
|
||||
}
|
||||
return _inherited(...);
|
||||
}
|
||||
|
||||
public func Damage(int change, int cause, int cause_plr)
|
||||
{
|
||||
// Only do stuff if the object has the HitPoints property.
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
[DefCore]
|
||||
id=Rule_EnergyBarsAboveStructures
|
||||
Version=5,2,0,1
|
||||
Category=C4D_StaticBack|C4D_Rule
|
||||
Picture=0,0,64,64
|
|
@ -1,9 +0,0 @@
|
|||
[DefCore]
|
||||
id=EnergyBar
|
||||
Category=C4D_StaticBack
|
||||
Width=32
|
||||
Height=32
|
||||
Offset=-16,-16
|
||||
Vertices=1
|
||||
VertexX=0
|
||||
VertexY=8
|
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB |
|
@ -1,67 +0,0 @@
|
|||
/*--
|
||||
Energy bars
|
||||
Author: Maikel
|
||||
|
||||
Displays an energy bar above an object, uses Library_Bars.
|
||||
--*/
|
||||
|
||||
|
||||
#include Library_Bars
|
||||
|
||||
private func EnergyBarWidth() { return 24; }
|
||||
private func EnergyBarHeight() { return 6; }
|
||||
|
||||
protected func Initialize()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public func SetTarget(object target, int vtx)
|
||||
{
|
||||
// Create energy bar.
|
||||
SetBarLayers(2, 0);
|
||||
SetBarOffset(0, - target->GetDefHeight() / 2, 0);
|
||||
SetBarDimensions(target->GetDefWidth(), EnergyBarHeight(), 0);
|
||||
// Attach energy bar to the object.
|
||||
SetAction("Attach", target);
|
||||
SetActionData(vtx);
|
||||
SetClrModulation(RGB(200, 0, 0), 3);
|
||||
UpdateEnergy();
|
||||
return;
|
||||
}
|
||||
|
||||
protected func UpdateEnergy()
|
||||
{
|
||||
var target = GetActionTarget();
|
||||
var hp = target.HitPoints - target->GetDamage();
|
||||
if (!hp)
|
||||
return RemoveObject();
|
||||
var max_hp = target.HitPoints;
|
||||
var promille;
|
||||
if (max_hp == 0)
|
||||
promille = 0;
|
||||
else
|
||||
promille = 1000 * hp / max_hp;
|
||||
SetBarProgress(promille, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
protected func AttachTargetLost() { RemoveObject(); }
|
||||
|
||||
local Name = "$Name$";
|
||||
local Plane = 750;
|
||||
local ActMap = {
|
||||
Attach = {
|
||||
Prototype = Action,
|
||||
Name = "Attach",
|
||||
Procedure = DFA_ATTACH,
|
||||
Length = 1,
|
||||
Delay = 1,
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Wdt = 32,
|
||||
Hgt = 32,
|
||||
NextAction = "Attach",
|
||||
StartCall = "UpdateEnergy",
|
||||
},
|
||||
};
|
|
@ -1 +0,0 @@
|
|||
Name=Energy bar
|
|
@ -1 +0,0 @@
|
|||
Name=Energy bar
|
|
@ -19,7 +19,10 @@ func Initialize()
|
|||
goal->SetWealthGoal(250);
|
||||
goal = CreateObject(Goal_Expansion);
|
||||
goal->SetExpansionGoal(250);
|
||||
|
||||
|
||||
// some rules
|
||||
CreateObject(Rule_EnergyBarsAboveStructures, 0, 0, NO_OWNER);
|
||||
|
||||
// Find start location and place lorry plus extras there.
|
||||
FindVolcanoLocation();
|
||||
var lorry = CreateObject(Lorry);
|
||||
|
@ -83,7 +86,7 @@ func Initialize()
|
|||
|
||||
// Initialize the effect for controlling the big volcano.
|
||||
AddEffect("BigVolcano", nil, 100, 5, nil);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
// Energy bars above structures with hitpoints
|
||||
|
||||
#appendto *
|
||||
|
||||
public func Initialize()
|
||||
{
|
||||
if (this.HitPoints != nil)
|
||||
{
|
||||
AddVertex(0, 0);
|
||||
CreateObject(EnergyBar)->SetTarget(this, GetVertexNum());
|
||||
}
|
||||
return _inherited(...);
|
||||
}
|
Loading…
Reference in New Issue