diff --git a/planet/Objects.c4d/Clonk.c4d/Script.c b/planet/Objects.c4d/Clonk.c4d/Script.c index c782cd655..1b0f5d935 100644 --- a/planet/Objects.c4d/Clonk.c4d/Script.c +++ b/planet/Objects.c4d/Clonk.c4d/Script.c @@ -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() diff --git a/src/game/object/C4Object.cpp b/src/game/object/C4Object.cpp index b1892a5b7..2f1cf04c6 100644 --- a/src/game/object/C4Object.cpp +++ b/src/game/object/C4Object.cpp @@ -729,6 +729,23 @@ void C4Object::ComponentConGain() Max(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(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(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 */ diff --git a/src/game/object/C4Object.h b/src/game/object/C4Object.h index 530b81daa..7c0e08ea2 100644 --- a/src/game/object/C4Object.h +++ b/src/game/object/C4Object.h @@ -131,6 +131,8 @@ public: class C4Object: public C4PropListNumbered { +private: + void UpdateInMat(); public: C4Object(); ~C4Object(); diff --git a/src/game/script/C4Script.h b/src/game/script/C4Script.h index a48ccb216..e2f1540c6 100644 --- a/src/game/script/C4Script.h +++ b/src/game/script/C4Script.h @@ -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