Move miscellaneous global functions from C4Effect.cpp to their users

objectmenu
Günther Brammer 2015-12-19 01:17:40 +01:00
parent 9833c1ef2d
commit a5f797f96b
6 changed files with 60 additions and 76 deletions

View File

@ -23,12 +23,7 @@
#include <C4DefList.h>
#include <C4Object.h>
#include <C4Random.h>
#include <C4Game.h>
#include <C4Landscape.h>
#include <C4PXS.h>
#include <C4GameObjects.h>
#include <C4SoundSystem.h>
void C4Effect::AssignCallbackFunctions()
{
@ -568,66 +563,3 @@ C4ValueArray * C4Effect::GetProperties() const
(*a)[i++] = C4VString(&::Strings.P[P_Time]);
return a;
}
// Some other, internal effects -------------------------------------------------------------
static int32_t GetSmokeLevel()
{
// just use fixed smoke level, smoke uses particles anyway
return 150;
}
static void BubbleOut(int32_t tx, int32_t ty)
{
// No bubbles from nowhere
if (!GBackSemiSolid(tx,ty)) return;
// User-defined smoke level
int32_t SmokeLevel = GetSmokeLevel();
// Enough bubbles out there already
if (::Objects.ObjectCount(C4ID::Bubble) >= SmokeLevel) return;
// Create bubble
Game.CreateObject(C4ID::Bubble,NULL,NO_OWNER,tx,ty);
}
void Splash(int32_t tx, int32_t ty, int32_t amt, C4Object *pByObj)
{
// Splash only if there is free space above
if (GBackSemiSolid(tx, ty - 15)) return;
// get back mat
int32_t iMat = GBackMat(tx, ty);
// check liquid
if (MatValid(iMat))
if (DensityLiquid(::MaterialMap.Map[iMat].Density) && ::MaterialMap.Map[iMat].Instable)
{
int32_t sy = ty;
while (GBackLiquid(tx, sy) && sy > ty - 20 && sy >= 0) sy--;
// Splash bubbles and liquid
for (int32_t cnt=0; cnt<amt; cnt++)
{
int32_t bubble_x = tx+Random(16)-8;
int32_t bubble_y = ty+Random(16)-6;
BubbleOut(bubble_x,bubble_y);
if (GBackLiquid(tx,ty) && !GBackSemiSolid(tx, sy))
{
C4Real xdir = C4REAL100(Random(151)-75);
C4Real ydir = C4REAL100(-Random(200));
::PXS.Create(::Landscape.ExtractMaterial(tx,ty,false),
itofix(tx),itofix(sy),
xdir,
ydir);
}
}
}
// Splash sound
if (amt>=20)
StartSoundEffect("Liquids::Splash2", false, 50, pByObj);
else if (amt>1) StartSoundEffect("Liquids::Splash1", false, 50, pByObj);
}
void Smoke(int32_t tx, int32_t ty, int32_t level, DWORD dwClr)
{
// Use scripted function (global func Smoke) to create smoke
// Caution: This makes engine internal smoking a synced call.
C4AulParSet pars(C4VInt(tx), C4VInt(ty), C4VInt(level), C4VInt(dwClr));
::ScriptEngine.GetPropList()->Call(P_Smoke, &pars);
}

View File

@ -146,8 +146,4 @@ protected:
#define C4Fx_FirePriority 100
#define C4Fx_FireTimer 1
// some other hardcoded engine effects
void Splash(int32_t tx, int32_t ty, int32_t amt, C4Object *pByObj);
void Smoke(int32_t tx, int32_t ty, int32_t level, DWORD dwClr=0);
#endif

View File

