OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4GameScript.cpp File Reference
Include dependency graph for C4GameScript.cpp:

Go to the source code of this file.

Classes

class  C4ValueCompiler
 
class  C4ValueGetCompiler
 
struct  PathInfo
 
struct  SumPathLength
 

Macros

#define F(f)   ::AddFunc(p, #f, Fn##f)
 

Functions

C4Effect ** FnGetEffectsFor (C4PropList *pTarget)
 
C4FindObjectCreateCriterionsFromPars (C4Value *pPars, C4FindObject **pFOs, C4SortObject **pSOs, const C4Object *context)
 
C4ObjectFnPlaceVegetation (C4PropList *_this, C4PropList *Def, long iX, long iY, long iWdt, long iHgt, long iGrowth, C4PropList *shape)
 
C4ObjectFnPlaceAnimal (C4PropList *_this, C4PropList *Def)
 
C4ObjectFnObject (C4PropList *_this, long iNumber)
 
template<class T >
C4Value GetValByStdCompiler (const char *strEntry, const char *strSection, int iEntryNr, const T &rFrom)
 
bool SimFlight (C4Real &x, C4Real &y, C4Real &xdir, C4Real &ydir, int32_t iDensityMin, int32_t iDensityMax, int32_t &iIter)
 
void InitGameFunctionMap (C4AulScriptEngine *pEngine)
 

Variables

C4ScriptConstDef C4ScriptGameConstMap []
 
C4ScriptFnDef C4ScriptGameFnMap []
 

Class Documentation

struct PathInfo

Definition at line 2051 of file C4GameScript.cpp.

Class Members
long ilen
long ilx
long ily

Macro Definition Documentation

#define F (   f)    ::AddFunc(p, #f, Fn##f)

Referenced by InitGameFunctionMap().

Function Documentation

C4FindObject* CreateCriterionsFromPars ( C4Value pPars,
C4FindObject **  pFOs,
C4SortObject **  pSOs,
const C4Object context 
)

Definition at line 251 of file C4GameScript.cpp.

References C4AUL_MAX_Par, C4FindObject::CreateByValue(), iCnt, C4Object::Layer, and C4FindObject::SetSort().

252 {
253  int i, iCnt = 0, iSortCnt = 0;
254  bool has_layer_check = false;
255  // Read all parameters
256  for (i = 0; i < C4AUL_MAX_Par; i++)
257  {
258  C4Value Data = *(pPars++);
259  // No data given?
260  if (!Data) break;
261  // Construct
262  C4SortObject *pSO = nullptr;
263  C4FindObject *pFO = C4FindObject::CreateByValue(Data, pSOs ? &pSO : nullptr, context, &has_layer_check);
264  // Add FindObject
265  if (pFO)
266  {
267  pFOs[iCnt++] = pFO;
268  }
269  // Add SortObject
270  if (pSO)
271  {
272  pSOs[iSortCnt++] = pSO;
273  }
274  }
275  // No criterions?
276  if (!iCnt)
277  {
278  for (i = 0; i < iSortCnt; ++i) delete pSOs[i];
279  return nullptr;
280  }
281  // Implicit layer check
282  if (context && !has_layer_check)
283  {
284  pFOs[iCnt++] = new C4FindObjectLayer(context->Layer);
285  }
286  // create sort criterion
287  C4SortObject *pSO = nullptr;
288  if (iSortCnt)
289  {
290  if (iSortCnt == 1)
291  pSO = pSOs[0];
292  else
293  pSO = new C4SortObjectMultiple(iSortCnt, pSOs, false);
294  }
295  // Create search object
296  C4FindObject *pFO;
297  if (iCnt == 1)
298  pFO = pFOs[0];
299  else
300  pFO = new C4FindObjectAnd(iCnt, pFOs, false);
301  if (pSO) pFO->SetSort(pSO);
302  return pFO;
303 }
static C4FindObject * CreateByValue(const C4Value &Data, C4SortObject **ppSortObj=nullptr, const C4Object *context=nullptr, bool *has_layer_check=nullptr)
C4ObjectPtr Layer
Definition: C4Object.h:136
void SetSort(C4SortObject *pToSort)
#define C4AUL_MAX_Par
Definition: C4AulFunc.h:26
int iCnt
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

C4Effect** FnGetEffectsFor ( C4PropList pTarget)

Definition at line 51 of file C4GameScript.cpp.

