forked from Mirrors/openclonk
added callback OnMaterialChanged (#217)
parent
4d248d85c5
commit
2a6e2cbc89
|
@ -5,9 +5,6 @@
|
|||
The protoganist of the game. Witty and nimble if skillfully controled ;-)
|
||||
|
||||
TODO:
|
||||
+ You should write a lot about the functioning of the animations-system,
|
||||
holding weapons etc. and/or put that into a separate library - Newton
|
||||
|
||||
+ replace German comments
|
||||
*/
|
||||
|
||||
|
@ -47,7 +44,6 @@ protected func Construction()
|
|||
|
||||
AddEffect("IntTurn", this, 1, 1, this);
|
||||
AddEffect("IntEyes", this, 1, 35+Random(4), this);
|
||||
AddEffect("Bubble", this, 1, 72, this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1716,9 +1712,24 @@ func FxIntRidingStop(pTarget, iNumber, fTmp)
|
|||
pMount->~OnUnmount(this);
|
||||
}
|
||||
|
||||
// calback from engine
|
||||
func OnMaterialChanged(int new, int old)
|
||||
{
|
||||
var newdens = GetMaterialVal("Density","Material",new);
|
||||
var olddens = GetMaterialVal("Density","Material",old);
|
||||
var newliquid = (newdens >= C4M_Liquid) && (newdens < C4M_Solid);
|
||||
var oldliquid = (olddens >= C4M_Liquid) && (olddens < C4M_Solid);
|
||||
// into water
|
||||
if(newliquid && !oldliquid)
|
||||
AddEffect("Bubble", this, 1, 72, this);
|
||||
// out of water
|
||||
else if(!newliquid && oldliquid)
|
||||
RemoveEffect("Bubble", this);
|
||||
}
|
||||
|
||||
func FxBubbleTimer(pTarget, iNumber, iTime)
|
||||
{
|
||||
if(GBackLiquid(0,-4)) Bubble();
|
||||
Bubble();
|
||||
}
|
||||
|
||||
func StartPushing()
|
||||
|
|
|
@ -729,6 +729,23 @@ void C4Object::ComponentConGain()
|
|||
Max<int32_t>(Component.GetCount(cnt),Def->Component.GetCount(cnt)*Con/FullCon));
|
||||
}
|
||||
|
||||
void C4Object::UpdateInMat()
|
||||
{
|
||||
// get new mat
|
||||
int32_t newmat;
|
||||
if (Contained)
|
||||
newmat = Contained->Def->ClosedContainer ? MNone : Contained->InMat;
|
||||
else
|
||||
newmat = GBackMat(GetX(), GetY());
|
||||
|
||||
// mat changed?
|
||||
if (newmat != InMat)
|
||||
{
|
||||
Call(PSF_OnMaterialChanged,&C4AulParSet(C4VInt(newmat),C4VInt(InMat)));
|
||||
InMat = newmat;
|
||||
}
|
||||
}
|
||||
|
||||
void C4Object::SetOCF()
|
||||
{
|
||||
C4PropList* pActionDef = GetAction();
|
||||
|
@ -743,10 +760,7 @@ void C4Object::SetOCF()
|
|||
else if (Contained && !Contained->Status)
|
||||
{ LogF("Warning: contained in deleted object %p (%s)!", static_cast<void*>(Contained), Contained->GetName()); }
|
||||
#endif
|
||||
if (Contained)
|
||||
InMat = Contained->Def->ClosedContainer ? MNone : Contained->InMat;
|
||||
else
|
||||
InMat = GBackMat(GetX(), GetY());
|
||||
UpdateInMat();
|
||||
// OCF_Normal: The OCF is never zero
|
||||
OCF=OCF_Normal;
|
||||
// OCF_Construct: Can be built outside
|
||||
|
@ -882,10 +896,7 @@ void C4Object::UpdateOCF()
|
|||
else if (Contained && !Contained->Status)
|
||||
{ LogF("Warning: contained in deleted object %p (%s)!", static_cast<void*>(Contained), Contained->GetName()); }
|
||||
#endif
|
||||
if (Contained)
|
||||
InMat = Contained->Def->ClosedContainer ? MNone : Contained->InMat;
|
||||
else
|
||||
InMat = GBackMat(GetX(), GetY());
|
||||
UpdateInMat();
|
||||
// Keep the bits that only have to be updated with SetOCF (def, category, con, alive, onfire)
|
||||
OCF=OCF & (OCF_Normal | OCF_Exclusive | OCF_Edible | OCF_Grab | OCF_FullCon
|
||||
/*| OCF_Chop - now updated regularly, see below */
|
||||
|
|
|
@ -131,6 +131,8 @@ public:
|
|||
|
||||
class C4Object: public C4PropListNumbered
|
||||
{
|
||||
private:
|
||||
void UpdateInMat();
|
||||
public:
|
||||
C4Object();
|
||||
~C4Object();
|
||||
|
|
|
@ -190,6 +190,7 @@ bool C4ValueToMatrix(const C4ValueArray& array, StdMeshMatrix* matrix);
|
|||
#define PSF_NameChange "~OnNameChanged" // bool inInfoSection
|
||||
#define PSF_OnWealthChanged "~OnWealthChanged" // int iPlr
|
||||
#define PSF_OnActionChanged "~OnActionChanged" // string oldaction
|
||||
#define PSF_OnMaterialChanged "~OnMaterialChanged" // int newmat, int oldmat
|
||||
|
||||
// Fx%s is automatically prefixed
|
||||
#define PSFS_FxAdd "Add" // C4Object *pTarget, int iEffectNumber, C4String *szNewEffect, int iNewTimer, C4Value vNewEffectVar1, C4Value vNewEffectVar2, C4Value vNewEffectVar3, C4Value vNewEffectVar4
|
||||
|
|
Loading…
Reference in New Issue