summaryrefslogtreecommitdiffstats
path: root/DTPhysicalStack.c
diff options
context:
space:
mode:
authorMarkus Mittendrein <git@maxmitti.tk>2017-01-05 16:19:56 +0100
committerMarkus Mittendrein <git@maxmitti.tk>2017-01-05 16:19:56 +0100
commit9b5d0a3ddf41e686439dcda1edfe11eee51c3b07 (patch)
treeeda63d0f51f49b36e0269b6efdf4c612d9ab7d68 /DTPhysicalStack.c
downloadSystem.c4g-9b5d0a3ddf41e686439dcda1edfe11eee51c3b07.tar.gz
System.c4g-9b5d0a3ddf41e686439dcda1edfe11eee51c3b07.zip
Initial
Diffstat (limited to 'DTPhysicalStack.c')
-rw-r--r--DTPhysicalStack.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/DTPhysicalStack.c b/DTPhysicalStack.c
new file mode 100644
index 0000000..c0aa7ad
--- /dev/null
+++ b/DTPhysicalStack.c
@@ -0,0 +1,72 @@
+#strict 2
+
+global func GetPhysicalFactorStack(object target)
+{
+ target || FatalError("GetPhysicalFactorStack: no target object given");
+ return GetEffect("PhysicalFactorStack", target) || AddEffect("PhysicalFactorStack", target, 200);
+}
+
+global func AddPhysicalFactor(string physical, int factor, int precision, object target)
+{
+ target = target || this || FatalError("AddPhysicalFactor: no target object given");
+ precision = precision || 100;
+
+ return EffectCall(target, GetPhysicalFactorStack(target), "AddFactor", physical, factor, precision);
+}
+
+global func RemovePhysicalFactor(int id, object target)
+{
+ target = target || this || FatalError("AddPhysicalFactor: no target object given");
+
+ return EffectCall(target, GetPhysicalFactorStack(target), "RemoveFactor", id);
+}
+
+global func FxPhysicalFactorStackStart(object target, int effectNumber, int temp)
+{
+ if(!temp)
+ {
+ EffectVar(1, target, effectNumber) = [];
+ }
+}
+
+global func FxPhysicalFactorStackAddFactor(object target, int effectNumber, string physical, int factor, int precision)
+{
+ ArrayAppend(EffectVar(1, target, effectNumber), [++EffectVar(0, target, effectNumber), physical, factor, precision]);
+ EffectCall(target, effectNumber, "ApplyPhysical", physical);
+ return EffectVar(0, target, effectNumber);
+}
+
+global func FxPhysicalFactorStackRemoveFactor(object target, int effectNumber, int id)
+{
+ for(var i = 0; i < GetLength(EffectVar(1, target, effectNumber)); ++i)
+ {
+ if(EffectVar(1, target, effectNumber)[i][0] == id)
+ {
+ var physical = EffectVar(1, target, effectNumber)[i][1];
+ ArrayErase(EffectVar(1, target, effectNumber), i);
+ EffectCall(target, effectNumber, "ApplyPhysical", physical);
+ return true;
+ }
+ }
+ return 0;
+}
+
+global func FxPhysicalFactorStackApplyPhysical(object target, int effectNumber, string physical)
+{
+ var phys = GetPhysical(physical, PHYS_Temporary, target);
+ if(phys)
+ {
+ ResetPhysical(target, physical);
+ }
+ phys = GetPhysical(physical, PHYS_Current, target);
+ for(var factor in EffectVar(1, target, effectNumber))
+ {
+ if(factor[1] == physical)
+ {
+ phys *= factor[2];
+ phys /= factor[3];
+ }
+ }
+ SetPhysical(physical, phys, PHYS_StackTemporary, target);
+ return phys;
+}