52 {
53  if (pTarget)
54  {
55  if (pTarget == ScriptEngine.GetPropList())
57  if (pTarget == GameScript.ScenPropList.getPropList())
59  C4Object * Obj = pTarget->GetObject();
60  if (!Obj)
61  throw C4AulExecError("Effect target has to be an object");
62  return &Obj->pEffects;
63  }
65 }
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
C4GameScriptHost GameScript
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
virtual C4Object * GetObject()
Definition: C4PropList.cpp:667
C4Value ScenPropList
Definition: C4ScriptHost.h:163
C4Effect * pScenarioEffects
Definition: C4ScriptHost.h:165
C4Effect * pGlobalEffects
Definition: C4Aul.h:144
C4PropList * getPropList() const
Definition: C4Value.h:116
C4Object* FnObject ( C4PropList _this,
long  iNumber 
)

Definition at line 1303 of file C4GameScript.cpp.

References Objects, and C4GameObjects::SafeObjectPointer().

1304 {
1306  // See FnObjectNumber
1307 }
C4Object * SafeObjectPointer(int32_t iNumber)
C4GameObjects Objects
Definition: C4Globals.cpp:48

Here is the call graph for this function:

C4Object* FnPlaceAnimal ( C4PropList _this,
C4PropList Def 
)

Definition at line 771 of file C4GameScript.cpp.

References Game, and C4Game::PlaceAnimal().

772 {
773  return Game.PlaceAnimal(Def? Def : _this);
774 }
C4Game Game
Definition: C4Globals.cpp:52
C4Object * PlaceAnimal(C4PropList *def)
Definition: C4Game.cpp:2772

Here is the call graph for this function:

C4Object* FnPlaceVegetation ( C4PropList _this,
C4PropList Def,
long  iX,
long  iY,
long  iWdt,
long  iHgt,
long  iGrowth,
C4PropList shape 
)

Definition at line 752 of file C4GameScript.cpp.

References C4VPropList(), Game, C4Object::GetX(), C4Object::GetY(), C4PropList::New(), Object(), and C4Game::PlaceVegetation().

753 {
754  if (shape)
755  {
756  // New-style call with scripted shape
757  C4PropList *out_pos = C4PropList::New(nullptr);
758  C4Value vout_pos = C4VPropList(out_pos);
759  return Game.PlaceVegetation(Def, iX, iY, iWdt, iHgt, iGrowth, shape, out_pos);
760  }
761  else
762  {
763  // Call in old-style shape
764  // Local call: relative coordinates
765  if (Object(_this)) { iX += Object(_this)->GetX(); iY += Object(_this)->GetY(); }
766  // Place vegetation
767  return Game.PlaceVegetation(Def, iX, iY, iWdt, iHgt, iGrowth, nullptr, nullptr);
768  }
769 }
int32_t GetY() const
Definition: C4Object.h:287
C4Game Game
Definition: C4Globals.cpp:52
C4Value C4VPropList(C4PropList *p)
Definition: C4Value.h:245
int32_t GetX() const
Definition: C4Object.h:286
C4Object * Object(C4PropList *_this)
Definition: C4AulDefFunc.h:34
C4Object * PlaceVegetation(C4PropList *def, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, int32_t iGrowth, C4PropList *shape_proplist, C4PropList *out_pos_proplist)
Definition: C4Game.cpp:2649
static C4PropList * New(C4PropList *prototype=nullptr)
Definition: C4PropList.cpp:64

Here is the call graph for this function:

template<class T >
C4Value GetValByStdCompiler ( const char *  strEntry,
const char *  strSection,
int  iEntryNr,
const T &  rFrom 
)

Definition at line 1579 of file C4GameScript.cpp.

References C4VNull, StdCompiler::Decompile(), and C4ValueGetCompiler::getResult().

1580 {
1581  // Set up name array, create compiler
1582  const char *szNames[2] = { strSection ? strSection : strEntry, strSection ? strEntry : nullptr };
1583  C4ValueGetCompiler Comp(szNames, strSection ? 2 : 1, iEntryNr);
1584 
1585  // Compile
1586  try
1587  {
1588  Comp.Decompile(rFrom);
1589  return Comp.getResult();
1590  }
1591  // Should not happen, catch it anyway.
1592  catch (StdCompiler::Exception *)
1593  {
1594  return C4VNull;
1595  }
1596 }
const C4Value C4VNull
Definition: C4Value.cpp:30

Here is the call graph for this function:

void InitGameFunctionMap ( C4AulScriptEngine pEngine)

Definition at line 2752 of file C4GameScript.cpp.

