1 /**
2 	Status Symbol
3 	Shows a certain state of an object.
4 
5 	@author Zapper, Maikel
6 */
7 
8 
9 local symbol;
10 
Init(object to)11 public func Init(object to)
12 {
13 	SetAction("Be", to);
14 
15 	// Above the object.
16 	var hgt = to->GetDefCoreVal("Height", "DefCore") / 2;
17 	SetVertex(0, VTX_Y, hgt);
18 	var x = to->GetVertex(0, VTX_X);
19 	SetVertex(0, VTX_X, x);
20 	// Set plane to be higher than the object attached to.
21 	this.Plane = Max(to.Plane + 1, 1000);
22 	return;
23 }
24 
GetStatusSymbolHelper(object to)25 public func GetStatusSymbolHelper(object to)
26 {
27 	var obj = FindObject(Find_ID(StatusSymbol), Find_ActionTarget(to));
28 	if (obj)
29 		return obj;
30 	obj = CreateObject(StatusSymbol, 0, 0, to->GetOwner());
31 	obj->Init(to);
32 	return obj;
33 }
34 
ShowStatusSymbol(id symbol)35 global func ShowStatusSymbol(id symbol)
36 {
37 	if (!this)
38 		return false;
39 	var h = StatusSymbol->GetStatusSymbolHelper(this);
40 	if(!h)
41 		return false;
42 
43 	h->AddSymbol(symbol);
44 	return true;
45 }
46 
RemoveStatusSymbol(id symbol)47 global func RemoveStatusSymbol(id symbol)
48 {
49 	if (!this)
50 		return false;
51 	var h = StatusSymbol->GetStatusSymbolHelper(this);
52 	if (!h)
53 		return false;
54 	h->RemoveSymbol(symbol);
55 	return true;
56 }
57 
AddSymbol(id symbol_id)58 public func AddSymbol(id symbol_id)
59 {
60 	symbol = symbol_id;
61 	Update();
62 }
63 
RemoveSymbol(id symbol_id)64 public func RemoveSymbol(id symbol_id)
65 {
66 	if (symbol != symbol_id)
67 		return;
68 	symbol = nil;
69 	Update();
70 }
71 
Update()72 public func Update()
73 {
74 	if (!symbol)
75 	{
76 		SetGraphics();
77 		this.Visibility = VIS_None;
78 		return;
79 	}
80 	SetShape(symbol->GetDefOffset(0), symbol->GetDefOffset(1), symbol->GetDefWidth(), symbol->GetDefHeight());
81 	SetGraphics(nil, symbol);
82 	Blink();
83 	return;
84 }
85 
Blink()86 public func Blink()
87 {
88 	if (GetEffect("Blinking", this))
89 		RemoveEffect("Blinking", this);
90 	AddEffect("Blinking", this, 1, 16, this);
91 	return;
92 }
93 
FxBlinkingStart(object target,proplist effect,int temp)94 protected func FxBlinkingStart(object target, proplist effect, int temp)
95 {
96 	if (temp)
97 		return FX_OK;
98 	// Set interval to a fixed number of frames.
99 	effect.Interval = 16;
100 	// Set initial visibility to visible.
101 	this.Visibility = this->GetActionTarget().Visibility;
102 	effect.visible = true;
103 	return FX_OK;
104 }
105 
FxBlinkingTimer(object target,proplist effect)106 protected func FxBlinkingTimer(object target, proplist effect)
107 {
108 	if (effect.visible)
109 	{
110 		effect.visible = false;
111 		this.Visibility = VIS_None;
112 	}
113 	else
114 	{
115 		effect.visible = true;
116 		this.Visibility = this->GetActionTarget().Visibility;
117 	}
118 	return FX_OK;
119 }
120 
121 // Callback from the engine: this symbol has lost its parent.
AttachTargetLost()122 protected func AttachTargetLost()
123 {
124 	return RemoveObject();
125 }
126 
SaveScenarioObject()127 public func SaveScenarioObject() { return false; }
128 
129 
130 /*-- Properties --*/
131 
132 local Name = "$Name$";
133 local Description = "$Description$";
134 local Plane = 1000;
135 
136 local ActMap =
137 {
138 	Be =
139 	{
140 		Prototype = Action,
141 		Name = "Be",
142 		Procedure = DFA_ATTACH,
143 		NextAction = "Be",
144 		Length = 1,
145 		FacetBase = 1,
146 		AbortCall = "AttachTargetLost"
147 	}
148 };
149