OpenClonk
C4Effect.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2013-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 // C4AulFun-based effects assigned to an object
19 // an effect itself only supplies the callback mechanism for effects assigned to objects
20 // the effect itself supplies the callback mechanism for creation, destruction, timers
21 // and overlapped effects
22 /* Also contains some helper functions for various landscape effects */
23 
24 #ifndef INC_C4Effects
25 #define INC_C4Effects
26 
27 #include "script/C4PropList.h"
28 
29 // callback return values
30 #define C4Fx_OK 0 // generic standard behaviour for all effect callbacks
31 
32 #define C4Fx_Effect_Deny -1 // delete effect
33 #define C4Fx_Effect_Annul -2 // delete effect, because it has annulled a countereffect
34 #define C4Fx_Effect_AnnulCalls -3 // delete effect, because it has annulled a countereffect; temp readd countereffect
35 
36 #define C4Fx_Execute_Kill -1 // execute callback: Remove effect now
37 
38 #define C4Fx_Stop_Deny -1 // deny effect removal
39 #define C4Fx_Start_Deny -1 // deny effect start
40 
41 // parameters for effect callbacks
42 #define C4FxCall_Normal 0 // normal call; effect is being added or removed
43 #define C4FxCall_Temp 1 // temp call; effect is being added or removed in responce to a lower-level effect change
44 #define C4FxCall_TempAddForRemoval 2 // temp call; effect is being added because it had been temp removed and is now removed forever
45 #define C4FxCall_RemoveClear 3 // effect is being removed because object is being removed
46 #define C4FxCall_RemoveDeath 4 // effect is being removed because object died - return -1 to avoid removal
47 
48 // damage-callbacks
49 #define C4FxCall_DmgScript 0 // damage through script call
50 #define C4FxCall_DmgBlast 1 // damage through blast
51 #define C4FxCall_DmgFire 2 // damage through fire
52 #define C4FxCall_DmgChop 3 // damage through chopping
53 
54 // energy loss callbacks
55 #define C4FxCall_EngScript 32 // energy loss through script call
56 #define C4FxCall_EngBlast 33 // energy loss through blast
57 #define C4FxCall_EngObjHit 34 // energy loss through object hitting the living
58 #define C4FxCall_EngFire 35 // energy loss through fire
59 #define C4FxCall_EngBaseRefresh 36 // energy reload in base (also by base object, but that's normally not called)
60 #define C4FxCall_EngAsphyxiation 37 // energy loss through asphyxiaction
61 #define C4FxCall_EngCorrosion 38 // energy loss through corrosion (acid)
62 #define C4FxCall_EngStruct 39 // regular structure energy loss (normally not called)
63 #define C4FxCall_EngGetPunched 40 // energy loss from Punch
64 
65 #define C4Fx_FireParticle1 "Fire"
66 #define C4Fx_FireParticle2 "Fire2"
67 
68 // generic object effect
70 {
71 public:
72  int32_t iPriority; // effect priority for sorting into effect list; -1 indicates a dead effect
73  int32_t iTime, iInterval; // effect time; effect callback intervall
74 
75  C4Effect *pNext; // next effect in linked list
76 
77 protected:
78  C4Value CommandTarget; // target object for script callbacks - if deleted, the effect is removed without callbacks
79  C4PropList * Target; // target the effect is contained in
80  // presearched callback functions for faster calling
81  C4AulFunc *pFnTimer; // timer function Fx%sTimer
82  C4AulFunc *pFnStart, *pFnStop; // init/deinit-functions Fx%sStart, Fx%sStop
83  C4AulFunc *pFnEffect; // callback if other effect tries to register
84  C4AulFunc *pFnDamage; // callback when owned object gets damage
85 
86  void AssignCallbackFunctions(); // resolve callback function names
87 
88  int CallStart(int temporary, const C4Value &var1, const C4Value &var2, const C4Value &var3, const C4Value &var4);
89  int CallStop(int reason, bool temporary);
90  int CallTimer(int time);
91  void CallDamage(int32_t & damage, int damagetype, int plr);
92  int CallEffect(const char * effect, const C4Value &var1, const C4Value &var2, const C4Value &var3, const C4Value &var4);
93 
94  C4Effect(C4Effect **ppEffectList, C4String * szName, int32_t iPrio, int32_t iTimerInterval, C4PropList * pCmdTarget);
95  C4Effect(C4Effect **ppEffectList, C4PropList * prototype, int32_t iPrio, int32_t iTimerInterval);
96  C4Effect(const C4Effect &) = delete;
97  C4Effect(); // for the StdCompiler
98  C4Effect * Init(C4PropList *pForObj, int32_t iPrio, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4);
99  template <class T, typename ... P> friend void CompileNewFunc(T *&, StdCompiler *, P && ...);
100 public:
101  static C4Effect * New(C4PropList *pForObj, C4Effect **ppEffectList, C4String * szName, int32_t iPrio, int32_t iTimerInterval, C4PropList * pCmdTarget, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4);
102  static C4Effect * New(C4PropList *pForObj, C4Effect **ppEffectList, C4PropList * prototype, int32_t iPrio, int32_t iTimerInterval, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4);
103  ~C4Effect() override; // dtor - deletes all following effects
104 
105  void Register(C4Effect **ppEffectList, int32_t iPrio); // add into effect list of object or global effect list
106  void Denumerate(C4ValueNumbers *) override; // numbers to object pointers
107  void ClearPointers(C4PropList *pObj); // clear all pointers to object - may kill some effects w/o callback, because the callback target is lost
108 
109  void SetDead(); // mark effect to be removed in next execution cycle
110  bool IsDead() { return !iPriority; } // return whether effect is to be removed
111  void FlipActive() { iPriority*=-1; } // alters activation status
112  bool IsActive() { return iPriority>0; } // returns whether effect is active
113  bool IsInactiveAndNotDead() { return iPriority<0; } // as the name says
114 
115  C4Effect *Get(const char *szName, int32_t iIndex=0, int32_t iMaxPriority=0); // get effect by name
116  int32_t GetCount(const char *szMask, int32_t iMaxPriority=0); // count effects that match the mask
117  C4Effect *Check(const char *szCheckEffect, int32_t iPrio, int32_t iTimer, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4); // do some effect callbacks
118  C4PropList * GetCallbackScript(); // get script context for effect callbacks
119 
120  static void Execute(C4Effect **ppEffectList); // execute all effects
121  void Kill(); // mark this effect deleted and do approprioate calls
122  void ClearAll(int32_t iClearFlag);// kill all effects doing removal calls w/o reagard of inactive effects
123  void DoDamage(int32_t &riDamage, int32_t iDamageType, int32_t iCausePlr); // ask all effects for damage
124 
125  C4Value DoCall(C4PropList *pObj, const char *szFn, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4, const C4Value &rVal5, const C4Value &rVal6, const C4Value &rVal7); // custom call
126 
130  {
133  }
134  void OnObjectChangedDef(C4PropList *pObj);
135 
136  void CompileFunc(StdCompiler *pComp, C4PropList *Owner, C4ValueNumbers *);
137  C4Effect * GetEffect() override { return this; }
138  void SetPropertyByS(C4String * k, const C4Value & to) override;
139  void ResetProperty(C4String * k) override;
140  bool GetPropertyByS(const C4String *k, C4Value *pResult) const override;
141  C4ValueArray * GetProperties() const override;
142 
143 protected:
144  void TempRemoveUpperEffects(bool fTempRemoveThis, C4Effect **ppLastRemovedEffect); // temp remove all effects with higher priority
145  void TempReaddUpperEffects(C4Effect *pLastReaddEffect); // temp remove all effects with higher priority
146 };
147 
148 // Effect name patterns
149 #define C4Fx_AnyFire "*Fire*"
150 
151 #endif
void AssignCallbackFunctions()
Definition: C4Effect.cpp:27
int CallStop(int reason, bool temporary)
Definition: C4Effect.cpp:435
C4Value DoCall(C4PropList *pObj, const char *szFn, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4, const C4Value &rVal5, const C4Value &rVal6, const C4Value &rVal7)
Definition: C4Effect.cpp:409
static C4Effect * New(C4PropList *pForObj, C4Effect **ppEffectList, C4String *szName, int32_t iPrio, int32_t iTimerInterval, C4PropList *pCmdTarget, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4)
Definition: C4Effect.cpp:91
C4Effect * GetEffect() override
Definition: C4Effect.h:137
bool IsActive()
Definition: C4Effect.h:112
C4AulFunc * pFnTimer
Definition: C4Effect.h:81
int32_t iPriority
Definition: C4Effect.h:72
~C4Effect() override
Definition: C4Effect.cpp:164
void DoDamage(int32_t &riDamage, int32_t iDamageType, int32_t iCausePlr)
Definition: C4Effect.cpp:394
void ReAssignAllCallbackFunctions()
Definition: C4Effect.h:129
C4Effect * pNext
Definition: C4Effect.h:75
C4Effect(const C4Effect &)=delete
C4PropList * GetCallbackScript()
Definition: C4Effect.cpp:40
C4PropList * Target
Definition: C4Effect.h:79
void FlipActive()
Definition: C4Effect.h:111
C4ValueArray * GetProperties() const override
Definition: C4Effect.cpp:665
C4Effect * Check(const char *szCheckEffect, int32_t iPrio, int32_t iTimer, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4)
Definition: C4Effect.cpp:249
void TempRemoveUpperEffects(bool fTempRemoveThis, C4Effect **ppLastRemovedEffect)
Definition: C4Effect.cpp:496
C4AulFunc * pFnStart
Definition: C4Effect.h:82
bool IsInactiveAndNotDead()
Definition: C4Effect.h:113
void Denumerate(C4ValueNumbers *) override
Definition: C4Effect.cpp:176
C4AulFunc * pFnDamage
Definition: C4Effect.h:84
void Register(C4Effect **ppEffectList, int32_t iPrio)
Definition: C4Effect.cpp:71
void CallDamage(int32_t &damage, int damagetype, int plr)
Definition: C4Effect.cpp:462
void ResetProperty(C4String *k) override
Definition: C4Effect.cpp:625
int32_t iTime
Definition: C4Effect.h:73
bool GetPropertyByS(const C4String *k, C4Value *pResult) const override
Definition: C4Effect.cpp:648
void SetPropertyByS(C4String *k, const C4Value &to) override
Definition: C4Effect.cpp:598
friend void CompileNewFunc(T *&, StdCompiler *, P &&...)
void ClearPointers(C4PropList *pObj)
Definition: C4Effect.cpp:191
void ReAssignCallbackFunctions()
Definition: C4Effect.h:127
C4AulFunc * pFnStop
Definition: C4Effect.h:82
C4AulFunc * pFnEffect
Definition: C4Effect.h:83
int32_t iInterval
Definition: C4Effect.h:73
void OnObjectChangedDef(C4PropList *pObj)
Definition: C4Effect.cpp:482
C4Effect * Get(const char *szName, int32_t iIndex=0, int32_t iMaxPriority=0)
Definition: C4Effect.cpp:210
int CallEffect(const char *effect, const C4Value &var1, const C4Value &var2, const C4Value &var3, const C4Value &var4)
Definition: C4Effect.cpp:473
int CallStart(int temporary, const C4Value &var1, const C4Value &var2, const C4Value &var3, const C4Value &var4)
Definition: C4Effect.cpp:427
C4Value CommandTarget
Definition: C4Effect.h:78
int32_t GetCount(const char *szMask, int32_t iMaxPriority=0)
Definition: C4Effect.cpp:236
void Kill()
Definition: C4Effect.cpp:343
C4Effect * Init(C4PropList *pForObj, int32_t iPrio, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4)
Definition: C4Effect.cpp:103
bool IsDead()
Definition: C4Effect.h:110
static void Execute(C4Effect **ppEffectList)
Definition: C4Effect.cpp:297
void ClearAll(int32_t iClearFlag)
Definition: C4Effect.cpp:369
int CallTimer(int time)
Definition: C4Effect.cpp:443
void TempReaddUpperEffects(C4Effect *pLastReaddEffect)
Definition: C4Effect.cpp:521
void CompileFunc(StdCompiler *pComp, C4PropList *Owner, C4ValueNumbers *)
Definition: C4Effect.cpp:541
void SetDead()
Definition: C4Effect.cpp:205