References AddFunc(), C4V_Int, F, GBackLiquid(), GBackSemiSolid(), GBackSolid(), C4AulScriptEngine::GetPropList(), Hostile(), C4ScriptConstDef::Identifier, Object(), PathFree(), C4AulScriptEngine::RegisterGlobalConstant(), and SimFlight().

Referenced by C4Game::InitScriptEngine().

2753 {
2754  // add all def constants (all Int)
2755  for (C4ScriptConstDef *pCDef = &C4ScriptGameConstMap[0]; pCDef->Identifier; pCDef++)
2756  {
2757  assert(pCDef->ValType == C4V_Int); // only int supported currently
2758  pEngine->RegisterGlobalConstant(pCDef->Identifier, C4VInt(pCDef->Data));
2759  }
2760  C4PropListStatic * p = pEngine->GetPropList();
2761  // add all def script funcs
2762  for (C4ScriptFnDef *pDef = &C4ScriptGameFnMap[0]; pDef->Identifier; pDef++)
2763  new C4AulDefFunc(p, pDef);
2764 #define F(f) ::AddFunc(p, #f, Fn##f)
2765  F(GetX);
2766  F(GetY);
2767  F(GetDefinition);
2768  F(GetDefinitionGroupPath);
2769  F(GetPlayerName);
2770  F(GetPlayerType);
2771  F(GetPlayerColor);
2772  F(GetPlrClonkSkin);
2773  F(CreateObject);
2774  F(CreateObjectAbove);
2775  F(CreateConstruction);
2776  F(FindConstructionSite);
2777  F(CheckConstructionSite);
2778  F(Sound);
2779  F(SoundAt);
2780  F(ChangeSoundModifier);
2781  F(SetGlobalSoundModifier);
2782  F(Music);
2783  F(MusicLevel);
2784  F(SetPlayList);
2785  F(SetPlrView);
2786  F(SetPlrKnowledge);
2787  F(GetPlrViewMode);
2788  F(ResetCursorView);
2789  F(GetPlrView);
2790  F(GetWealth);
2791  F(SetWealth);
2792  F(DoPlayerScore);
2793  F(GetPlayerScore);
2794  F(GetPlayerScoreGain);
2795  F(GetWind);
2796  F(SetWind);
2797  F(GetTemperature);
2798  F(SetTemperature);
2799  F(ShakeFree);
2800  F(DigFree);
2801  F(DigFreeRect);
2802  F(ClearFreeRect);
2803  F(Hostile);
2804  F(SetHostility);
2805  F(PlaceVegetation);
2806  F(PlaceAnimal);
2807  F(GameOver);
2808  F(GetHiRank);
2809  F(GetCrew);
2810  F(GetCrewCount);
2811  F(GetPlayerCount);
2812  F(GetPlayerByIndex);
2813  F(EliminatePlayer);
2814  F(SurrenderPlayer);
2815  F(GetLeagueScore);
2816  F(SetLeaguePerformance);
2817  F(SetLeagueProgressData);
2818  F(GetLeagueProgressData);
2819  F(CreateScriptPlayer);
2820  F(GetCursor);
2821  F(GetViewCursor);
2822  F(SetCursor);
2823  F(SetViewCursor);
2824  F(GetMaterial);
2825  F(GetBackMaterial);
2826  F(GetTexture);
2827  F(GetBackTexture);
2828  F(GetAverageTextureColor);
2829  F(GetMaterialCount);
2830  F(GBackSolid);
2831  F(GBackSemiSolid);
2832  F(GBackLiquid);
2833  F(GBackSky);
2834  F(Material);
2835  F(BlastFree);
2836  F(InsertMaterial);
2837  F(CanInsertMaterial);
2838  F(LandscapeWidth);
2839  F(LandscapeHeight);
2840  F(SetAmbientBrightness);
2841  F(GetAmbientBrightness);
2842  F(SetSeason);
2843  F(GetSeason);
2844  F(SetClimate);
2845  F(GetClimate);
2846  F(SetPlayerZoomByViewRange);
2847  F(GetPlayerZoomLimits);
2848  F(SetPlayerZoom);
2849  F(SetPlayerViewLock);
2850  F(DoBaseMaterial);
2851  F(DoBaseProduction);
2852  F(GainMissionAccess);
2853  F(IsNetwork);
2854  F(IsEditor);
2855  F(GetLeague);
2856  ::AddFunc(p, "TestMessageBoard", FnTestMessageBoard, false);
2857  ::AddFunc(p, "CallMessageBoard", FnCallMessageBoard, false);
2858  ::AddFunc(p, "AbortMessageBoard", FnAbortMessageBoard, false);
2859  F(SetFoW);
2860  F(SetMaxPlayer);
2861  F(Object);
2862  F(GetTime);
2863  F(GetMissionAccess);
2864  F(MaterialName);
2865  F(DrawMap);
2866  F(DrawDefMap);
2867  F(CreateParticle);
2868  F(ClearParticles);
2869  F(SetSky);
2870  F(SetSkyAdjust);
2871  F(SetMatAdjust);
2872  F(GetSkyAdjust);
2873  F(GetMatAdjust);
2874  F(SetSkyParallax);
2875  F(ReloadDef);
2876  F(ReloadParticle);
2877  F(SetGamma);
2878  F(ResetGamma);
2879  F(AddFragmentShader);
2880  F(RemoveShader);
2881  F(FrameCounter);
2882  F(DrawMaterialQuad);
2883  F(SetFilmView);
2884  F(AddMsgBoardCmd);
2885  ::AddFunc(p, "SetGameSpeed", FnSetGameSpeed, false);
2886  ::AddFunc(p, "DrawMatChunks", FnDrawMatChunks, false);
2887  F(GetPathLength);
2888  F(SetTextureIndex);
2889  F(RemoveUnusedTexMapEntries);
2890  F(SimFlight);
2891  F(LoadScenarioSection);
2892  F(SetViewOffset);
2893  ::AddFunc(p, "SetPreSend", FnSetPreSend, false);
2894  F(GetPlayerID);
2895  F(GetPlayerTeam);
2896  F(SetPlayerTeam);
2897  F(GetScriptPlayerExtraID);
2898  F(GetTeamConfig);
2899  F(GetTeamName);
2900  F(GetTeamColor);
2901  F(GetTeamByIndex);
2902  F(GetTeamCount);
2903  ::AddFunc(p, "InitScenarioPlayer", FnInitScenarioPlayer, false);
2904  F(SetScoreboardData);
2905  ::AddFunc(p, "GetScoreboardString", FnGetScoreboardString, false);
2906  ::AddFunc(p, "GetScoreboardData", FnGetScoreboardData, false);
2907  F(DoScoreboardShow);
2908  F(SortScoreboard);
2909  F(AddEvaluationData);
2910  F(HideSettlementScoreInEvaluation);
2911  F(ExtractMaterialAmount);
2912  F(CustomMessage);
2913  F(GuiOpen);
2914  F(GuiUpdateTag);
2915  F(GuiClose);
2916  F(GuiUpdate);
2917  ::AddFunc(p, "PauseGame", FnPauseGame, false);
2918  F(PathFree);
2919  F(PathFree2);
2920  F(SetNextMission);
2921  F(GetPlayerControlState);
2922  F(SetPlayerControlEnabled);
2923  F(GetPlayerControlEnabled);
2924  F(GetPlayerControlAssignment);
2925  F(PlayRumble);
2926  F(StopRumble);
2927  F(GetStartupPlayerCount);
2928  F(GetStartupTeamCount);
2929  F(EditCursor);
2930  F(GainScenarioAchievement);
2931  F(GetPXSCount);
2932  F(GetPlrKnowledge);
2933  F(GetBaseMaterial);
2934  F(GetBaseProduction);
2935  F(GetDefCoreVal);
2936  F(GetObjectVal);
2937  F(GetObjectInfoCoreVal);
2938  F(GetScenarioVal);
2939  F(GetPlayerVal);
2940  F(GetPlayerInfoCoreVal);
2941  F(GetMaterialVal);
2942  F(SetPlrExtraData);
2943  F(GetPlrExtraData);
2944  F(PV_Linear);
2945  F(PV_Random);
2946  F(PV_Direction);
2947  F(PV_Step);
2948  F(PV_Speed);
2949  F(PV_Wind);
2950  F(PV_Gravity);
2951  // F(PV_KeyFrames); added below
2952  F(PV_Sin);
2953  F(PV_Cos);
2954  F(PC_Die);
2955  F(PC_Bounce);
2956  F(PC_Stop);
2957  F(IncinerateLandscape);
2958  F(GetGravity);
2959  F(SetGravity);
2960  F(GetTranslatedString);
2961 #undef F
2962 }
void RegisterGlobalConstant(const char *szName, const C4Value &rValue)
bool SimFlight(C4Real &x, C4Real &y, C4Real &xdir, C4Real &ydir, int32_t iDensityMin, int32_t iDensityMax, int32_t &iIter)
Definition: C4Movement.cpp:610
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
C4Value C4VInt(int32_t i)
Definition: C4Value.h:242
#define F(f)
const char * Identifier
Definition: C4AulDefFunc.h:276
C4ScriptFnDef C4ScriptGameFnMap[]
int32_t Hostile(int32_t plr1, int32_t plr2)
bool PathFree(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
C4Object * Object(C4PropList *_this)
Definition: C4AulDefFunc.h:34
const char * Identifier
Definition: C4AulDefFunc.h:268
bool GBackSemiSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:236
C4ScriptConstDef C4ScriptGameConstMap[]
void AddFunc(C4PropListStatic *Parent, const char *Name, RType(*pFunc)(ThisType *, ParTypes...), bool Public=true)
Definition: C4AulDefFunc.h:260
bool GBackLiquid(int32_t x, int32_t y)
Definition: C4Landscape.h:241
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:231

Here is the call graph for this function:

Here is the caller graph for this function:

bool SimFlight ( C4Real x,
C4Real y,
C4Real xdir,
C4Real ydir,
int32_t  iDensityMin,
int32_t  iDensityMax,
int32_t &  iIter 
)

Definition at line 610 of file C4Movement.cpp.

References fixtoi(), GBackDensity(), C4Landscape::GetHeight(), C4Landscape::GetWidth(), GravAccel, Inside(), itofix(), Landscape, and Sign().

Referenced by InitGameFunctionMap(), and SimFlightHitsLiquid().

611 {
612  bool hitOnTime = true;
613  bool fBreak = false;
614  int32_t ctcox,ctcoy,cx,cy,i;
615  cx = fixtoi(x); cy = fixtoi(y);
616  i = iIter;
617  do
618  {
619  if (!--i) {hitOnTime = false; break;}
620  // If the object isn't moving and there is no gravity either, abort
621  if (xdir == 0 && ydir == 0 && GravAccel == 0)
622  return false;
623  // If the object is above the landscape flying upwards in no/negative gravity, abort
624  if (ydir <= 0 && GravAccel <= 0 && cy < 0)
625  return false;
626  // Set target position by momentum
627  x+=xdir; y+=ydir;
628  // Movement to target
629  ctcox=fixtoi(x); ctcoy=fixtoi(y);
630  // Bounds
631  if (!Inside<int32_t>(ctcox,0,::Landscape.GetWidth()) || (ctcoy>=::Landscape.GetHeight()))
632  return false;
633  // Move to target
634  do
635  {
636  // Set next step target
637  cx+=Sign(ctcox-cx); cy+=Sign(ctcoy-cy);
638  // Contact check
639  if (Inside(GBackDensity(cx,cy), iDensityMin, iDensityMax))
640  { fBreak = true; break; }
641  }
642  while ((cx!=ctcox) || (cy!=ctcoy));
643  // Adjust GravAccel once per frame
644  ydir+=GravAccel;
645  }
646  while (!fBreak);
647  // write position back
648  x = itofix(cx); y = itofix(cy);
649 
650  // how many steps did it take to get here?
651  iIter -= i;
652 
653  return hitOnTime;
654 }
#define GravAccel
Definition: C4Physics.h:27
int Sign(T val)
Definition: Standard.h:45
C4Landscape Landscape
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
int32_t GetHeight() const
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:226
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

C4ScriptConstDef C4ScriptGameConstMap

Definition at line 2964 of file C4GameScript.cpp.

C4ScriptFnDef C4ScriptGameFnMap
Initial value:
=
{
{ "FindObject", true, C4V_Object, { C4V_Array ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnFindObject },
{ "FindObjects", true, C4V_Array, { C4V_Array ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnFindObjects },
{ "ObjectCount", true, C4V_Int, { C4V_Array ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnObjectCount },
{ "GameCallEx", true, C4V_Any, { C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnGameCallEx },
{ "PlayerMessage", true, C4V_Int, { C4V_Int ,C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnPlayerMessage },
{ "Message", true, C4V_Bool, { C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnMessage },
{ "AddMessage", true, C4V_Bool, { C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnAddMessage },
{ "PV_KeyFrames", true, C4V_Array, { C4V_Int ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnPV_KeyFrames },
{ nullptr, false, C4V_Nil, { C4V_Nil ,C4V_Nil ,C4V_Nil ,C4V_Nil ,C4V_Nil ,C4V_Nil ,C4V_Nil ,C4V_Nil ,C4V_Nil ,C4V_Nil}, nullptr }
}

Definition at line 3102 of file C4GameScript.cpp.