@ -632,6 +632,13 @@ C4MaterialReaction *C4MaterialMap::GetReaction(int32_t iPXSMat, int32_t iLandsca
return GetReactionUnsafe(iPXSMat, iLandscapeMat);
}
static void Smoke(int32_t tx, int32_t ty, int32_t level)
{
// Use scripted function (global func Smoke) to create smoke
// Caution: This makes engine internal smoking a synced call.
C4AulParSet pars(C4VInt(tx), C4VInt(ty), C4VInt(level));
::ScriptEngine.GetPropList()->Call(P_Smoke, &pars);
}
bool mrfInsertCheck(int32_t &iX, int32_t &iY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, bool *pfPosChanged)
{

View File

@ -435,8 +435,8 @@ void C4Object::DoMovement()
{
if (!InLiquid) // Enter liquid
{
if (OCF & OCF_HitSpeed2) if (Mass>3)
Splash(GetX(),GetY()+1,std::min(Shape.Wdt*Shape.Hgt/10,20),this);
if (OCF & OCF_HitSpeed2)
if (Mass>3) Splash();
fNoAttach=false;
InLiquid=1;
}

View File

@ -24,6 +24,7 @@
#include <C4Effect.h>
#include <C4ObjectInfo.h>
#include <C4Physics.h>
#include <C4PXS.h>
#include <C4ObjectCom.h>
#include <C4Command.h>
#include <C4Viewport.h>
@ -4783,6 +4784,53 @@ bool C4Object::AdjustWalkRotation(int32_t iRangeX, int32_t iRangeY, int32_t iSpe
return true;
}
static void BubbleOut(int32_t tx, int32_t ty)
{
// No bubbles from nowhere
if (!GBackSemiSolid(tx,ty)) return;
// Enough bubbles out there already
if (::Objects.ObjectCount(C4ID::Bubble) >= 150) return;
// Create bubble
Game.CreateObject(C4ID::Bubble,NULL,NO_OWNER,tx,ty);
}
void C4Object::Splash()
{
int32_t tx = GetX(); int32_t ty = GetY()+1;
int32_t amt = std::min(Shape.Wdt*Shape.Hgt/10,20);
// Splash only if there is free space above
if (GBackSemiSolid(tx, ty - 15)) return;
// get back mat
int32_t iMat = GBackMat(tx, ty);
// check liquid
if (MatValid(iMat))
if (DensityLiquid(::MaterialMap.Map[iMat].Density) && ::MaterialMap.Map[iMat].Instable)
{
int32_t sy = ty;
while (GBackLiquid(tx, sy) && sy > ty - 20 && sy >= 0) sy--;
// Splash bubbles and liquid
for (int32_t cnt=0; cnt<amt; cnt++)
{
int32_t bubble_x = tx+Random(16)-8;
int32_t bubble_y = ty+Random(16)-6;
BubbleOut(bubble_x,bubble_y);
if (GBackLiquid(tx,ty) && !GBackSemiSolid(tx, sy))
{
C4Real xdir = C4REAL100(Random(151)-75);
C4Real ydir = C4REAL100(-Random(200));
::PXS.Create(::Landscape.ExtractMaterial(tx,ty,false),
itofix(tx),itofix(sy),
xdir,
ydir);
}
}
}
// Splash sound
if (amt>=20)
StartSoundEffect("Liquids::Splash2", false, 50, this);
else if (amt>1) StartSoundEffect("Liquids::Splash1", false, 50, this);
}
void C4Object::UpdateInLiquid()
{
// InLiquid check
@ -4790,8 +4838,8 @@ void C4Object::UpdateInLiquid()
{
if (!InLiquid) // Enter liquid
{
if (OCF & OCF_HitSpeed2) if (Mass>3)
Splash(GetX(),GetY()+1,std::min(Shape.Wdt*Shape.Hgt/10,20),this);
if (OCF & OCF_HitSpeed2)
if (Mass>3) Splash();
InLiquid=1;
}
}

View File

@ -119,6 +119,7 @@ class C4Object: public C4PropListNumbered
{
private:
void UpdateInMat();
void Splash();
public:
C4Object();
~C4Object();