2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
2011-03-04 12:49:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 1998 - 2000 , Matthes Bender
* Copyright ( c ) 2001 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright ( c ) 2009 - 2016 , The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* To redistribute this file separately , substitute the full license texts
* for the above references .
2009-05-08 13:28:41 +00:00
*/
/* Functions mapped by C4Script */
2016-04-03 18:07:56 +00:00
# include "C4Include.h"
# include "game/C4GameScript.h"
2009-05-08 13:28:41 +00:00
2016-04-03 18:07:56 +00:00
# include "game/C4Application.h"
# include "script/C4AulDefFunc.h"
# include "object/C4Command.h"
# include "object/C4DefList.h"
# include "editor/C4Console.h"
# include "game/C4Game.h"
# include "object/C4GameObjects.h"
# include "control/C4GameControl.h"
# include "gui/C4GameMessage.h"
# include "platform/C4GamePadCon.h"
# include "game/C4GraphicsSystem.h"
# include "lib/C4Log.h"
# include "gui/C4MessageInput.h"
# include "gui/C4ScriptGuiWindow.h"
# include "gui/C4MouseControl.h"
# include "player/C4Player.h"
# include "player/C4PlayerList.h"
# include "landscape/C4PXS.h"
# include "control/C4RoundResults.h"
# include "landscape/C4Texture.h"
# include "landscape/C4Weather.h"
# include "game/C4Viewport.h"
# include "landscape/fow/C4FoW.h"
2016-04-02 15:50:49 +00:00
# include "landscape/C4Landscape.h"
# include "landscape/C4Sky.h"
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2015-10-09 20:24:16 +00:00
static bool FnIncinerateLandscape ( C4PropList * _this , long iX , long iY , long caused_by_plr )
2009-08-16 13:18:07 +00:00
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) ) { iX + = Object ( _this ) - > GetX ( ) ; iY + = Object ( _this ) - > GetY ( ) ; }
2015-10-09 20:24:16 +00:00
return ! ! : : Landscape . Incinerate ( iX , iY , caused_by_plr ) ;
2009-08-16 13:18:07 +00:00
}
2009-08-15 18:50:32 +00:00
2016-01-03 01:39:11 +00:00
static void FnSetGravity ( C4PropList * _this , long iGravity )
2009-08-16 13:18:07 +00:00
{
2016-04-02 15:50:49 +00:00
: : Landscape . SetGravity ( C4REAL100 ( Clamp < long > ( iGravity , - 1000 , 1000 ) ) ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetGravity ( C4PropList * _this )
2009-08-16 13:18:07 +00:00
{
2016-04-02 15:50:49 +00:00
return fixtoi ( : : Landscape . GetGravity ( ) * 100 ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static C4String * FnGetPlayerName ( C4PropList * _this , long iPlayer )
2009-08-16 13:18:07 +00:00
{
2011-01-20 00:57:44 +00:00
if ( ! ValidPlr ( iPlayer ) ) return NULL ;
return String ( : : Players . Get ( iPlayer ) - > GetName ( ) ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetPlayerType ( C4PropList * _this , long iPlayer )
2009-08-16 13:18:07 +00:00
{
2011-01-20 00:57:44 +00:00
C4Player * pPlr = : : Players . Get ( iPlayer ) ;
if ( ! pPlr ) return 0 ;
return pPlr - > GetType ( ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetPlayerColor ( C4PropList * _this , long iPlayer )
2009-08-16 13:18:07 +00:00
{
2011-01-20 00:57:44 +00:00
C4Player * plr = : : Players . Get ( iPlayer ) ;
return plr ? plr - > ColorDw : 0 ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static Nillable < long > FnGetPlrClonkSkin ( C4PropList * _this , long iPlayer )
2012-01-29 02:17:00 +00:00
{
C4Player * plr = : : Players . Get ( iPlayer ) ;
2012-05-12 18:49:53 +00:00
if ( plr )
return plr - > PrefClonkSkin ;
return C4Void ( ) ;
2012-01-29 02:17:00 +00:00
}
2012-05-15 01:03:47 +00:00
static Nillable < long > FnGetX ( C4PropList * _this , long iPrec )
2009-08-16 13:18:07 +00:00
{
2012-05-15 01:03:47 +00:00
if ( ! Object ( _this ) ) return C4Void ( ) ;
2011-01-20 00:57:44 +00:00
if ( ! iPrec ) iPrec = 1 ;
2012-05-15 01:03:47 +00:00
return fixtoi ( Object ( _this ) - > fix_x , iPrec ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static Nillable < long > FnGetY ( C4PropList * _this , long iPrec )
2009-08-16 13:18:07 +00:00
{
2012-05-15 01:03:47 +00:00
if ( ! Object ( _this ) ) return C4Void ( ) ;
2011-01-20 00:57:44 +00:00
if ( ! iPrec ) iPrec = 1 ;
2012-05-15 01:03:47 +00:00
return fixtoi ( Object ( _this ) - > fix_y , iPrec ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2015-01-10 09:14:02 +00:00
static C4Object * FnCreateObjectAbove ( C4PropList * _this ,
2010-03-28 18:58:01 +00:00
C4PropList * PropList , long iXOffset , long iYOffset , Nillable < long > owner )
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) ) // Local object calls override
2010-03-28 18:58:01 +00:00
{
2015-01-11 21:04:35 +00:00
iXOffset + = Object ( _this ) - > GetX ( ) ;
iYOffset + = Object ( _this ) - > GetY ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2009-07-25 23:12:10 +00:00
long iOwner = owner ;
if ( owner . IsNil ( ) )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) )
iOwner = Object ( _this ) - > Controller ;
2009-07-25 23:12:10 +00:00
else
iOwner = NO_OWNER ;
2010-03-28 18:58:01 +00:00
}
2009-07-25 23:12:10 +00:00
2015-01-11 21:04:35 +00:00
C4Object * pNewObj = Game . CreateObject ( PropList , Object ( _this ) , iOwner , iXOffset , iYOffset ) ;
2009-05-08 13:28:41 +00:00
// Set initial controller to creating controller, so more complicated cause-effect-chains can be traced back to the causing player
2012-05-15 01:03:47 +00:00
if ( pNewObj & & Object ( _this ) & & Object ( _this ) - > Controller > NO_OWNER ) pNewObj - > Controller = Object ( _this ) - > Controller ;
2009-05-08 13:28:41 +00:00
return pNewObj ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2015-01-10 09:14:02 +00:00
static C4Object * FnCreateObject ( C4PropList * _this ,
C4PropList * PropList , long iXOffset , long iYOffset , Nillable < long > owner )
{
2015-01-11 21:04:35 +00:00
if ( Object ( _this ) ) // Local object calls override
{
iXOffset + = Object ( _this ) - > GetX ( ) ;
iYOffset + = Object ( _this ) - > GetY ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2009-07-25 23:12:10 +00:00
long iOwner = owner ;
if ( owner . IsNil ( ) )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) )
iOwner = Object ( _this ) - > Controller ;
2009-07-25 23:12:10 +00:00
else
iOwner = NO_OWNER ;
2010-03-28 18:58:01 +00:00
}
2009-07-25 23:12:10 +00:00
2015-01-11 21:04:35 +00:00
C4Object * pNewObj = Game . CreateObject ( PropList , Object ( _this ) , iOwner , iXOffset , iYOffset , 0 , true ) ;
2009-05-08 13:28:41 +00:00
// Set initial controller to creating controller, so more complicated cause-effect-chains can be traced back to the causing player
2012-05-15 01:03:47 +00:00
if ( pNewObj & & Object ( _this ) & & Object ( _this ) - > Controller > NO_OWNER ) pNewObj - > Controller = Object ( _this ) - > Controller ;
2009-05-08 13:28:41 +00:00
return pNewObj ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2015-01-11 21:04:35 +00:00
2012-05-15 01:03:47 +00:00
static C4Object * FnCreateConstruction ( C4PropList * _this ,
2010-03-28 18:58:01 +00:00
C4PropList * PropList , long iXOffset , long iYOffset , Nillable < long > owner ,
long iCompletion , bool fTerrain , bool fCheckSite )
{
2012-01-03 20:57:55 +00:00
// Make sure parameters are valid
if ( ! PropList | | ! PropList - > GetDef ( ) )
return NULL ;
2009-05-08 13:28:41 +00:00
// Local object calls override position offset, owner
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
iXOffset + = Object ( _this ) - > GetX ( ) ;
iYOffset + = Object ( _this ) - > GetY ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// Check site
if ( fCheckSite )
2012-05-15 01:03:47 +00:00
if ( ! ConstructionCheck ( PropList , iXOffset , iYOffset , Object ( _this ) ) )
2009-05-08 13:28:41 +00:00
return NULL ;
2009-07-25 23:12:10 +00:00
long iOwner = owner ;
if ( owner . IsNil ( ) )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) )
iOwner = Object ( _this ) - > Controller ;
2009-07-25 23:12:10 +00:00
else
iOwner = NO_OWNER ;
2010-03-28 18:58:01 +00:00
}
2009-07-25 23:12:10 +00:00
2009-05-08 13:28:41 +00:00
// Create site object
2012-05-15 01:03:47 +00:00
C4Object * pNewObj = Game . CreateObjectConstruction ( PropList , Object ( _this ) , iOwner , iXOffset , iYOffset , iCompletion * FullCon / 100 , fTerrain ) ;
2009-05-08 13:28:41 +00:00
// Set initial controller to creating controller, so more complicated cause-effect-chains can be traced back to the causing player
2012-05-15 01:03:47 +00:00
if ( pNewObj & & Object ( _this ) & & Object ( _this ) - > Controller > NO_OWNER ) pNewObj - > Controller = Object ( _this ) - > Controller ;
2009-05-08 13:28:41 +00:00
return pNewObj ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static C4ValueArray * FnFindConstructionSite ( C4PropList * _this , C4PropList * PropList , int32_t v1 , int32_t v2 )
2010-03-28 18:58:01 +00:00
{
2010-04-08 00:47:45 +00:00
// Get def
2010-03-27 16:05:02 +00:00
C4Def * pDef ;
2011-09-27 22:48:46 +00:00
if ( ! ( pDef = PropList - > GetDef ( ) ) ) return NULL ;
2010-03-27 16:05:02 +00:00
// Construction check at starting position
2010-04-08 00:47:45 +00:00
if ( ConstructionCheck ( PropList , v1 , v2 ) )
return NULL ;
2010-03-27 16:05:02 +00:00
// Search for real
2016-01-30 13:46:14 +00:00
bool result = ! ! FindConSiteSpot ( v1 , v2 , pDef - > Shape . Wdt , pDef - > Shape . Hgt , 20 ) ;
2010-12-04 22:48:17 +00:00
if ( ! result ) return 0 ;
2010-04-08 00:47:45 +00:00
C4ValueArray * pArray = new C4ValueArray ( 2 ) ;
pArray - > SetItem ( 0 , C4VInt ( v1 ) ) ;
pArray - > SetItem ( 1 , C4VInt ( v2 ) ) ;
return pArray ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnCheckConstructionSite ( C4PropList * _this , C4PropList * PropList , int32_t iXOffset , int32_t iYOffset )
2012-03-27 18:09:55 +00:00
{
// Make sure parameters are valid
if ( ! PropList | | ! PropList - > GetDef ( ) )
2014-04-17 17:16:24 +00:00
return false ;
2012-03-27 18:09:55 +00:00
// Local object calls override position offset, owner
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) )
2012-03-27 18:09:55 +00:00
{
2012-05-15 01:03:47 +00:00
iXOffset + = Object ( _this ) - > GetX ( ) ;
iYOffset + = Object ( _this ) - > GetY ( ) ;
2012-03-27 18:09:55 +00:00
}
// Check construction site
return ConstructionCheck ( PropList , iXOffset , iYOffset ) ;
}
2013-08-31 22:46:04 +00:00
C4FindObject * CreateCriterionsFromPars ( C4Value * pPars , C4FindObject * * pFOs , C4SortObject * * pSOs , const C4Object * context )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
int i , iCnt = 0 , iSortCnt = 0 ;
2015-09-10 00:19:45 +00:00
bool has_layer_check = false ;
2009-05-08 13:28:41 +00:00
// Read all parameters
2010-03-28 18:58:01 +00:00
for ( i = 0 ; i < C4AUL_MAX_Par ; i + + )
{
2012-05-18 18:02:25 +00:00
C4Value Data = * ( pPars + + ) ;
2009-05-08 13:28:41 +00:00
// No data given?
2010-03-28 18:58:01 +00:00
if ( ! Data ) break ;
2009-05-08 13:28:41 +00:00
// Construct
C4SortObject * pSO = NULL ;
2015-09-10 00:19:45 +00:00
C4FindObject * pFO = C4FindObject : : CreateByValue ( Data , pSOs ? & pSO : NULL , context , & has_layer_check ) ;
2009-05-08 13:28:41 +00:00
// Add FindObject
2010-03-28 18:58:01 +00:00
if ( pFO )
{
2009-05-08 13:28:41 +00:00
pFOs [ iCnt + + ] = pFO ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// Add SortObject
if ( pSO )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
pSOs [ iSortCnt + + ] = pSO ;
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// No criterions?
2010-03-28 18:58:01 +00:00
if ( ! iCnt )
{
2009-05-08 13:28:41 +00:00
for ( i = 0 ; i < iSortCnt ; + + i ) delete pSOs [ i ] ;
return NULL ;
2010-03-28 18:58:01 +00:00
}
2015-09-10 00:19:45 +00:00
// Implicit layer check
if ( context & & ! has_layer_check )
{
pFOs [ iCnt + + ] = new C4FindObjectLayer ( context - > Layer ) ;
}
2009-05-08 13:28:41 +00:00
// create sort criterion
C4SortObject * pSO = NULL ;
if ( iSortCnt )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( iSortCnt = = 1 )
pSO = pSOs [ 0 ] ;
else
pSO = new C4SortObjectMultiple ( iSortCnt , pSOs , false ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// Create search object
C4FindObject * pFO ;
2010-03-28 18:58:01 +00:00
if ( iCnt = = 1 )
2009-05-08 13:28:41 +00:00
pFO = pFOs [ 0 ] ;
else
pFO = new C4FindObjectAnd ( iCnt , pFOs , false ) ;
if ( pSO ) pFO - > SetSort ( pSO ) ;
return pFO ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static C4Value FnObjectCount ( C4PropList * _this , C4Value * pPars )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Create FindObject-structure
2015-09-10 00:19:45 +00:00
C4FindObject * pFOs [ C4AUL_MAX_Par + 1 ] ; // +1 array element to include space for implicit layer check
2013-08-31 22:46:04 +00:00
C4FindObject * pFO = CreateCriterionsFromPars ( pPars , pFOs , NULL , Object ( _this ) ) ;
2009-05-08 13:28:41 +00:00
// Error?
2010-03-28 18:58:01 +00:00
if ( ! pFO )
2015-12-07 14:15:49 +00:00
throw C4AulExecError ( " ObjectCount: No valid search criterions supplied " ) ;
2009-05-08 13:28:41 +00:00
// Search
2009-06-15 21:47:26 +00:00
int32_t iCnt = pFO - > Count ( : : Objects , : : Objects . Sectors ) ;
2009-05-08 13:28:41 +00:00
// Free
delete pFO ;
// Return
return C4VInt ( iCnt ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static C4Value FnFindObject ( C4PropList * _this , C4Value * pPars )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Create FindObject-structure
2015-09-10 00:19:45 +00:00
C4FindObject * pFOs [ C4AUL_MAX_Par ] ; // +1 array element to include space for implicit layer check
2009-05-08 13:28:41 +00:00
C4SortObject * pSOs [ C4AUL_MAX_Par ] ;
2013-08-31 22:46:04 +00:00
C4FindObject * pFO = CreateCriterionsFromPars ( pPars , pFOs , pSOs , Object ( _this ) ) ;
2009-05-08 13:28:41 +00:00
// Error?
2010-03-28 18:58:01 +00:00
if ( ! pFO )
2015-12-07 14:15:49 +00:00
throw C4AulExecError ( " FindObject: No valid search criterions supplied " ) ;
2009-05-08 13:28:41 +00:00
// Search
2009-06-15 21:47:26 +00:00
C4Object * pObj = pFO - > Find ( : : Objects , : : Objects . Sectors ) ;
2009-05-08 13:28:41 +00:00
// Free
delete pFO ;
// Return
return C4VObj ( pObj ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static C4Value FnFindObjects ( C4PropList * _this , C4Value * pPars )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Create FindObject-structure
2015-09-10 00:19:45 +00:00
C4FindObject * pFOs [ C4AUL_MAX_Par ] ; // +1 array element to include space for implicit layer check
2009-05-08 13:28:41 +00:00
C4SortObject * pSOs [ C4AUL_MAX_Par ] ;
2013-08-31 22:46:04 +00:00
C4FindObject * pFO = CreateCriterionsFromPars ( pPars , pFOs , pSOs , Object ( _this ) ) ;
2009-05-08 13:28:41 +00:00
// Error?
2010-03-28 18:58:01 +00:00
if ( ! pFO )
2015-12-07 14:15:49 +00:00
throw C4AulExecError ( " FindObjects: No valid search criterions supplied " ) ;
2009-05-08 13:28:41 +00:00
// Search
2009-06-15 21:47:26 +00:00
C4ValueArray * pResult = pFO - > FindMany ( : : Objects , : : Objects . Sectors ) ;
2009-05-08 13:28:41 +00:00
// Free
delete pFO ;
// Return
return C4VArray ( pResult ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2013-06-04 18:07:43 +00:00
static bool FnInsertMaterial ( C4PropList * _this , long mat , long x , long y , long vx , long vy , C4PropList * insert_position )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
2013-02-17 17:29:44 +00:00
int32_t insert_x = x , insert_y = y ;
2014-04-03 17:35:22 +00:00
if ( ! : : Landscape . InsertMaterial ( mat , & insert_x , & insert_y , vx , vy ) ) return false ;
2016-01-08 05:03:32 +00:00
// output insertion position if desired (may be out of landscape range)
2014-04-03 17:35:22 +00:00
if ( insert_position & & ! insert_position - > IsFrozen ( ) )
{
insert_position - > SetProperty ( P_X , C4VInt ( insert_x ) ) ;
insert_position - > SetProperty ( P_Y , C4VInt ( insert_y ) ) ;
}
2013-06-04 18:07:43 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2013-06-04 18:07:43 +00:00
static bool FnCanInsertMaterial ( C4PropList * _this , long mat , long x , long y , C4PropList * insert_position )
2013-05-30 20:11:39 +00:00
{
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
int32_t insert_x = x , insert_y = y ;
2014-04-03 17:35:22 +00:00
if ( ! : : Landscape . InsertMaterial ( mat , & insert_x , & insert_y , 0 , 0 , true ) ) return false ;
// output insertion position if desired
if ( insert_position & & ! insert_position - > IsFrozen ( ) )
{
insert_position - > SetProperty ( P_X , C4VInt ( insert_x ) ) ;
insert_position - > SetProperty ( P_Y , C4VInt ( insert_y ) ) ;
2013-02-17 17:29:44 +00:00
}
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetMaterialCount ( C4PropList * _this , long iMaterial , bool fReal )
2010-03-28 18:58:01 +00:00
{
if ( ! MatValid ( iMaterial ) ) return - 1 ;
if ( fReal | | ! : : MaterialMap . Map [ iMaterial ] . MinHeightCount )
2016-04-02 15:50:49 +00:00
return : : Landscape . GetMatCount ( iMaterial ) ;
2010-03-27 16:05:02 +00:00
else
2016-04-02 15:50:49 +00:00
return : : Landscape . GetEffectiveMatCount ( iMaterial ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetMaterial ( C4PropList * _this , long x , long y )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
2009-05-08 13:28:41 +00:00
return GBackMat ( x , y ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2015-07-14 01:02:38 +00:00
static long FnGetBackMaterial ( C4PropList * _this , long x , long y )
{
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
return : : Landscape . GetBackMat ( x , y ) ;
}
2012-05-15 01:03:47 +00:00
static C4String * FnGetTexture ( C4PropList * _this , long x , long y )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
2010-04-18 14:15:41 +00:00
2009-05-08 13:28:41 +00:00
// Get texture
2016-04-02 15:50:49 +00:00
int32_t iTex = PixCol2Tex ( : : Landscape . GetPix ( x , y ) ) ;
2010-03-28 18:58:01 +00:00
if ( ! iTex ) return NULL ;
2009-05-08 13:28:41 +00:00
// Get material-texture mapping
2009-06-05 15:09:54 +00:00
const C4TexMapEntry * pTex = : : TextureMap . GetEntry ( iTex ) ;
2010-03-28 18:58:01 +00:00
if ( ! pTex ) return NULL ;
2009-05-08 13:28:41 +00:00
// Return tex name
return String ( pTex - > GetTextureName ( ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2015-07-14 01:02:38 +00:00
static C4String * FnGetBackTexture ( C4PropList * _this , long x , long y )
{
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
// Get texture
int32_t iTex = PixCol2Tex ( : : Landscape . GetBackPix ( x , y ) ) ;
if ( ! iTex ) return NULL ;
// Get material-texture mapping
const C4TexMapEntry * pTex = : : TextureMap . GetEntry ( iTex ) ;
if ( ! pTex ) return NULL ;
// Return tex name
return String ( pTex - > GetTextureName ( ) ) ;
}
2010-04-10 12:24:38 +00:00
// Note: Might be async in case of 16<->32 bit textures!
2012-05-15 01:03:47 +00:00
static Nillable < long > FnGetAverageTextureColor ( C4PropList * _this , C4String * Texture )
2010-04-10 12:24:38 +00:00
{
// Safety
2011-03-02 23:57:38 +00:00
if ( ! Texture ) return C4Void ( ) ;
2010-04-10 12:24:38 +00:00
// Check texture
2012-10-13 14:27:15 +00:00
StdStrBuf texture_name ;
texture_name . Ref ( Texture - > GetCStr ( ) ) ;
const char * pch = strchr ( texture_name . getData ( ) , ' - ' ) ;
if ( pch ! = NULL )
{
size_t len = pch - texture_name . getData ( ) ;
texture_name . Copy ( ) ;
texture_name . SetLength ( len ) ;
}
C4Texture * Tex = : : TextureMap . GetTexture ( texture_name . getData ( ) ) ;
2011-03-02 23:57:38 +00:00
if ( ! Tex ) return C4Void ( ) ;
2010-04-10 12:24:38 +00:00
return Tex - > GetAverageColor ( ) ;
}
2012-05-15 01:03:47 +00:00
static bool FnGBackSolid ( C4PropList * _this , long x , long y )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
2009-05-08 13:28:41 +00:00
return GBackSolid ( x , y ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnGBackSemiSolid ( C4PropList * _this , long x , long y )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
2009-05-08 13:28:41 +00:00
return GBackSemiSolid ( x , y ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnGBackLiquid ( C4PropList * _this , long x , long y )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
2009-05-08 13:28:41 +00:00
return GBackLiquid ( x , y ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnGBackSky ( C4PropList * _this , long x , long y )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
2015-06-18 01:34:21 +00:00
return Landscape . GetBackPix ( x , y ) = = 0 ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2015-05-01 16:04:42 +00:00
static long FnExtractMaterialAmount ( C4PropList * _this , long x , long y , long mat , long amount , bool distant_first )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
2010-03-28 18:58:01 +00:00
long extracted = 0 ; for ( ; extracted < amount ; extracted + + )
{
2009-05-08 13:28:41 +00:00
if ( GBackMat ( x , y ) ! = mat ) return extracted ;
2015-05-01 16:04:42 +00:00
if ( : : Landscape . ExtractMaterial ( x , y , distant_first ) ! = mat ) return extracted ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
return extracted ;
}
2009-05-08 13:28:41 +00:00
2016-01-03 01:39:11 +00:00
static void FnBlastFree ( C4PropList * _this , long iX , long iY , long iLevel , Nillable < long > iCausedBy , Nillable < long > iMaxDensity )
2009-08-16 13:18:07 +00:00
{
2012-05-15 01:03:47 +00:00
if ( iCausedBy . IsNil ( ) & & Object ( _this ) ) iCausedBy = Object ( _this ) - > Controller ;
2013-03-25 23:45:44 +00:00
if ( iMaxDensity . IsNil ( ) ) iMaxDensity = C4M_Vehicle ;
2009-08-16 13:18:07 +00:00
2013-03-25 23:45:44 +00:00
: : Landscape . BlastFree ( iX , iY , iLevel , iCausedBy , Object ( _this ) , iMaxDensity ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2015-08-28 01:44:23 +00:00
static bool FnSoundAt ( C4PropList * _this , C4String * szSound , long iX , long iY , Nillable < long > iLevel , Nillable < long > iAtPlayer , long iCustomFalloffDistance , long iPitch , C4PropList * modifier_props )
2013-11-29 11:20:36 +00:00
{
// play here?
if ( ! iAtPlayer . IsNil ( ) )
{
// get player to play at
C4Player * pPlr = : : Players . Get ( iAtPlayer ) ;
// not existant? fail
if ( ! pPlr ) return false ;
// network client: don't play here
// return true for network sync
if ( ! pPlr - > LocalControl ) return true ;
}
// even less than nothing?
if ( iLevel < 0 ) return true ;
// default sound level
if ( iLevel . IsNil ( ) | | iLevel > 100 )
iLevel = 100 ;
2015-08-28 01:44:23 +00:00
// modifier from prop list
C4SoundModifier * modifier ;
if ( modifier_props )
modifier = Application . SoundSystem . Modifiers . Get ( modifier_props , true ) ;
else
modifier = NULL ;
2013-11-29 11:20:36 +00:00
// target object
C4Object * pObj = Object ( _this ) ;
if ( pObj )
{
iX + = pObj - > GetX ( ) ;
iY + = pObj - > GetY ( ) ;
}
2015-09-04 01:23:47 +00:00
StartSoundEffectAt ( FnStringPar ( szSound ) , iX , iY , iLevel , iCustomFalloffDistance , iPitch , modifier ) ;
2013-11-29 11:20:36 +00:00
// always return true (network safety!)
return true ;
}
2015-08-28 01:44:23 +00:00
static bool FnSound ( C4PropList * _this , C4String * szSound , bool fGlobal , Nillable < long > iLevel , Nillable < long > iAtPlayer , long iLoop , long iCustomFalloffDistance , long iPitch , C4PropList * modifier_props )
2009-08-16 13:18:07 +00:00
{
2009-05-08 13:28:41 +00:00
// play here?
2009-08-16 13:18:07 +00:00
if ( ! iAtPlayer . IsNil ( ) )
{
2009-05-08 13:28:41 +00:00
// get player to play at
2009-08-16 13:18:07 +00:00
C4Player * pPlr = : : Players . Get ( iAtPlayer ) ;
2009-05-08 13:28:41 +00:00
// not existant? fail
2009-08-12 20:44:09 +00:00
if ( ! pPlr ) return false ;
2009-05-08 13:28:41 +00:00
// network client: don't play here
// return true for network sync
2009-08-12 20:44:09 +00:00
if ( ! pPlr - > LocalControl ) return true ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
// even less than nothing?
2009-08-12 20:44:09 +00:00
if ( iLevel < 0 ) return true ;
2009-05-08 13:28:41 +00:00
// default sound level
2009-08-16 13:18:07 +00:00
if ( iLevel . IsNil ( ) | | iLevel > 100 )
2009-05-08 13:28:41 +00:00
iLevel = 100 ;
2015-08-28 01:44:23 +00:00
// modifier from prop list
C4SoundModifier * modifier ;
if ( modifier_props )
modifier = Application . SoundSystem . Modifiers . Get ( modifier_props , true ) ;
else
modifier = NULL ;
2009-08-16 13:18:07 +00:00
// target object
C4Object * pObj = NULL ;
2012-05-15 01:03:47 +00:00
if ( ! fGlobal ) pObj = Object ( _this ) ;
2015-08-09 22:40:42 +00:00
// play/stop?
2010-03-28 18:58:01 +00:00
if ( iLoop > = 0 )
2015-08-09 22:40:42 +00:00
{
// already playing?
C4SoundInstance * inst = GetSoundInstance ( FnStringPar ( szSound ) , pObj ) ;
if ( inst )
{
// then just update parameters
SoundUpdate ( inst , iLevel , iPitch ) ;
}
else
{
// try to play effect
2015-08-28 01:44:23 +00:00
StartSoundEffect ( FnStringPar ( szSound ) , ! ! iLoop , iLevel , pObj , iCustomFalloffDistance , iPitch , modifier ) ;
2015-08-09 22:40:42 +00:00
}
}
2009-08-16 13:18:07 +00:00
else
2015-08-09 22:40:42 +00:00
{
StopSoundEffect ( FnStringPar ( szSound ) , pObj ) ;
}
2009-05-08 13:28:41 +00:00
// always return true (network safety!)
2009-08-12 20:44:09 +00:00
return true ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2015-08-28 01:44:23 +00:00
static bool FnChangeSoundModifier ( C4PropList * _this , C4PropList * modifier_props , bool release )
{
// internal function to be used by sound library: Updates sound modifier
C4SoundModifier * modifier = Application . SoundSystem . Modifiers . Get ( modifier_props , false ) ;
// modifier not found. May be due to savegame resume.
// In that case, creation/updates will happen automatically next time Sound() is called
// always return true for sync safety because the internal C4SoundModifierList is not synchronized
if ( ! modifier ) return true ;
if ( release )
modifier - > Release ( ) ;
else
modifier - > Update ( ) ;
return true ;
}
static bool FnSetGlobalSoundModifier ( C4PropList * _this , C4PropList * modifier_props , Nillable < long > at_player )
{
// set modifier to be applied to all future sounds
if ( at_player . IsNil ( ) )
{
// no player given: Global modifier for all players.
Game . SetGlobalSoundModifier ( modifier_props ) ;
}
else
{
// modifier for all viewports of a player
C4Player * plr = : : Players . Get ( at_player ) ;
if ( ! plr ) return false ;
plr - > SetSoundModifier ( modifier_props ) ;
}
// always true on valid params for sync safety
return true ;
}
2015-09-28 00:58:37 +00:00
static bool FnMusic ( C4PropList * _this , C4String * szSongname , bool fLoop , long iFadeTime_ms , long max_resume_time_ms )
2010-03-28 18:58:01 +00:00
{
2010-01-02 16:33:58 +00:00
bool success ;
2015-09-28 00:58:37 +00:00
if ( max_resume_time_ms < 0 ) return false ; // Safety
2009-05-08 13:28:41 +00:00
if ( ! szSongname )
2010-03-28 18:58:01 +00:00
{
2010-01-02 16:33:58 +00:00
success = Application . MusicSystem . Stop ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2015-09-28 00:58:37 +00:00
success = Application . MusicSystem . Play ( FnStringPar ( szSongname ) , ! ! fLoop , iFadeTime_ms , double ( max_resume_time_ms ) / 1000.0 ) ;
2010-03-27 16:05:02 +00:00
}
2010-03-28 18:58:01 +00:00
if ( : : Control . SyncMode ( ) ) return true ;
return success ;
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnMusicLevel ( C4PropList * _this , long iLevel )
2010-03-28 18:58:01 +00:00
{
2015-10-01 02:49:47 +00:00
return : : Application . MusicSystem . SetGameMusicLevel ( iLevel ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2015-10-01 02:49:47 +00:00
static long FnSetPlayList ( C4PropList * _this , const C4Value & playlist_data , Nillable < long > iAtPlayer , bool fForceSwitch , long iFadeTime_ms , long max_resume_time_ms )
2010-03-28 18:58:01 +00:00
{
2015-09-28 00:58:37 +00:00
// Safety
if ( max_resume_time_ms < 0 ) return 0 ;
2014-08-07 15:33:36 +00:00
// If a player number is provided, set play list for clients where given player is local only
if ( ! iAtPlayer . IsNil ( ) & & iAtPlayer ! = NO_OWNER )
{
C4Player * at_plr = : : Players . Get ( iAtPlayer ) ;
if ( ! at_plr ) return 0 ;
if ( ! at_plr - > LocalControl ) return 0 ;
}
2015-10-01 02:49:47 +00:00
// Playlist might be a string for the new playlist, a proplist with more info, or nil to reset the playlist
C4String * szPlayList = playlist_data . getStr ( ) ;
C4PropList * playlist_props = NULL ;
if ( ! szPlayList )
{
playlist_props = playlist_data . getPropList ( ) ;
if ( playlist_props )
{
szPlayList = playlist_props - > GetPropertyStr ( P_PlayList ) ;
// Update playlist properties
C4Value val ;
if ( playlist_props - > GetProperty ( P_MusicBreakMin , & val ) ) : : Application . MusicSystem . SetMusicBreakMin ( val . getInt ( ) ) ;
if ( playlist_props - > GetProperty ( P_MusicBreakMax , & val ) ) : : Application . MusicSystem . SetMusicBreakMax ( val . getInt ( ) ) ;
if ( playlist_props - > GetProperty ( P_MusicBreakChance , & val ) ) : : Application . MusicSystem . SetMusicBreakChance ( val . getInt ( ) ) ;
2015-12-04 00:17:14 +00:00
if ( playlist_props - > GetProperty ( P_MusicMaxPositionMemory , & val ) ) : : Application . MusicSystem . SetMusicMaxPositionMemory ( val . getInt ( ) ) ;
2015-10-01 02:49:47 +00:00
}
}
2014-08-07 15:33:36 +00:00
// Set playlist; count entries
2015-10-01 02:49:47 +00:00
long iFilesInPlayList = : : Application . MusicSystem . SetPlayList ( FnStringPar ( szPlayList ) , fForceSwitch , iFadeTime_ms , double ( max_resume_time_ms ) / 1000.0f ) ;
2014-08-07 15:33:36 +00:00
// network/record/replay: return 0 for sync reasons
2010-03-28 18:58:01 +00:00
if ( : : Control . SyncMode ( ) ) return 0 ;
2009-05-08 13:28:41 +00:00
return iFilesInPlayList ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnGameOver ( C4PropList * _this , long iGameOverValue /* provided for future compatibility */ )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
return ! ! Game . DoGameOver ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnGainMissionAccess ( C4PropList * _this , C4String * szPassword )
2010-03-28 18:58:01 +00:00
{
2010-01-25 04:00:59 +00:00
if ( std : : strlen ( Config . General . MissionAccess ) + std : : strlen ( FnStringPar ( szPassword ) ) + 3 > CFG_MaxString ) return false ;
2009-05-08 13:28:41 +00:00
SAddModule ( Config . General . MissionAccess , FnStringPar ( szPassword ) ) ;
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-19 16:34:17 +00:00
static C4Value FnPlayerMessage ( C4PropList * _this , C4Value * Pars )
2010-03-28 18:58:01 +00:00
{
2015-12-07 14:15:49 +00:00
if ( ! Object ( _this ) ) throw NeedObjectContext ( " PlayerMessage " ) ;
2012-05-19 16:34:17 +00:00
int iPlayer = Pars [ 0 ] . getInt ( ) ;
C4String * szMessage = Pars [ 1 ] . getStr ( ) ;
2009-05-08 13:28:41 +00:00
if ( ! szMessage ) return C4VBool ( false ) ;
2012-05-19 16:34:17 +00:00
StdStrBuf buf ;
buf . SetLength ( szMessage - > GetData ( ) . getLength ( ) ) ;
2009-05-08 13:28:41 +00:00
// Speech
2009-08-15 18:50:32 +00:00
bool fSpoken = false ;
2012-05-19 16:34:17 +00:00
if ( SCopySegment ( FnStringPar ( szMessage ) , 1 , buf . getMData ( ) , ' $ ' ) )
if ( StartSoundEffect ( buf . getData ( ) , false , 100 , Object ( _this ) ) )
2009-08-15 18:50:32 +00:00
fSpoken = true ;
2009-05-08 13:28:41 +00:00
// Text
if ( ! fSpoken )
2012-05-19 16:34:17 +00:00
{
buf . Take ( FnStringFormat ( _this , szMessage , & Pars [ 2 ] , 8 ) ) ;
const char * dollar = strchr ( buf . getData ( ) , ' $ ' ) ;
if ( dollar ) buf . Shrink ( dollar - buf . getData ( ) ) ;
GameMsgObjectPlayer ( buf . getData ( ) , Object ( _this ) , iPlayer ) ;
}
2009-05-08 13:28:41 +00:00
return C4VBool ( true ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-19 16:34:17 +00:00
static C4Value FnMessage ( C4PropList * _this , C4Value * Pars )
2010-03-28 18:58:01 +00:00
{
2015-12-07 14:15:49 +00:00
if ( ! Object ( _this ) ) throw NeedObjectContext ( " Message " ) ;
2012-05-19 16:34:17 +00:00
C4String * szMessage = Pars [ 0 ] . getStr ( ) ;
2009-05-08 13:28:41 +00:00
if ( ! szMessage ) return C4VBool ( false ) ;
2012-05-19 16:34:17 +00:00
StdStrBuf buf ;
buf . SetLength ( szMessage - > GetData ( ) . getLength ( ) ) ;
2009-05-08 13:28:41 +00:00
// Speech
2009-08-15 18:50:32 +00:00
bool fSpoken = false ;
2012-05-19 16:34:17 +00:00
if ( SCopySegment ( FnStringPar ( szMessage ) , 1 , buf . getMData ( ) , ' $ ' ) )
if ( StartSoundEffect ( buf . getData ( ) , false , 100 , Object ( _this ) ) )
2009-08-15 18:50:32 +00:00
fSpoken = true ;
2009-05-08 13:28:41 +00:00
// Text
if ( ! fSpoken )
2012-05-19 16:34:17 +00:00
{
buf . Take ( FnStringFormat ( _this , szMessage , & Pars [ 1 ] , 9 ) ) ;
const char * dollar = strchr ( buf . getData ( ) , ' $ ' ) ;
if ( dollar ) buf . Shrink ( dollar - buf . getData ( ) ) ;
GameMsgObject ( buf . getData ( ) , Object ( _this ) ) ;
}
2009-05-08 13:28:41 +00:00
return C4VBool ( true ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-19 16:34:17 +00:00
static C4Value FnAddMessage ( C4PropList * _this , C4Value * Pars )
2010-03-28 18:58:01 +00:00
{
2015-12-07 14:15:49 +00:00
if ( ! Object ( _this ) ) throw NeedObjectContext ( " AddMessage " ) ;
2012-05-19 16:34:17 +00:00
C4String * szMessage = Pars [ 0 ] . getStr ( ) ;
2009-05-08 13:28:41 +00:00
if ( ! szMessage ) return C4VBool ( false ) ;
2012-05-19 16:34:17 +00:00
: : Messages . Append ( C4GM_Target , FnStringFormat ( _this , szMessage , & Pars [ 1 ] , 9 ) . getData ( ) ,
Object ( _this ) , NO_OWNER , 0 , 0 , C4RGB ( 0xff , 0xff , 0xff ) ) ;
2009-05-08 13:28:41 +00:00
return C4VBool ( true ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnMaterial ( C4PropList * _this , C4String * mat_name )
2010-03-28 18:58:01 +00:00
{
2009-06-05 18:46:03 +00:00
return : : MaterialMap . Get ( FnStringPar ( mat_name ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2015-07-31 03:13:31 +00:00
C4Object * FnPlaceVegetation ( C4PropList * _this , C4PropList * Def , long iX , long iY , long iWdt , long iHgt , long iGrowth , C4PropList * shape )
2010-03-28 18:58:01 +00:00
{
2015-07-31 03:13:31 +00:00
if ( shape )
{
// New-style call with scripted shape
C4PropList * out_pos = C4PropList : : New ( NULL ) ;
C4Value vout_pos = C4VPropList ( out_pos ) ;
return Game . PlaceVegetation ( Def , iX , iY , iWdt , iHgt , iGrowth , shape , out_pos ) ;
}
else
{
// Call in old-style shape
// Local call: relative coordinates
if ( Object ( _this ) ) { iX + = Object ( _this ) - > GetX ( ) ; iY + = Object ( _this ) - > GetY ( ) ; }
// Place vegetation
return Game . PlaceVegetation ( Def , iX , iY , iWdt , iHgt , iGrowth , NULL , NULL ) ;
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
C4Object * FnPlaceAnimal ( C4PropList * _this , C4PropList * Def )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
return Game . PlaceAnimal ( Def ? Def : _this ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnHostile ( C4PropList * _this , long iPlr1 , long iPlr2 , bool fCheckOneWayOnly )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( fCheckOneWayOnly )
2010-03-28 18:58:01 +00:00
{
2009-06-12 23:09:32 +00:00
return : : Players . HostilityDeclared ( iPlr1 , iPlr2 ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
return ! ! Hostile ( iPlr1 , iPlr2 ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetHostility ( C4PropList * _this , long iPlr , long iPlr2 , bool fHostile , bool fSilent , bool fNoCalls )
2010-03-28 18:58:01 +00:00
{
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iPlr ) ;
2009-05-08 13:28:41 +00:00
if ( ! pPlr ) return false ;
// do rejection test first
if ( ! fNoCalls )
2010-03-28 18:58:01 +00:00
{
2014-05-30 23:03:23 +00:00
if ( ! ! : : Game . GRBroadcast ( PSF_RejectHostilityChange , & C4AulParSet ( iPlr , iPlr2 , fHostile ) , true , true ) )
2009-05-08 13:28:41 +00:00
return false ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// OK; set hostility
2009-06-12 23:09:32 +00:00
bool fOldHostility = : : Players . HostilityDeclared ( iPlr , iPlr2 ) ;
2009-05-08 13:28:41 +00:00
if ( ! pPlr - > SetHostility ( iPlr2 , fHostile , fSilent ) ) return false ;
// calls afterwards
2014-05-11 21:32:22 +00:00
: : Game . GRBroadcast ( PSF_OnHostilityChange , & C4AulParSet ( C4VInt ( iPlr ) , C4VInt ( iPlr2 ) , C4VBool ( fHostile ) , C4VBool ( fOldHostility ) ) , true ) ;
2009-05-08 13:28:41 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2015-12-03 03:11:28 +00:00
static bool FnSetPlrView ( C4PropList * _this , long iPlr , C4Object * tobj , bool immediate_position )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return false ;
2015-12-03 03:11:28 +00:00
: : Players . Get ( iPlr ) - > SetViewMode ( C4PVM_Target , tobj , immediate_position ) ;
2010-03-27 16:05:02 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetPlrViewMode ( C4PropList * _this , long iPlr )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return - 1 ;
2009-06-15 22:06:37 +00:00
if ( : : Control . SyncMode ( ) ) return - 1 ;
2010-03-27 16:05:02 +00:00
return : : Players . Get ( iPlr ) - > ViewMode ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2016-01-03 01:39:11 +00:00
static void FnResetCursorView ( C4PropList * _this , long plr , bool immediate_position )
2010-01-04 12:59:47 +00:00
{
C4Player * pplr = : : Players . Get ( plr ) ;
2015-12-03 03:11:28 +00:00
if ( pplr ) pplr - > ResetCursorView ( immediate_position ) ;
2010-01-04 12:59:47 +00:00
}
2012-05-15 01:03:47 +00:00
static C4Object * FnGetPlrView ( C4PropList * _this , long iPlr )
2010-03-28 18:58:01 +00:00
{
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iPlr ) ;
2010-03-27 16:05:02 +00:00
if ( ! pPlr | | pPlr - > ViewMode ! = C4PVM_Target ) return NULL ;
return pPlr - > ViewTarget ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2010-09-08 21:49:42 +00:00
// flags for SetPlayerZoom* calls
static const int PLRZOOM_Direct = 0x01 ,
PLRZOOM_NoIncrease = 0x04 ,
PLRZOOM_NoDecrease = 0x08 ,
PLRZOOM_LimitMin = 0x10 ,
2014-05-11 08:30:41 +00:00
PLRZOOM_LimitMax = 0x20 ,
PLRZOOM_Set = 0x40 ;
2010-09-08 21:49:42 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetPlayerZoomByViewRange ( C4PropList * _this , long plr_idx , long range_wdt , long range_hgt , long flags )
2010-09-08 21:49:42 +00:00
{
// zoom size safety - both ranges 0 is fine, it causes a zoom reset to default
if ( range_wdt < 0 | | range_hgt < 0 ) return false ;
// special player NO_OWNER: apply to all viewports
if ( plr_idx = = NO_OWNER )
{
for ( C4Player * plr = : : Players . First ; plr ; plr = plr - > Next )
if ( plr - > Number ! = NO_OWNER ) // can't happen, but would be a crash if it did...
2012-05-15 01:03:47 +00:00
FnSetPlayerZoomByViewRange ( _this , plr - > Number , range_wdt , range_hgt , flags ) ;
2010-09-08 21:49:42 +00:00
return true ;
}
else
{
// safety check on player only, so function return result is always in sync
C4Player * plr = : : Players . Get ( plr_idx ) ;
if ( ! plr ) return false ;
// adjust values in player
2014-08-12 13:27:57 +00:00
if ( flags & PLRZOOM_LimitMin ) plr - > SetMinZoomByViewRange ( range_wdt , range_hgt , ! ! ( flags & PLRZOOM_NoIncrease ) , ! ! ( flags & PLRZOOM_NoDecrease ) ) ;
if ( flags & PLRZOOM_LimitMax ) plr - > SetMaxZoomByViewRange ( range_wdt , range_hgt , ! ! ( flags & PLRZOOM_NoIncrease ) , ! ! ( flags & PLRZOOM_NoDecrease ) ) ;
// set values after setting min/max to ensure old limits don't block new value
2014-05-11 08:30:41 +00:00
if ( ( flags & PLRZOOM_Set ) | | ! ( flags & ( PLRZOOM_LimitMin | PLRZOOM_LimitMax ) ) )
2010-09-08 21:49:42 +00:00
{
plr - > SetZoomByViewRange ( range_wdt , range_hgt , ! ! ( flags & PLRZOOM_Direct ) , ! ! ( flags & PLRZOOM_NoIncrease ) , ! ! ( flags & PLRZOOM_NoDecrease ) ) ;
}
2014-08-12 13:27:57 +00:00
2010-09-08 21:49:42 +00:00
}
return true ;
}
2014-05-11 09:10:13 +00:00
static C4PropList * FnGetPlayerZoomLimits ( C4PropList * _this , long plr_idx )
{
// get player
C4Player * plr = : : Players . Get ( plr_idx ) ;
if ( ! plr ) return NULL ;
// collect limits in a prop list
// if neither width not height is set for zoom limits, return engine defaults.
C4PropList * result = C4PropList : : New ( ) ;
if ( ! result ) return NULL ;
result - > SetPropertyByS ( : : Strings . RegString ( " MaxWidth " ) , C4VInt ( ( plr - > ZoomLimitMaxWdt | | plr - > ZoomLimitMaxHgt ) ? plr - > ZoomLimitMaxWdt : C4VP_DefMaxViewRangeX ) ) ;
result - > SetPropertyByS ( : : Strings . RegString ( " MaxHeight " ) , C4VInt ( plr - > ZoomLimitMaxHgt ) ) ;
result - > SetPropertyByS ( : : Strings . RegString ( " MaxValue " ) , C4VInt ( fixtoi ( plr - > ZoomLimitMaxVal , 100 ) ) ) ;
result - > SetPropertyByS ( : : Strings . RegString ( " MinWidth " ) , C4VInt ( ( plr - > ZoomLimitMinWdt | | plr - > ZoomLimitMinHgt ) ? plr - > ZoomLimitMinWdt : C4VP_DefMinViewRangeX ) ) ;
result - > SetPropertyByS ( : : Strings . RegString ( " MinHeight " ) , C4VInt ( plr - > ZoomLimitMinHgt ) ) ;
result - > SetPropertyByS ( : : Strings . RegString ( " MinValue " ) , C4VInt ( fixtoi ( plr - > ZoomLimitMinVal , 100 ) ) ) ;
return result ;
}
2014-04-21 17:38:05 +00:00
static bool FnSetPlayerZoom ( C4PropList * _this , long plr_idx , long zoom , long precision , long flags )
{
// parameter safety. 0/0 means "reset to default".
if ( zoom < 0 | | precision < 0 ) return false ;
// special player NO_OWNER: apply to all viewports
if ( plr_idx = = NO_OWNER )
{
for ( C4Player * plr = : : Players . First ; plr ; plr = plr - > Next )
if ( plr - > Number ! = NO_OWNER ) // can't happen, but would be a crash if it did...
FnSetPlayerZoom ( _this , plr - > Number , zoom , precision , flags ) ;
return true ;
}
else
{
// zoom factor calculation
if ( ! precision ) precision = 1 ;
C4Fixed fZoom = itofix ( zoom , precision ) ;
// safety check on player only, so function return result is always in sync
C4Player * plr = : : Players . Get ( plr_idx ) ;
if ( ! plr ) return false ;
// adjust values in player
2014-08-12 13:27:57 +00:00
if ( flags & PLRZOOM_LimitMin ) plr - > SetMinZoom ( fZoom , ! ! ( flags & PLRZOOM_NoIncrease ) , ! ! ( flags & PLRZOOM_NoDecrease ) ) ;
if ( flags & PLRZOOM_LimitMax ) plr - > SetMaxZoom ( fZoom , ! ! ( flags & PLRZOOM_NoIncrease ) , ! ! ( flags & PLRZOOM_NoDecrease ) ) ;
2014-05-11 08:30:41 +00:00
if ( ( flags & PLRZOOM_Set ) | | ! ( flags & ( PLRZOOM_LimitMin | PLRZOOM_LimitMax ) ) )
2010-09-08 21:49:42 +00:00
{
2014-05-11 08:30:41 +00:00
plr - > SetZoom ( fZoom , ! ! ( flags & PLRZOOM_Direct ) , ! ! ( flags & PLRZOOM_NoIncrease ) , ! ! ( flags & PLRZOOM_NoDecrease ) ) ;
2010-09-08 21:49:42 +00:00
}
2014-08-12 13:27:57 +00:00
2010-09-08 21:49:42 +00:00
}
return true ;
}
2012-05-15 01:03:47 +00:00
static bool FnSetPlayerViewLock ( C4PropList * _this , long plr_idx , bool is_locked )
2010-09-08 21:49:42 +00:00
{
// special player NO_OWNER: apply to all players
if ( plr_idx = = NO_OWNER )
{
for ( C4Player * plr = : : Players . First ; plr ; plr = plr - > Next )
if ( plr - > Number ! = NO_OWNER ) // can't happen, but would be a crash if it did...
2012-05-15 01:03:47 +00:00
FnSetPlayerViewLock ( _this , plr - > Number , is_locked ) ;
2010-09-08 21:49:42 +00:00
return true ;
}
C4Player * plr = : : Players . Get ( plr_idx ) ;
if ( ! plr ) return false ;
plr - > SetViewLocked ( is_locked ) ;
return true ;
}
2014-04-16 12:06:30 +00:00
static bool FnDoBaseMaterial ( C4PropList * _this , long iPlr , C4ID id , long iChange )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// validity check
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return false ;
2009-05-08 13:28:41 +00:00
C4Def * pDef = C4Id2Def ( id ) ;
if ( ! pDef ) return false ;
// add to material
2014-04-16 12:06:30 +00:00
long iLastcount = : : Players . Get ( iPlr ) - > BaseMaterial . GetIDCount ( id ) ;
return : : Players . Get ( iPlr ) - > BaseMaterial . SetIDCount ( id , iLastcount + iChange , true ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-04-16 12:06:30 +00:00
static bool FnDoBaseProduction ( C4PropList * _this , long iPlr , C4ID id , long iChange )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// validity check
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return false ;
2009-05-08 13:28:41 +00:00
C4Def * pDef = C4Id2Def ( id ) ;
if ( ! pDef ) return false ;
// add to material
2014-04-16 12:06:30 +00:00
long iLastcount = : : Players . Get ( iPlr ) - > BaseProduction . GetIDCount ( id ) ;
return : : Players . Get ( iPlr ) - > BaseProduction . SetIDCount ( id , iLastcount + iChange , true ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2015-01-13 23:33:51 +00:00
static bool FnSetPlrKnowledge ( C4PropList * _this , Nillable < long > iPlr , C4ID id , bool fRemove )
{
bool success = false ;
// iPlr == nil: Call for all players
if ( iPlr . IsNil ( ) )
{
for ( C4Player * player = : : Players . First ; player ; player = player - > Next )
2015-12-18 18:26:46 +00:00
if ( player - > SetKnowledge ( id , fRemove ) )
2015-01-13 23:33:51 +00:00
success = true ;
2010-03-27 16:05:02 +00:00
}
2015-01-13 23:33:51 +00:00
else
{
// Otherwise call for requested player
C4Player * player = : : Players . Get ( iPlr ) ;
2015-12-18 18:26:46 +00:00
if ( player ) success = player - > SetKnowledge ( id , fRemove ) ;
2015-01-13 23:33:51 +00:00
}
return success ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-20 00:04:46 +00:00
static C4Value FnGetPlrKnowledge ( C4PropList * _this , int iPlr , C4ID id , int iIndex , int dwCategory )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return C4VBool ( false ) ;
2009-05-08 13:28:41 +00:00
// Search by id, check if available, return bool
2010-03-28 18:58:01 +00:00
if ( id ) return C4VBool ( : : Players . Get ( iPlr ) - > Knowledge . GetIDCount ( id , 1 ) ! = 0 ) ;
2009-05-08 13:28:41 +00:00
// Search indexed item of given category, return C4ID
2011-02-05 22:09:09 +00:00
return C4VPropList ( C4Id2Def ( : : Players . Get ( iPlr ) - > Knowledge . GetID ( : : Definitions , dwCategory , iIndex ) ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static C4Def * FnGetDefinition ( C4PropList * _this , long iIndex )
2010-03-28 18:58:01 +00:00
{
2011-03-07 20:26:56 +00:00
return : : Definitions . GetDef ( iIndex ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-20 00:04:46 +00:00
static C4Value FnGetComponent ( C4PropList * _this , C4ID idComponent , int iIndex , C4Object * pObj , C4ID idDef )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Def component - as seen by scope object as builder
if ( idDef )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Get def
C4Def * pDef = C4Id2Def ( idDef ) ; if ( ! pDef ) return C4Value ( ) ;
// Component count
2011-07-31 00:22:29 +00:00
if ( idComponent ) return C4VInt ( pDef - > GetComponentCount ( idComponent ) ) ;
2009-05-08 13:28:41 +00:00
// Indexed component
2011-07-31 00:22:29 +00:00
return C4VPropList ( C4Id2Def ( pDef - > GetIndexedComponent ( iIndex ) ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// Object component
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Get object
2012-05-15 01:03:47 +00:00
if ( ! pObj ) pObj = Object ( _this ) ; if ( ! pObj ) return C4Value ( ) ;
2009-05-08 13:28:41 +00:00
// Component count
if ( idComponent ) return C4VInt ( pObj - > Component . GetIDCount ( idComponent ) ) ;
// Indexed component
2011-02-05 22:09:09 +00:00
return C4VPropList ( C4Id2Def ( pObj - > Component . GetID ( iIndex ) ) ) ;
2010-03-27 16:05:02 +00:00
}
2010-03-28 18:58:01 +00:00
return C4Value ( ) ;
}
2009-05-08 13:28:41 +00:00
2014-04-16 12:06:30 +00:00
static C4Value FnGetBaseMaterial ( C4PropList * _this , int iPlr , C4ID id , int iIndex , int dwCategory )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return C4VBool ( false ) ;
2009-05-08 13:28:41 +00:00
// Search by id, return available count
2014-04-16 12:06:30 +00:00
if ( id ) return C4VInt ( : : Players . Get ( iPlr ) - > BaseMaterial . GetIDCount ( id ) ) ;
2009-05-08 13:28:41 +00:00
// Search indexed item of given category, return C4ID
2014-04-16 12:06:30 +00:00
return C4VPropList ( C4Id2Def ( : : Players . Get ( iPlr ) - > BaseMaterial . GetID ( : : Definitions , dwCategory , iIndex ) ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-04-16 12:06:30 +00:00
static C4Value FnGetBaseProduction ( C4PropList * _this , int iPlr , C4ID id , int iIndex , int dwCategory )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return C4VBool ( false ) ;
2009-05-08 13:28:41 +00:00
// Search by id, return available count
2014-04-16 12:06:30 +00:00
if ( id ) return C4VInt ( : : Players . Get ( iPlr ) - > BaseProduction . GetIDCount ( id ) ) ;
2009-05-08 13:28:41 +00:00
// Search indexed item of given category, return C4ID
2014-04-16 12:06:30 +00:00
return C4VPropList ( C4Id2Def ( : : Players . Get ( iPlr ) - > BaseProduction . GetID ( : : Definitions , dwCategory , iIndex ) ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetWealth ( C4PropList * _this , long iPlr )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return 0 ;
return : : Players . Get ( iPlr ) - > Wealth ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetWealth ( C4PropList * _this , long iPlr , long iValue )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return false ;
: : Players . Get ( iPlr ) - > SetWealth ( iValue ) ;
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnDoPlayerScore ( C4PropList * _this , long iPlr , long iChange )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return false ;
2010-04-21 19:12:49 +00:00
return : : Players . Get ( iPlr ) - > DoScore ( iChange ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetPlayerScore ( C4PropList * _this , long iPlr )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return 0 ;
2010-04-21 19:12:49 +00:00
return : : Players . Get ( iPlr ) - > CurrentScore ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetPlayerScoreGain ( C4PropList * _this , long iPlr )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return 0 ;
2010-04-21 19:12:49 +00:00
return : : Players . Get ( iPlr ) - > CurrentScore - : : Players . Get ( iPlr ) - > InitialScore ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static C4Object * FnGetHiRank ( C4PropList * _this , long iPlr )
2010-03-28 18:58:01 +00:00
{
2011-09-27 22:48:46 +00:00
if ( ! ValidPlr ( iPlr ) ) return NULL ;
2010-07-30 20:38:21 +00:00
return : : Players . Get ( iPlr ) - > GetHiRankActiveCrew ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static C4Object * FnGetCrew ( C4PropList * _this , long iPlr , long index )
2010-03-28 18:58:01 +00:00
{
2011-09-27 22:48:46 +00:00
if ( ! ValidPlr ( iPlr ) ) return NULL ;
2010-03-27 16:05:02 +00:00
return : : Players . Get ( iPlr ) - > Crew . GetObject ( index ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetCrewCount ( C4PropList * _this , long iPlr )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
if ( ! ValidPlr ( iPlr ) ) return 0 ;
return : : Players . Get ( iPlr ) - > Crew . ObjectCount ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetPlayerCount ( C4PropList * _this , long iType )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! iType )
2009-06-12 23:09:32 +00:00
return : : Players . GetCount ( ) ;
2009-05-08 13:28:41 +00:00
else
2009-06-12 23:09:32 +00:00
return : : Players . GetCount ( ( C4PlayerType ) iType ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetPlayerByIndex ( C4PropList * _this , long iIndex , long iType )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4Player * pPlayer ;
if ( iType )
2009-06-12 23:09:32 +00:00
pPlayer = : : Players . GetByIndex ( iIndex , ( C4PlayerType ) iType ) ;
2009-05-08 13:28:41 +00:00
else
2009-06-12 23:09:32 +00:00
pPlayer = : : Players . GetByIndex ( iIndex ) ;
2010-03-28 18:58:01 +00:00
if ( ! pPlayer ) return NO_OWNER ;
2009-05-08 13:28:41 +00:00
return pPlayer - > Number ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnEliminatePlayer ( C4PropList * _this , long iPlr , bool fRemoveDirect )
2010-03-28 18:58:01 +00:00
{
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iPlr ) ;
2009-08-15 18:50:32 +00:00
if ( ! pPlr ) return false ;
2009-05-08 13:28:41 +00:00
// direct removal?
if ( fRemoveDirect )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// do direct removal (no fate)
2011-11-08 16:16:31 +00:00
if ( : : Control . isCtrlHost ( ) ) : : Players . CtrlRemove ( iPlr , false ) ;
return true ;
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// do regular elimination
2009-08-15 18:50:32 +00:00
if ( pPlr - > Eliminated ) return false ;
2009-05-08 13:28:41 +00:00
pPlr - > Eliminate ( ) ;
2010-03-27 16:05:02 +00:00
}
2010-03-28 18:58:01 +00:00
return true ;
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static bool FnSurrenderPlayer ( C4PropList * _this , long iPlr )
2010-03-28 18:58:01 +00:00
{
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iPlr ) ;
2009-08-15 18:50:32 +00:00
if ( ! pPlr ) return false ;
if ( pPlr - > Eliminated ) return false ;
2010-03-27 16:05:02 +00:00
pPlr - > Surrender ( ) ;
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2014-04-20 13:33:36 +00:00
static bool FnSetLeaguePerformance ( C4PropList * _this , long iScore , long idPlayer )
{
if ( ! Game . Parameters . isLeague ( ) ) return false ;
if ( idPlayer & & ! Game . PlayerInfos . GetPlayerInfoByID ( idPlayer ) ) return false ;
Game . RoundResults . SetLeaguePerformance ( iScore , idPlayer ) ;
2009-08-15 18:50:32 +00:00
return true ;
2014-04-20 13:33:36 +00:00
}
2009-05-08 13:28:41 +00:00
static const int32_t CSPF_FixedAttributes = 1 < < 0 ,
2010-03-28 18:58:01 +00:00
CSPF_NoScenarioInit = 1 < < 1 ,
CSPF_NoEliminationCheck = 1 < < 2 ,
CSPF_Invisible = 1 < < 3 ;
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnCreateScriptPlayer ( C4PropList * _this , C4String * szName , long dwColor , long idTeam , long dwFlags , C4ID idExtra )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// safety
2009-04-01 21:36:58 +00:00
if ( ! szName | | ! szName - > GetData ( ) . getLength ( ) ) return false ;
2009-05-08 13:28:41 +00:00
// this script command puts a new script player info into the list
// the actual join will be delayed and synchronized via queue
// processed by control host only - clients/replay/etc. will perform the join via queue
2009-06-15 22:06:37 +00:00
if ( ! : : Control . isCtrlHost ( ) ) return true ;
2009-05-08 13:28:41 +00:00
C4PlayerInfo * pScriptPlrInfo = new C4PlayerInfo ( ) ;
uint32_t dwInfoFlags = 0u ;
if ( dwFlags & CSPF_FixedAttributes ) dwInfoFlags | = C4PlayerInfo : : PIF_AttributesFixed ;
if ( dwFlags & CSPF_NoScenarioInit ) dwInfoFlags | = C4PlayerInfo : : PIF_NoScenarioInit ;
if ( dwFlags & CSPF_NoEliminationCheck ) dwInfoFlags | = C4PlayerInfo : : PIF_NoEliminationCheck ;
if ( dwFlags & CSPF_Invisible ) dwInfoFlags | = C4PlayerInfo : : PIF_Invisible ;
pScriptPlrInfo - > SetAsScriptPlayer ( szName - > GetCStr ( ) , dwColor , dwInfoFlags , idExtra ) ;
pScriptPlrInfo - > SetTeam ( idTeam ) ;
C4ClientPlayerInfos JoinPkt ( NULL , true , pScriptPlrInfo ) ;
// add to queue!
Game . PlayerInfos . DoPlayerInfoUpdate ( & JoinPkt ) ;
// always successful for sync reasons
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static C4Object * FnGetCursor ( C4PropList * _this , long iPlr )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// get player
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iPlr ) ;
2009-05-08 13:28:41 +00:00
// invalid player?
if ( ! pPlr ) return NULL ;
2010-07-30 20:38:21 +00:00
return pPlr - > Cursor ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static C4Object * FnGetViewCursor ( C4PropList * _this , long iPlr )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// get player
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iPlr ) ;
2009-05-08 13:28:41 +00:00
// get viewcursor
return pPlr ? pPlr - > ViewCursor : NULL ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetCursor ( C4PropList * _this , long iPlr , C4Object * pObj , bool fNoSelectArrow )
2010-03-28 18:58:01 +00:00
{
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iPlr ) ;
2009-10-11 19:44:40 +00:00
if ( ! pPlr | | ( pObj & & ! pObj - > Status ) | | ( pObj & & pObj - > CrewDisabled ) ) return false ;
2010-07-30 20:38:21 +00:00
pPlr - > SetCursor ( pObj , ! fNoSelectArrow ) ;
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static bool FnSetViewCursor ( C4PropList * _this , long iPlr , C4Object * pObj )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// get player
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iPlr ) ;
2009-05-08 13:28:41 +00:00
// invalid player?
2009-08-15 18:50:32 +00:00
if ( ! pPlr ) return false ;
2009-05-08 13:28:41 +00:00
// set viewcursor
pPlr - > ViewCursor = pObj ;
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetWind ( C4PropList * _this , long x , long y , bool fGlobal )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// global wind
2009-06-11 19:59:35 +00:00
if ( fGlobal ) return : : Weather . Wind ;
2009-05-08 13:28:41 +00:00
// local wind
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
2010-03-27 16:05:02 +00:00
return : : Weather . GetWind ( x , y ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2016-01-03 01:39:11 +00:00
static void FnSetWind ( C4PropList * _this , long iWind )
2009-08-16 13:18:07 +00:00
{
2009-06-11 19:59:35 +00:00
: : Weather . SetWind ( iWind ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2016-01-03 01:39:11 +00:00
static void FnSetTemperature ( C4PropList * _this , long iTemperature )
2009-08-16 13:18:07 +00:00
{
2009-06-11 19:59:35 +00:00
: : Weather . SetTemperature ( iTemperature ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetTemperature ( C4PropList * _this )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
return : : Weather . GetTemperature ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2016-01-03 01:39:11 +00:00
static void FnSetAmbientBrightness ( C4PropList * _this , long iBrightness )
2014-11-19 16:18:07 +00:00
{
2016-04-02 15:50:49 +00:00
if ( : : Landscape . HasFoW ( ) )
: : Landscape . GetFoW ( ) - > Ambient . SetBrightness ( iBrightness / 100. ) ;
2014-11-19 16:18:07 +00:00
}
static long FnGetAmbientBrightness ( C4PropList * _this )
{
2016-04-02 15:50:49 +00:00
if ( ! : : Landscape . HasFoW ( ) )
2014-11-19 16:18:07 +00:00
return 100 ;
2016-04-02 15:50:49 +00:00
return static_cast < long > ( : : Landscape . GetFoW ( ) - > Ambient . GetBrightness ( ) * 100. + 0.5 ) ;
2014-11-19 16:18:07 +00:00
}
2016-01-03 01:39:11 +00:00
static void FnSetSeason ( C4PropList * _this , long iSeason )
2009-08-16 13:18:07 +00:00
{
2009-06-11 19:59:35 +00:00
: : Weather . SetSeason ( iSeason ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetSeason ( C4PropList * _this )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
return : : Weather . GetSeason ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2016-01-03 01:39:11 +00:00
static void FnSetClimate ( C4PropList * _this , long iClimate )
2009-08-16 13:18:07 +00:00
{
2009-06-11 19:59:35 +00:00
: : Weather . SetClimate ( iClimate ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetClimate ( C4PropList * _this )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
return : : Weather . GetClimate ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnLandscapeWidth ( C4PropList * _this )
2010-03-28 18:58:01 +00:00
{
2016-04-02 15:50:49 +00:00
return : : Landscape . GetWidth ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnLandscapeHeight ( C4PropList * _this )
2010-03-28 18:58:01 +00:00
{
2016-04-02 15:50:49 +00:00
return : : Landscape . GetHeight ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2016-01-03 01:39:11 +00:00
static void FnShakeFree ( C4PropList * _this , long x , long y , long rad )
2009-08-16 13:18:07 +00:00
{
2009-06-05 15:20:41 +00:00
: : Landscape . ShakeFree ( x , y , rad ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2013-03-31 13:39:29 +00:00
static long FnDigFree ( C4PropList * _this , long x , long y , long rad , bool no_dig2objects , bool no_instability_check )
2011-01-02 01:14:45 +00:00
{
2013-03-31 13:39:29 +00:00
return : : Landscape . DigFree ( x , y , rad , Object ( _this ) , no_dig2objects , no_instability_check ) ;
2011-01-02 01:14:45 +00:00
}
2013-03-31 13:39:29 +00:00
static long FnDigFreeRect ( C4PropList * _this , long iX , long iY , long iWdt , long iHgt , bool no_dig2objects , bool no_instability_check )
2009-08-16 13:18:07 +00:00
{
2013-03-31 13:39:29 +00:00
return : : Landscape . DigFreeRect ( iX , iY , iWdt , iHgt , Object ( _this ) , no_dig2objects , no_instability_check ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2016-01-03 01:39:11 +00:00
static void FnClearFreeRect ( C4PropList * _this , long iX , long iY , long iWdt , long iHgt )
2009-08-16 13:18:07 +00:00
{
2011-05-30 22:33:35 +00:00
: : Landscape . ClearFreeRect ( iX , iY , iWdt , iHgt ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnPathFree ( C4PropList * _this , long X1 , long Y1 , long X2 , long Y2 )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
return ! ! PathFree ( X1 , Y1 , X2 , Y2 ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static C4ValueArray * FnPathFree2 ( C4PropList * _this , int32_t x1 , int32_t y1 , int32_t x2 , int32_t y2 )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
int32_t x = - 1 , y = - 1 ;
2010-08-13 11:16:55 +00:00
if ( ! PathFree ( x1 , y1 , x2 , y2 , & x , & y ) )
2010-03-28 18:58:01 +00:00
{
2010-04-08 00:47:45 +00:00
C4ValueArray * pArray = new C4ValueArray ( 2 ) ;
pArray - > SetItem ( 0 , C4VInt ( x ) ) ;
pArray - > SetItem ( 1 , C4VInt ( y ) ) ;
2010-08-13 11:16:55 +00:00
return pArray ;
2009-05-08 13:28:41 +00:00
}
2010-08-13 11:16:55 +00:00
return 0 ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
C4Object * FnObject ( C4PropList * _this , long iNumber )
2010-03-28 18:58:01 +00:00
{
2009-06-15 21:47:26 +00:00
return : : Objects . SafeObjectPointer ( iNumber ) ;
2011-01-20 00:57:44 +00:00
// See FnObjectNumber
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-20 00:04:46 +00:00
static C4Value FnGameCallEx ( C4PropList * _this , C4Value * Pars )
2010-03-28 18:58:01 +00:00
{
2012-05-20 00:04:46 +00:00
C4String * fn = Pars [ 0 ] . getStr ( ) ;
if ( ! fn ) return C4Value ( ) ;
2009-05-08 13:28:41 +00:00
// copy parameters
2014-05-30 22:37:18 +00:00
C4AulParSet ParSet ;
ParSet . Copy ( & Pars [ 1 ] , 9 ) ;
2009-05-08 13:28:41 +00:00
// Call
2014-05-11 21:32:22 +00:00
return : : Game . GRBroadcast ( fn - > GetCStr ( ) , & ParSet , true ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-18 18:02:25 +00:00
static C4Object * FnEditCursor ( C4PropList * _this )
2010-03-28 18:58:01 +00:00
{
2012-05-18 18:02:25 +00:00
if ( : : Control . SyncMode ( ) ) return NULL ;
return Console . EditCursor . GetTarget ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnIsNetwork ( C4PropList * _this ) { return Game . Parameters . IsNetworkGame ; }
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static C4String * FnGetLeague ( C4PropList * _this , long idx )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// get indexed league
StdStrBuf sIdxLeague ;
if ( ! Game . Parameters . League . GetSection ( idx , & sIdxLeague ) ) return NULL ;
return String ( sIdxLeague . getData ( ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-04-20 13:33:36 +00:00
static int32_t FnGetLeagueScore ( C4PropList * _this , long idPlayer )
{
// security
if ( idPlayer < 1 ) return 0 ;
// get info
C4PlayerInfo * pInfo = Game . PlayerInfos . GetPlayerInfoByID ( idPlayer ) ;
if ( ! pInfo ) return 0 ;
// get league score
return pInfo - > getLeagueScore ( ) ;
}
static bool FnSetLeagueProgressData ( C4PropList * _this , C4String * pNewData , long idPlayer )
{
2014-04-20 18:10:53 +00:00
if ( ! Game . Parameters . League . getLength ( ) | | ! idPlayer ) return false ;
2014-04-20 13:33:36 +00:00
C4PlayerInfo * info = Game . PlayerInfos . GetPlayerInfoByID ( idPlayer ) ;
if ( ! info ) return false ;
info - > SetLeagueProgressData ( pNewData ? pNewData - > GetCStr ( ) : NULL ) ;
2014-04-24 10:40:30 +00:00
return true ;
2014-04-20 13:33:36 +00:00
}
static C4String * FnGetLeagueProgressData ( C4PropList * _this , long idPlayer )
{
if ( ! Game . Parameters . League . getLength ( ) ) return NULL ;
C4PlayerInfo * info = Game . PlayerInfos . GetPlayerInfoByID ( idPlayer ) ;
if ( ! info ) return NULL ;
return String ( info - > GetLeagueProgressData ( ) ) ;
}
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static bool FnTestMessageBoard ( C4PropList * _this , long iForPlr , bool fTestIfInUse )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// multi-query-MessageBoard is always available if the player is valid =)
// (but it won't do anything in developer mode...)
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iForPlr ) ;
2009-08-15 18:50:32 +00:00
if ( ! pPlr ) return false ;
if ( ! fTestIfInUse ) return true ;
2009-05-08 13:28:41 +00:00
// single query only if no query is scheduled
return pPlr - > HasMessageBoardQuery ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static bool FnCallMessageBoard ( C4PropList * _this , C4Object * pObj , bool fUpperCase , C4String * szQueryString , long iForPlr )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( ! pObj ) pObj = Object ( _this ) ;
2009-08-15 18:50:32 +00:00
if ( pObj & & ! pObj - > Status ) return false ;
2009-05-08 13:28:41 +00:00
// check player
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iForPlr ) ;
2009-08-15 18:50:32 +00:00
if ( ! pPlr ) return false ;
2009-05-08 13:28:41 +00:00
// remove any previous
pPlr - > CallMessageBoard ( pObj , StdStrBuf ( FnStringPar ( szQueryString ) ) , ! ! fUpperCase ) ;
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static bool FnAbortMessageBoard ( C4PropList * _this , C4Object * pObj , long iForPlr )
2010-03-28 18:58:01 +00:00
{
2012-05-15 01:03:47 +00:00
if ( ! pObj ) pObj = Object ( _this ) ;
2009-05-08 13:28:41 +00:00
// check player
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iForPlr ) ;
2009-08-15 18:50:32 +00:00
if ( ! pPlr ) return false ;
2009-05-08 13:28:41 +00:00
// close TypeIn if active
2009-06-05 15:18:45 +00:00
: : MessageInput . AbortMsgBoardQuery ( pObj , iForPlr ) ;
2009-05-08 13:28:41 +00:00
// abort for it
return pPlr - > RemoveMessageBoardQuery ( pObj ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2016-01-03 01:39:11 +00:00
static void FnSetFoW ( C4PropList * _this , bool fEnabled , long iPlr )
2009-08-16 13:18:07 +00:00
{
2009-05-08 13:28:41 +00:00
// safety
2016-01-03 01:39:11 +00:00
if ( ! ValidPlr ( iPlr ) ) return ;
2009-05-08 13:28:41 +00:00
// set enabled
2009-06-12 23:09:32 +00:00
: : Players . Get ( iPlr ) - > SetFoW ( ! ! fEnabled ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnSetMaxPlayer ( C4PropList * _this , long iTo )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// think positive! :)
2009-08-15 18:50:32 +00:00
if ( iTo < 0 ) return false ;
2009-05-08 13:28:41 +00:00
// script functions don't need to pass ControlQueue!
Game . Parameters . MaxPlayers = iTo ;
// success
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnGetMissionAccess ( C4PropList * _this , C4String * strMissionAccess )
2009-05-08 13:28:41 +00:00
{
// safety
2009-08-15 18:50:32 +00:00
if ( ! strMissionAccess ) return false ;
2009-05-08 13:28:41 +00:00
// non-sync mode: warn
2010-03-28 18:58:01 +00:00
if ( : : Control . SyncMode ( ) )
2009-05-08 13:28:41 +00:00
Log ( " Warning: using GetMissionAccess may cause desyncs when playing records! " ) ;
return SIsModule ( Config . General . MissionAccess , FnStringPar ( strMissionAccess ) ) ;
}
// Helper to read or write a value from/to a structure. Must be two
class C4ValueCompiler : public StdCompiler
{
public :
2010-03-27 16:05:02 +00:00
C4ValueCompiler ( const char * * pszNames , int iNameCnt , int iEntryNr )
2010-03-28 18:58:01 +00:00
: pszNames ( pszNames ) , iNameCnt ( iNameCnt ) , iEntryNr ( iEntryNr )
2010-03-27 16:05:02 +00:00
{ }
2009-05-08 13:28:41 +00:00
2010-03-27 16:05:02 +00:00
virtual bool isCompiler ( ) { return false ; }
virtual bool hasNaming ( ) { return true ; }
2009-05-08 13:28:41 +00:00
virtual bool isVerbose ( ) { return false ; }
2010-03-27 16:05:02 +00:00
virtual bool Name ( const char * szName )
{
// match possible? (no match yet / continued match)
2010-03-28 18:58:01 +00:00
if ( ! iMatchStart | | haveCurrentMatch ( ) )
2010-03-27 16:05:02 +00:00
// already got all names?
2010-03-28 18:58:01 +00:00
if ( ! haveCompleteMatch ( ) )
2010-03-27 16:05:02 +00:00
// check name
2010-03-28 18:58:01 +00:00
if ( SEqual ( pszNames [ iMatchCount ] , szName ) )
2010-03-27 16:05:02 +00:00
{
// got match
2010-03-28 18:58:01 +00:00
if ( ! iMatchCount ) iMatchStart = iDepth + 1 ;
2010-03-27 16:05:02 +00:00
iMatchCount + + ;
}
iDepth + + ;
return true ;
}
2009-05-08 13:28:41 +00:00
virtual bool Default ( const char * szName )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Always process values even if they are default!
return false ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2010-03-27 16:05:02 +00:00
virtual void NameEnd ( bool fBreak = false )
{
// end of matched name section?
2010-03-28 18:58:01 +00:00
if ( haveCurrentMatch ( ) )
2010-03-27 16:05:02 +00:00
{
iMatchCount - - ;
2010-03-28 18:58:01 +00:00
if ( ! iMatchCount ) iMatchStart = 0 ;
2010-03-27 16:05:02 +00:00
}
iDepth - - ;
}
virtual void Begin ( )
{
// set up
iDepth = iMatchStart = iMatchCount = 0 ;
}
2009-05-08 13:28:41 +00:00
protected :
// value function forward to be overwritten by get or set compiler
virtual void ProcessInt ( int32_t & rInt ) = 0 ;
virtual void ProcessBool ( bool & rBool ) = 0 ;
virtual void ProcessChar ( char & rChar ) = 0 ;
virtual void ProcessString ( char * szString , size_t iMaxLength , bool fIsID ) = 0 ;
virtual void ProcessString ( char * * pszString , bool fIsID ) = 0 ;
public :
2010-03-27 16:05:02 +00:00
// value functions
2010-03-28 18:58:01 +00:00
virtual void DWord ( int32_t & rInt ) { if ( haveCompleteMatch ( ) ) if ( ! iEntryNr - - ) ProcessInt ( rInt ) ; }
virtual void DWord ( uint32_t & rInt ) { if ( haveCompleteMatch ( ) ) if ( ! iEntryNr - - ) { int32_t i = rInt ; ProcessInt ( i ) ; rInt = i ; } }
virtual void Word ( int16_t & rShort ) { if ( haveCompleteMatch ( ) ) if ( ! iEntryNr - - ) { int32_t i = rShort ; ProcessInt ( i ) ; rShort = i ; } }
virtual void Word ( uint16_t & rShort ) { if ( haveCompleteMatch ( ) ) if ( ! iEntryNr - - ) { int32_t i = rShort ; ProcessInt ( i ) ; rShort = i ; } }
virtual void Byte ( int8_t & rByte ) { if ( haveCompleteMatch ( ) ) if ( ! iEntryNr - - ) { int32_t i = rByte ; ProcessInt ( i ) ; rByte = i ; } }
virtual void Byte ( uint8_t & rByte ) { if ( haveCompleteMatch ( ) ) if ( ! iEntryNr - - ) { int32_t i = rByte ; ProcessInt ( i ) ; rByte = i ; } }
virtual void Boolean ( bool & rBool ) { if ( haveCompleteMatch ( ) ) if ( ! iEntryNr - - ) ProcessBool ( rBool ) ; }
virtual void Character ( char & rChar ) { if ( haveCompleteMatch ( ) ) if ( ! iEntryNr - - ) ProcessChar ( rChar ) ; }
2010-03-27 16:05:02 +00:00
// The C4ID-Adaptor will set RCT_ID for it's strings (see C4Id.h), so we don't have to guess the type.
virtual void String ( char * szString , size_t iMaxLength , RawCompileType eType )
2010-03-28 18:58:01 +00:00
{ if ( haveCompleteMatch ( ) ) if ( ! iEntryNr - - ) ProcessString ( szString , iMaxLength , eType = = StdCompiler : : RCT_ID ) ; }
2010-03-27 16:05:02 +00:00
virtual void String ( char * * pszString , RawCompileType eType )
2010-03-28 18:58:01 +00:00
{ if ( haveCompleteMatch ( ) ) if ( ! iEntryNr - - ) ProcessString ( pszString , eType = = StdCompiler : : RCT_ID ) ; }
2010-03-27 16:05:02 +00:00
virtual void Raw ( void * pData , size_t iSize , RawCompileType eType = RCT_Escaped )
2010-03-28 18:58:01 +00:00
{ /* C4Script can't handle this */ }
2009-05-08 13:28:41 +00:00
private :
2010-03-27 16:05:02 +00:00
// Name(s) of the entry to read
const char * * pszNames ;
int iNameCnt ;
// Number of the element that is to be read
int iEntryNr ;
2009-05-08 13:28:41 +00:00
2010-03-27 16:05:02 +00:00
// current depth
int iDepth ;
// match start (where did the first name match?),
// match count (how many names did match, from that point?)
int iMatchStart , iMatchCount ;
2009-05-08 13:28:41 +00:00
private :
2010-03-27 16:05:02 +00:00
// match active?
bool haveCurrentMatch ( ) const { return iDepth + 1 = = iMatchStart + iMatchCount ; }
// match complete?
bool haveCompleteMatch ( ) const { return haveCurrentMatch ( ) & & iMatchCount = = iNameCnt ; }
2009-05-08 13:28:41 +00:00
} ;
class C4ValueGetCompiler : public C4ValueCompiler
{
private :
2010-03-27 16:05:02 +00:00
// Result
C4Value Res ;
2009-05-08 13:28:41 +00:00
public :
2010-03-28 18:58:01 +00:00
C4ValueGetCompiler ( const char * * pszNames , int iNameCnt , int iEntryNr )
: C4ValueCompiler ( pszNames , iNameCnt , iEntryNr )
2010-03-27 16:05:02 +00:00
{ }
2009-05-08 13:28:41 +00:00
2010-03-27 16:05:02 +00:00
// Result-getter
const C4Value & getResult ( ) const { return Res ; }
2009-05-08 13:28:41 +00:00
protected :
// get values as C4Value
virtual void ProcessInt ( int32_t & rInt ) { Res = C4VInt ( rInt ) ; }
virtual void ProcessBool ( bool & rBool ) { Res = C4VBool ( rBool ) ; }
virtual void ProcessChar ( char & rChar ) { Res = C4VString ( FormatString ( " %c " , rChar ) ) ; }
virtual void ProcessString ( char * szString , size_t iMaxLength , bool fIsID )
2011-02-05 22:09:09 +00:00
{ Res = ( fIsID ? C4VPropList ( C4Id2Def ( C4ID ( szString ) ) ) : C4VString ( szString ) ) ; }
2009-05-08 13:28:41 +00:00
virtual void ProcessString ( char * * pszString , bool fIsID )
2011-02-05 22:09:09 +00:00
{ Res = ( fIsID ? C4VPropList ( C4Id2Def ( C4ID ( * pszString ) ) ) : C4VString ( * pszString ) ) ; }
2009-05-08 13:28:41 +00:00
} ;
// Use the compiler to find a named value in a structure
template < class T >
2010-03-28 18:58:01 +00:00
C4Value GetValByStdCompiler ( const char * strEntry , const char * strSection , int iEntryNr , const T & rFrom )
{
// Set up name array, create compiler
const char * szNames [ 2 ] = { strSection ? strSection : strEntry , strSection ? strEntry : NULL } ;
C4ValueGetCompiler Comp ( szNames , strSection ? 2 : 1 , iEntryNr ) ;
2009-05-08 13:28:41 +00:00
2010-03-28 18:58:01 +00:00
// Compile
try
{
Comp . Decompile ( rFrom ) ;
return Comp . getResult ( ) ;
}
// Should not happen, catch it anyway.
catch ( StdCompiler : : Exception * )
{
return C4VNull ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-20 00:04:46 +00:00
static C4Value FnGetDefCoreVal ( C4PropList * _this , C4String * strEntry , C4String * strSection , int iEntryNr )
2009-05-08 13:28:41 +00:00
{
2012-05-15 01:03:47 +00:00
if ( ! _this | | ! _this - > GetDef ( ) )
2015-12-07 14:15:49 +00:00
throw NeedNonGlobalContext ( " GetDefCoreVal " ) ;
2009-08-16 13:18:07 +00:00
2012-05-20 00:04:46 +00:00
return GetValByStdCompiler ( FnStringPar ( strEntry ) , strSection ? strSection - > GetCStr ( ) : NULL ,
iEntryNr , mkNamingAdapt ( * _this - > GetDef ( ) , " DefCore " ) ) ;
2009-05-08 13:28:41 +00:00
}
2012-05-20 00:04:46 +00:00
static C4Value FnGetObjectVal ( C4Object * _this , C4String * strEntry , C4String * strSection , int iEntryNr )
2009-05-08 13:28:41 +00:00
{
// get value
2011-03-26 22:59:35 +00:00
C4ValueNumbers numbers ;
2012-05-20 00:04:46 +00:00
C4Value retval = GetValByStdCompiler ( FnStringPar ( strEntry ) , strSection ? strSection - > GetCStr ( ) : NULL ,
iEntryNr , mkNamingAdapt ( mkParAdapt ( * Object ( _this ) , & numbers ) , " Object " ) ) ;
2011-03-27 16:14:41 +00:00
numbers . Denumerate ( ) ;
2011-03-27 22:15:06 +00:00
retval . Denumerate ( & numbers ) ;
2010-03-30 21:47:59 +00:00
return retval ;
2009-05-08 13:28:41 +00:00
}
2012-05-20 00:04:46 +00:00
static C4Value FnGetObjectInfoCoreVal ( C4Object * _this , C4String * strEntry , C4String * strSection , int iEntryNr )
2009-05-08 13:28:41 +00:00
{
// get obj info
2012-05-15 01:03:47 +00:00
C4ObjectInfo * pObjInfo = Object ( _this ) - > Info ;
2009-05-08 13:28:41 +00:00
2010-03-28 18:58:01 +00:00
if ( ! pObjInfo ) return C4VNull ;
2009-05-08 13:28:41 +00:00
// get obj info core
C4ObjectInfoCore * pObjInfoCore = ( C4ObjectInfoCore * ) pObjInfo ;
// get value
2012-05-20 00:04:46 +00:00
return GetValByStdCompiler ( FnStringPar ( strEntry ) , strSection ? strSection - > GetCStr ( ) : NULL ,
iEntryNr , mkNamingAdapt ( * pObjInfoCore , " ObjectInfo " ) ) ;
2009-05-08 13:28:41 +00:00
}
2012-05-20 00:04:46 +00:00
static C4Value FnGetScenarioVal ( C4PropList * _this , C4String * strEntry , C4String * strSection , int iEntryNr )
2009-05-08 13:28:41 +00:00
{
2012-05-20 00:04:46 +00:00
return GetValByStdCompiler ( FnStringPar ( strEntry ) , strSection ? strSection - > GetCStr ( ) : NULL ,
iEntryNr , mkParAdapt ( Game . C4S , false ) ) ;
2009-05-08 13:28:41 +00:00
}
2012-05-20 00:04:46 +00:00
static C4Value FnGetPlayerVal ( C4PropList * _this , C4String * strEntry , C4String * strSection , int iPlayer , int iEntryNr )
2009-05-08 13:28:41 +00:00
{
// get player
2012-05-20 00:04:46 +00:00
C4Player * pPlayer = : : Players . Get ( iPlayer ) ;
if ( ! pPlayer ) return C4Value ( ) ;
2009-05-08 13:28:41 +00:00
// get value
2011-03-26 22:59:35 +00:00
C4ValueNumbers numbers ;
2012-05-20 00:04:46 +00:00
C4Value retval = GetValByStdCompiler ( FnStringPar ( strEntry ) , strSection ? strSection - > GetCStr ( ) : NULL ,
iEntryNr , mkNamingAdapt ( mkParAdapt ( * pPlayer , & numbers ) , " Player " ) ) ;
2011-03-27 16:14:41 +00:00
numbers . Denumerate ( ) ;
2011-03-27 22:15:06 +00:00
retval . Denumerate ( & numbers ) ;
2010-03-30 21:47:59 +00:00
return retval ;
2009-05-08 13:28:41 +00:00
}
2012-05-20 00:04:46 +00:00
static C4Value FnGetPlayerInfoCoreVal ( C4PropList * _this , C4String * strEntry , C4String * strSection , int iPlayer , int iEntryNr )
2009-05-08 13:28:41 +00:00
{
// get player
2012-05-20 00:04:46 +00:00
C4Player * pPlayer = : : Players . Get ( iPlayer ) ;
if ( ! pPlayer ) return C4Value ( ) ;
2009-05-08 13:28:41 +00:00
// get plr info core
C4PlayerInfoCore * pPlayerInfoCore = ( C4PlayerInfoCore * ) pPlayer ;
// get value
2012-05-20 00:04:46 +00:00
return GetValByStdCompiler ( FnStringPar ( strEntry ) , strSection ? strSection - > GetCStr ( ) : NULL ,
iEntryNr , * pPlayerInfoCore ) ;
2009-05-08 13:28:41 +00:00
}
2012-10-27 17:35:25 +00:00
static C4Value FnGetMaterialVal ( C4PropList * _this , C4String * strEntry , C4String * strSection , int iMat , int iEntryNr )
2009-05-08 13:28:41 +00:00
{
2010-03-28 18:58:01 +00:00
if ( iMat < 0 | | iMat > = : : MaterialMap . Num ) return C4Value ( ) ;
2009-05-08 13:28:41 +00:00
// get material
2009-06-05 18:46:03 +00:00
C4Material * pMaterial = & : : MaterialMap . Map [ iMat ] ;
2009-05-08 13:28:41 +00:00
// get plr info core
C4MaterialCore * pMaterialCore = static_cast < C4MaterialCore * > ( pMaterial ) ;
// get value
2012-10-27 17:35:25 +00:00
return GetValByStdCompiler ( FnStringPar ( strEntry ) , strSection ? strSection - > GetCStr ( ) : NULL , iEntryNr , * pMaterialCore ) ;
2009-05-08 13:28:41 +00:00
}
2012-05-15 01:03:47 +00:00
static C4String * FnMaterialName ( C4PropList * _this , long iMat )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// mat valid?
if ( ! MatValid ( iMat ) ) return NULL ;
// return mat name
2009-06-05 18:46:03 +00:00
return String ( : : MaterialMap . Map [ iMat ] . Name ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetSkyAdjust ( C4PropList * _this , long dwAdjust , long dwBackClr )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// set adjust
2016-04-02 15:50:49 +00:00
: : Landscape . GetSky ( ) . SetModulation ( dwAdjust , dwBackClr ) ;
2009-05-08 13:28:41 +00:00
// success
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetMatAdjust ( C4PropList * _this , long dwAdjust )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// set adjust
2009-06-05 15:20:41 +00:00
: : Landscape . SetModulation ( dwAdjust ) ;
2009-05-08 13:28:41 +00:00
// success
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetSkyAdjust ( C4PropList * _this , bool fBackColor )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// get adjust
2016-04-02 15:50:49 +00:00
return : : Landscape . GetSky ( ) . GetModulation ( ! ! fBackColor ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetMatAdjust ( C4PropList * _this )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// get adjust
2009-06-05 15:20:41 +00:00
return : : Landscape . GetModulation ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetTime ( C4PropList * _this )
2009-05-08 13:28:41 +00:00
{
// check network, record, etc
2009-06-15 22:06:37 +00:00
if ( : : Control . SyncMode ( ) ) return 0 ;
2013-12-07 14:27:01 +00:00
return C4TimeMilliseconds : : Now ( ) . AsInt ( ) ;
2009-05-08 13:28:41 +00:00
}
2012-05-20 00:04:46 +00:00
static C4Value FnSetPlrExtraData ( C4PropList * _this , int iPlayer , C4String * DataName , const C4Value & Data )
2009-05-08 13:28:41 +00:00
{
2012-05-20 00:04:46 +00:00
const char * strDataName = FnStringPar ( DataName ) ;
2011-05-02 21:01:19 +00:00
// do not allow data type C4V_Array or C4V_C4Object
2012-05-20 00:04:46 +00:00
if ( Data . GetType ( ) ! = C4V_Nil & &
Data . GetType ( ) ! = C4V_Int & &
Data . GetType ( ) ! = C4V_Bool & &
Data . GetType ( ) ! = C4V_String ) return C4VNull ;
2009-06-12 23:09:32 +00:00
C4Player * pPlayer = : : Players . Get ( iPlayer ) ;
2012-05-20 00:04:46 +00:00
if ( ! pPlayer ) return C4Value ( ) ;
2009-05-08 13:28:41 +00:00
// no name list created yet?
2010-03-28 18:58:01 +00:00
if ( ! pPlayer - > ExtraData . pNames )
2009-05-08 13:28:41 +00:00
// create name list
pPlayer - > ExtraData . CreateTempNameList ( ) ;
// data name already exists?
long ival ;
2010-03-28 18:58:01 +00:00
if ( ( ival = pPlayer - > ExtraData . pNames - > GetItemNr ( strDataName ) ) ! = - 1 )
2012-05-20 00:04:46 +00:00
pPlayer - > ExtraData [ ival ] = Data ;
2009-05-08 13:28:41 +00:00
else
{
// add name
pPlayer - > ExtraData . pNames - > AddName ( strDataName ) ;
// get val id & set
2010-03-28 18:58:01 +00:00
if ( ( ival = pPlayer - > ExtraData . pNames - > GetItemNr ( strDataName ) ) = = - 1 ) return C4Value ( ) ;
2012-05-20 00:04:46 +00:00
pPlayer - > ExtraData [ ival ] = Data ;
2009-05-08 13:28:41 +00:00
}
// ok, return the value that has been set
2012-05-20 00:04:46 +00:00
return Data ;
2009-05-08 13:28:41 +00:00
}
2012-05-20 00:04:46 +00:00
static C4Value FnGetPlrExtraData ( C4PropList * _this , int iPlayer , C4String * DataName )
2009-05-08 13:28:41 +00:00
{
2012-05-20 00:04:46 +00:00
const char * strDataName = FnStringPar ( DataName ) ;
2009-06-12 23:09:32 +00:00
C4Player * pPlayer = : : Players . Get ( iPlayer ) ;
2012-05-20 00:04:46 +00:00
if ( ! pPlayer ) return C4Value ( ) ;
2009-05-08 13:28:41 +00:00
// no name list?
2010-03-28 18:58:01 +00:00
if ( ! pPlayer - > ExtraData . pNames ) return C4Value ( ) ;
2009-05-08 13:28:41 +00:00
long ival ;
2011-01-20 00:57:44 +00:00
if ( ( ival = pPlayer - > ExtraData . pNames - > GetItemNr ( strDataName ) ) = = - 1 ) return C4Value ( ) ;
// return data
return pPlayer - > ExtraData [ ival ] ;
}
2009-11-30 23:41:37 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static long FnDrawMatChunks ( C4PropList * _this , long tx , long ty , long twdt , long thgt , long icntx , long icnty , C4String * strMaterial , C4String * strTexture , bool bIFT )
2011-01-20 00:57:44 +00:00
{
return : : Landscape . DrawChunks ( tx , ty , twdt , thgt , icntx , icnty , FnStringPar ( strMaterial ) , FnStringPar ( strTexture ) , bIFT ! = 0 ) ;
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnDrawMap ( C4PropList * _this , long iX , long iY , long iWdt , long iHgt , C4String * szMapDef )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// draw it!
2012-02-19 16:57:33 +00:00
// don't clear the old map before drawing
return : : Landscape . DrawMap ( iX , iY , iWdt , iHgt , FnStringPar ( szMapDef ) , true ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnDrawDefMap ( C4PropList * _this , long iX , long iY , long iWdt , long iHgt , C4String * szMapDef )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// draw it!
2012-02-19 16:57:33 +00:00
// don't clear the old map before drawing
return : : Landscape . DrawDefMap ( iX , iY , iWdt , iHgt , FnStringPar ( szMapDef ) , true ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2013-12-17 20:40:40 +00:00
static bool FnCreateParticle ( C4PropList * _this , C4String * name , C4Value x , C4Value y , C4Value speedX , C4Value speedY , C4Value lifetime , C4PropList * properties , int amount )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// safety
2013-09-21 14:48:28 +00:00
C4Object * obj = Object ( _this ) ;
if ( obj & & ! _this - > Status ) return false ;
2013-10-18 16:52:04 +00:00
# ifndef USE_CONSOLE
2013-10-10 15:19:20 +00:00
if ( amount < = 0 ) amount = 1 ;
2013-09-21 14:48:28 +00:00
2009-05-08 13:28:41 +00:00
// get particle
2013-12-17 20:40:40 +00:00
C4ParticleDef * pDef = : : Particles . definitions . GetDef ( FnStringPar ( name ) ) ;
2009-08-15 18:50:32 +00:00
if ( ! pDef ) return false ;
2013-09-21 14:48:28 +00:00
// construct data
2013-12-17 20:40:40 +00:00
C4ParticleValueProvider valueX , valueY , valueSpeedX , valueSpeedY , valueLifetime ;
2013-10-22 14:21:31 +00:00
valueX . Set ( x ) ;
valueY . Set ( y ) ;
2013-09-21 14:48:28 +00:00
valueSpeedX . Set ( speedX ) ;
valueSpeedY . Set ( speedY ) ;
2013-10-10 15:19:20 +00:00
valueLifetime . Set ( lifetime ) ;
2009-05-08 13:28:41 +00:00
// create
2013-12-17 20:40:40 +00:00
: : Particles . Create ( pDef , valueX , valueY , valueSpeedX , valueSpeedY , valueLifetime , properties , amount , obj ) ;
2013-10-18 16:52:04 +00:00
# endif
2009-05-08 13:28:41 +00:00
// success, even if not created
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2013-12-17 17:09:14 +00:00
static bool FnClearParticles ( C4PropList * _this )
2010-03-28 18:58:01 +00:00
{
2014-03-31 14:30:40 +00:00
# ifndef USE_CONSOLE
2013-12-17 17:09:14 +00:00
C4Object * obj ;
2014-04-17 17:16:24 +00:00
if ( ( obj = Object ( _this ) ) )
2010-03-28 18:58:01 +00:00
{
2013-12-17 20:40:40 +00:00
if ( obj - > BackParticles )
obj - > BackParticles - > Clear ( ) ;
if ( obj - > FrontParticles )
obj - > FrontParticles - > Clear ( ) ;
2010-03-28 18:58:01 +00:00
}
2013-12-17 17:09:14 +00:00
else
2010-03-28 18:58:01 +00:00
{
2013-12-17 20:40:40 +00:00
if ( : : Particles . GetGlobalParticles ( ) )
: : Particles . GetGlobalParticles ( ) - > Clear ( ) ;
2010-03-28 18:58:01 +00:00
}
2014-03-31 14:30:40 +00:00
# endif
2013-12-17 17:09:14 +00:00
// always return true
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2013-10-07 11:36:51 +00:00
static C4ValueArray * FnPV_Linear ( C4PropList * _this , C4Value startValue , C4Value endValue )
2010-03-28 18:58:01 +00:00
{
2013-09-21 14:48:28 +00:00
C4ValueArray * pArray = new C4ValueArray ( 3 ) ;
pArray - > SetItem ( 0 , C4VInt ( C4PV_Linear ) ) ;
2013-10-07 11:36:51 +00:00
pArray - > SetItem ( 1 , startValue ) ;
pArray - > SetItem ( 2 , endValue ) ;
2013-09-21 14:48:28 +00:00
return pArray ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2016-02-27 10:15:15 +00:00
static C4ValueArray * FnPV_Random ( C4PropList * _this , C4Value startValue , C4Value endValue , C4Value rerollInterval , C4Value seed )
2010-03-28 18:58:01 +00:00
{
2013-09-21 14:48:28 +00:00
C4ValueArray * pArray = new C4ValueArray ( 4 ) ;
2013-09-21 15:22:46 +00:00
pArray - > SetItem ( 0 , C4VInt ( C4PV_Random ) ) ;
2013-10-07 11:36:51 +00:00
pArray - > SetItem ( 1 , startValue ) ;
pArray - > SetItem ( 2 , endValue ) ;
pArray - > SetItem ( 3 , rerollInterval ) ;
2016-02-27 10:15:15 +00:00
pArray - > SetItem ( 4 , seed ) ;
2013-09-21 14:48:28 +00:00
return pArray ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2013-10-07 11:36:51 +00:00
static C4ValueArray * FnPV_Direction ( C4PropList * _this , C4Value factor )
2010-03-28 18:58:01 +00:00
{
2013-09-24 18:36:49 +00:00
C4ValueArray * pArray = new C4ValueArray ( 2 ) ;
pArray - > SetItem ( 0 , C4VInt ( C4PV_Direction ) ) ;
2013-10-07 11:36:51 +00:00
pArray - > SetItem ( 1 , factor . GetType ( ) ! = C4V_Nil ? factor : C4VInt ( 1000 ) ) ;
2013-09-24 18:36:49 +00:00
return pArray ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-02-18 19:37:43 +00:00
static C4ValueArray * FnPV_Step ( C4PropList * _this , C4Value step , C4Value startValue , C4Value delay , C4Value maximumValue )
2010-03-28 18:58:01 +00:00
{
2014-02-18 19:37:43 +00:00
C4ValueArray * pArray = new C4ValueArray ( 5 ) ;
2013-09-24 18:36:49 +00:00
pArray - > SetItem ( 0 , C4VInt ( C4PV_Step ) ) ;
2013-10-07 11:36:51 +00:00
pArray - > SetItem ( 1 , step ) ;
pArray - > SetItem ( 2 , startValue ) ;
pArray - > SetItem ( 3 , delay ) ;
2014-02-18 19:37:43 +00:00
pArray - > SetItem ( 4 , maximumValue ) ;
2013-09-24 18:36:49 +00:00
return pArray ;
}
2013-09-21 15:22:46 +00:00
static C4Value FnPV_KeyFrames ( C4PropList * _this , C4Value * pars )
{
C4ValueArray * pArray = new C4ValueArray ( C4AUL_MAX_Par ) ;
pArray - > SetItem ( 0 , C4VInt ( C4PV_KeyFrames ) ) ;
const int offset = 1 ;
// Read all parameters
int i = 0 ;
for ( ; i < C4AUL_MAX_Par ; i + + )
2010-03-28 18:58:01 +00:00
{
2013-09-21 15:22:46 +00:00
C4Value Data = * ( pars + + ) ;
// No data given?
if ( Data . GetType ( ) = = C4V_Nil ) break ;
2013-10-07 11:36:51 +00:00
pArray - > SetItem ( offset + i , Data ) ;
2010-03-28 18:58:01 +00:00
}
2013-09-21 15:22:46 +00:00
pArray - > SetSize ( i + offset ) ;
return C4Value ( pArray ) ;
}
2014-06-29 23:00:15 +00:00
static C4ValueArray * FnPV_Sin ( C4PropList * _this , C4Value value , C4Value amplitude , C4Value offset )
{
C4ValueArray * pArray = new C4ValueArray ( 5 ) ;
pArray - > SetItem ( 0 , C4VInt ( C4PV_Sin ) ) ;
pArray - > SetItem ( 1 , value ) ;
pArray - > SetItem ( 2 , amplitude ) ;
pArray - > SetItem ( 3 , offset ) ;
return pArray ;
}
2016-02-27 10:33:19 +00:00
static C4ValueArray * FnPV_Cos ( C4PropList * _this , C4Value value , C4Value amplitude , C4Value offset )
{
C4ValueArray * pArray = new C4ValueArray ( 5 ) ;
pArray - > SetItem ( 0 , C4VInt ( C4PV_Cos ) ) ;
pArray - > SetItem ( 1 , value ) ;
pArray - > SetItem ( 2 , amplitude ) ;
pArray - > SetItem ( 3 , offset ) ;
return pArray ;
}
2013-10-07 11:36:51 +00:00
static C4ValueArray * FnPV_Speed ( C4PropList * _this , C4Value factor , C4Value startValue )
2013-09-27 11:28:38 +00:00
{
C4ValueArray * pArray = new C4ValueArray ( 3 ) ;
pArray - > SetItem ( 0 , C4VInt ( C4PV_Speed ) ) ;
2013-10-19 12:50:43 +00:00
pArray - > SetItem ( 1 , factor . GetType ( ) = = C4V_Nil ? C4VInt ( 1000 ) : factor ) ;
pArray - > SetItem ( 2 , startValue ) ;
return pArray ;
}
static C4ValueArray * FnPV_Wind ( C4PropList * _this , C4Value factor , C4Value startValue )
{
C4ValueArray * pArray = new C4ValueArray ( 3 ) ;
pArray - > SetItem ( 0 , C4VInt ( C4PV_Wind ) ) ;
pArray - > SetItem ( 1 , factor . GetType ( ) = = C4V_Nil ? C4VInt ( 1000 ) : factor ) ;
pArray - > SetItem ( 2 , startValue ) ;
return pArray ;
}
static C4ValueArray * FnPV_Gravity ( C4PropList * _this , C4Value factor , C4Value startValue )
{
C4ValueArray * pArray = new C4ValueArray ( 3 ) ;
pArray - > SetItem ( 0 , C4VInt ( C4PV_Gravity ) ) ;
pArray - > SetItem ( 1 , factor . GetType ( ) = = C4V_Nil ? C4VInt ( 1000 ) : factor ) ;
2013-10-07 11:36:51 +00:00
pArray - > SetItem ( 2 , startValue ) ;
2013-09-27 11:28:38 +00:00
return pArray ;
}
2013-09-21 15:22:46 +00:00
2013-09-27 14:06:25 +00:00
static C4ValueArray * FnPC_Die ( C4PropList * _this )
{
C4ValueArray * pArray = new C4ValueArray ( 1 ) ;
pArray - > SetItem ( 0 , C4VInt ( C4PC_Die ) ) ;
return pArray ;
}
2013-10-07 11:36:51 +00:00
static C4ValueArray * FnPC_Bounce ( C4PropList * _this , C4Value bouncyness )
2013-09-27 14:06:25 +00:00
{
C4ValueArray * pArray = new C4ValueArray ( 2 ) ;
pArray - > SetItem ( 0 , C4VInt ( C4PC_Bounce ) ) ;
2013-10-07 11:36:51 +00:00
pArray - > SetItem ( 1 , bouncyness . GetType ( ) ! = C4V_Nil ? bouncyness : C4VInt ( 1000 ) ) ;
2013-09-27 14:06:25 +00:00
return pArray ;
}
2013-10-19 12:50:43 +00:00
static C4ValueArray * FnPC_Stop ( C4PropList * _this )
{
C4ValueArray * pArray = new C4ValueArray ( 1 ) ;
pArray - > SetItem ( 0 , C4VInt ( C4PC_Stop ) ) ;
return pArray ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetSkyParallax ( C4PropList * _this , Nillable < long > iMode , Nillable < long > iParX , Nillable < long > iParY , Nillable < long > iXDir , Nillable < long > iYDir , Nillable < long > iX , Nillable < long > iY )
2010-03-28 18:58:01 +00:00
{
2011-07-02 21:44:53 +00:00
// set all parameters that aren't nil
if ( ! iMode . IsNil ( ) )
2016-04-02 15:50:49 +00:00
if ( Inside < long > ( iMode , 0 , 1 ) ) : : Landscape . GetSky ( ) . ParallaxMode = iMode ;
if ( ! iParX . IsNil ( ) & & iParX ) : : Landscape . GetSky ( ) . ParX = iParX ;
if ( ! iParY . IsNil ( ) & & iParY ) : : Landscape . GetSky ( ) . ParY = iParY ;
if ( ! iXDir . IsNil ( ) ) : : Landscape . GetSky ( ) . xdir = itofix ( iXDir ) ;
if ( ! iYDir . IsNil ( ) ) : : Landscape . GetSky ( ) . ydir = itofix ( iYDir ) ;
if ( ! iX . IsNil ( ) ) : : Landscape . GetSky ( ) . x = itofix ( iX ) ;
if ( ! iY . IsNil ( ) ) : : Landscape . GetSky ( ) . y = itofix ( iY ) ;
2009-05-08 13:28:41 +00:00
// success
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnReloadDef ( C4PropList * _this , C4ID idDef , long iReloadWhat )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// get def
C4Def * pDef = NULL ;
if ( ! idDef )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// no def given: local def
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) ) pDef = Object ( _this ) - > Def ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
// def by ID
2009-06-05 16:46:37 +00:00
pDef = : : Definitions . ID2Def ( idDef ) ;
2009-05-08 13:28:41 +00:00
// safety
if ( ! pDef ) return false ;
// reload everything if nothing has been specified
if ( ! iReloadWhat ) iReloadWhat = C4D_Load_RX ;
// perform reload
return Game . ReloadDef ( pDef - > id ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnReloadParticle ( C4PropList * _this , C4String * szParticleName )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// perform reload
return Game . ReloadParticle ( FnStringPar ( szParticleName ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2015-08-31 15:34:01 +00:00
static bool FnSetGamma ( C4PropList * _this , long iRed , long iGreen , long iBlue , long iRampIndex )
2010-03-28 18:58:01 +00:00
{
2015-08-31 15:34:01 +00:00
pDraw - > SetGamma ( float ( iRed ) / 100 ,
float ( iGreen ) / 100 ,
float ( iBlue ) / 100 ,
iRampIndex ) ;
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnResetGamma ( C4PropList * _this , long iRampIndex )
2010-03-28 18:58:01 +00:00
{
2015-08-31 15:34:01 +00:00
: : Game . SetDefaultGamma ( ) ;
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static long FnFrameCounter ( C4PropList * _this ) { return Game . FrameCounter ; }
2009-05-08 13:28:41 +00:00
struct PathInfo
{
long ilx , ily ;
long ilen ;
} ;
2015-03-31 15:12:43 +00:00
struct SumPathLength
2009-05-08 13:28:41 +00:00
{
2015-03-31 15:12:43 +00:00
explicit SumPathLength ( PathInfo * info ) : pPathInfo ( info ) { }
bool operator ( ) ( int32_t iX , int32_t iY , C4Object * TransferTarget )
{
pPathInfo - > ilen + = Distance ( pPathInfo - > ilx , pPathInfo - > ily , iX , iY ) ;
pPathInfo - > ilx = iX ;
pPathInfo - > ily = iY ;
return true ;
}
private :
PathInfo * pPathInfo ;
} ;
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static Nillable < long > FnGetPathLength ( C4PropList * _this , long iFromX , long iFromY , long iToX , long iToY )
2009-05-08 13:28:41 +00:00
{
PathInfo PathInfo ;
PathInfo . ilx = iFromX ;
PathInfo . ily = iFromY ;
PathInfo . ilen = 0 ;
2015-03-31 15:12:43 +00:00
if ( ! Game . PathFinder . Find ( iFromX , iFromY , iToX , iToY , SumPathLength ( & PathInfo ) ) )
2011-07-30 23:32:02 +00:00
return C4Void ( ) ;
2009-05-08 13:28:41 +00:00
return PathInfo . ilen + Distance ( PathInfo . ilx , PathInfo . ily , iToX , iToY ) ;
}
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static long FnSetTextureIndex ( C4PropList * _this , C4String * psMatTex , long iNewIndex , bool fInsert )
2010-03-28 18:58:01 +00:00
{
if ( ! Inside ( iNewIndex , 0l , 255l ) ) return false ;
2009-06-05 15:20:41 +00:00
return : : Landscape . SetTextureIndex ( FnStringPar ( psMatTex ) , BYTE ( iNewIndex ) , ! ! fInsert ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static long FnRemoveUnusedTexMapEntries ( C4PropList * _this )
2010-03-28 18:58:01 +00:00
{
2010-03-27 16:05:02 +00:00
: : Landscape . RemoveUnusedTexMapEntries ( ) ;
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2010-02-09 19:09:32 +00:00
static const int32_t DMQ_Sky = 0 , // draw w/ sky IFT
2014-01-22 07:00:37 +00:00
DMQ_Sub = 1 , // draw w/ tunnel IFT
DMQ_Bridge = 2 ; // draw only over materials you can bridge over
2010-02-09 19:09:32 +00:00
2015-07-14 01:02:38 +00:00
static bool FnDrawMaterialQuad ( C4PropList * _this , C4String * szMaterial , long iX1 , long iY1 , long iX2 , long iY2 , long iX3 , long iY3 , long iX4 , long iY4 , const C4Value & draw_mode )
2010-03-28 18:58:01 +00:00
{
2010-02-09 19:09:32 +00:00
const char * szMat = FnStringPar ( szMaterial ) ;
2015-07-14 01:02:38 +00:00
const char * szBackMat = NULL ;
bool fBridge = false ;
if ( draw_mode . GetType ( ) = = C4V_Int )
{
// Default behaviour: Default background material
const int draw_mode_value = draw_mode . getInt ( ) ;
switch ( draw_mode_value )
{
case DMQ_Sky : break ;
case DMQ_Sub : szBackMat = " Tunnel " ; break ; // TODO: Go via DefaultBkgMat
case DMQ_Bridge : fBridge = true ; break ;
}
}
else if ( draw_mode . GetType ( ) = = C4V_String )
{
szBackMat = FnStringPar ( draw_mode . getStr ( ) ) ;
}
return ! ! : : Landscape . DrawQuad ( iX1 , iY1 , iX2 , iY2 , iX3 , iY3 , iX4 , iY4 , szMat , szBackMat , fBridge ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetFilmView ( C4PropList * _this , long iToPlr )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// check player
2009-08-15 18:50:32 +00:00
if ( ! ValidPlr ( iToPlr ) & & iToPlr ! = NO_OWNER ) return false ;
2009-05-08 13:28:41 +00:00
// real switch in replays only
2009-08-15 18:50:32 +00:00
if ( ! : : Control . isReplay ( ) ) return true ;
2009-05-08 13:28:41 +00:00
// set new target plr
2010-09-29 01:44:05 +00:00
if ( C4Viewport * vp = : : Viewports . GetFirstViewport ( ) ) vp - > Init ( iToPlr , true ) ;
2009-05-08 13:28:41 +00:00
// done, always success (sync)
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnAddMsgBoardCmd ( C4PropList * _this , C4String * pstrCommand , C4String * pstrScript )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// safety
2010-03-28 18:58:01 +00:00
if ( ! pstrCommand | | ! pstrScript ) return false ;
2009-05-08 13:28:41 +00:00
// add command
2011-02-23 19:00:50 +00:00
: : MessageInput . AddCommand ( FnStringPar ( pstrCommand ) , FnStringPar ( pstrScript ) ) ;
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetGameSpeed ( C4PropList * _this , long iSpeed )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// safety
2010-03-28 18:58:01 +00:00
if ( iSpeed ) if ( ! Inside < long > ( iSpeed , 0 , 1000 ) ) return false ;
if ( ! iSpeed ) iSpeed = 38 ;
2009-05-08 13:28:41 +00:00
// set speed, restart timer
Application . SetGameTickDelay ( 1000 / iSpeed ) ;
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2010-10-02 00:30:59 +00:00
bool SimFlight ( C4Real & x , C4Real & y , C4Real & xdir , C4Real & ydir , int32_t iDensityMin , int32_t iDensityMax , int32_t & iIter ) ;
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static C4ValueArray * FnSimFlight ( C4PropList * _this , int X , int Y , Nillable < int > pvrXDir , Nillable < int > pvrYDir , Nillable < int > pviDensityMin , Nillable < int > pviDensityMax , Nillable < int > pviIter , int iPrec )
2009-08-16 13:18:07 +00:00
{
2010-10-02 00:30:59 +00:00
// check and set parameters
2012-05-15 01:03:47 +00:00
if ( Object ( _this ) )
2010-10-02 00:30:59 +00:00
{
2012-05-15 01:03:47 +00:00
X + = Object ( _this ) - > GetX ( ) ;
Y + = Object ( _this ) - > GetY ( ) ;
2010-10-02 00:30:59 +00:00
}
2012-05-15 01:03:47 +00:00
int XDir = pvrXDir . IsNil ( ) & & Object ( _this ) ? fixtoi ( Object ( _this ) - > xdir ) : static_cast < int > ( pvrXDir ) ;
int YDir = pvrXDir . IsNil ( ) & & Object ( _this ) ? fixtoi ( Object ( _this ) - > ydir ) : static_cast < int > ( pvrYDir ) ;
2009-05-08 13:28:41 +00:00
2010-10-03 10:15:19 +00:00
int iDensityMin = pviDensityMin . IsNil ( ) ? C4M_Solid : static_cast < int > ( pviDensityMin ) ;
int iDensityMax = pviDensityMax . IsNil ( ) ? 100 : static_cast < int > ( pviDensityMax ) ;
int iIter = pviIter . IsNil ( ) ? - 1 : static_cast < int > ( pviIter ) ;
2010-10-02 00:30:59 +00:00
if ( ! iPrec ) iPrec = 10 ;
2009-05-08 13:28:41 +00:00
2010-05-04 15:35:18 +00:00
// convert to C4Real
2010-10-02 00:30:59 +00:00
C4Real x = itofix ( X ) , y = itofix ( Y ) ,
xdir = itofix ( XDir , iPrec ) , ydir = itofix ( YDir , iPrec ) ;
2009-05-08 13:28:41 +00:00
// simulate
2010-03-28 18:58:01 +00:00
if ( ! SimFlight ( x , y , xdir , ydir , iDensityMin , iDensityMax , iIter ) )
2010-10-02 00:30:59 +00:00
{
iIter * = - 1 ;
2011-03-12 17:38:47 +00:00
}
2009-05-08 13:28:41 +00:00
2010-04-08 00:47:45 +00:00
// write results to array
2010-10-02 00:30:59 +00:00
C4ValueArray * pResults = new C4ValueArray ( 5 ) ;
2010-04-08 00:47:45 +00:00
pResults - > SetItem ( 0 , C4VInt ( fixtoi ( x ) ) ) ;
pResults - > SetItem ( 1 , C4VInt ( fixtoi ( y ) ) ) ;
pResults - > SetItem ( 2 , C4VInt ( fixtoi ( xdir * iPrec ) ) ) ;
pResults - > SetItem ( 3 , C4VInt ( fixtoi ( ydir * iPrec ) ) ) ;
2010-10-02 00:30:59 +00:00
pResults - > SetItem ( 4 , C4VInt ( iIter ) ) ;
return pResults ;
2009-08-16 13:18:07 +00:00
}
2010-10-02 00:30:59 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static long FnLoadScenarioSection ( C4PropList * _this , C4String * pstrSection , long dwFlags )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// safety
const char * szSection ;
2009-08-15 18:50:32 +00:00
if ( ! pstrSection | | ! * ( szSection = FnStringPar ( pstrSection ) ) ) return false ;
2009-05-08 13:28:41 +00:00
// try to load it
return Game . LoadScenarioSection ( szSection , dwFlags ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-20 00:04:46 +00:00
static C4Value FnAddEffect ( C4PropList * _this , C4String * szEffect , C4Object * pTarget ,
int iPrio , int iTimerInterval , C4Object * pCmdTarget , C4ID idCmdTarget ,
const C4Value & Val1 , const C4Value & Val2 , const C4Value & Val3 , const C4Value & Val4 )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// safety
2010-03-28 18:58:01 +00:00
if ( pTarget & & ! pTarget - > Status ) return C4Value ( ) ;
2011-03-16 18:07:18 +00:00
if ( ! szEffect | | ! * szEffect - > GetCStr ( ) | | ! iPrio ) return C4Value ( ) ;
2009-05-08 13:28:41 +00:00
// create effect
2012-05-20 00:04:46 +00:00
C4Effect * pEffect = C4Effect : : New ( pTarget , szEffect , iPrio , iTimerInterval , pCmdTarget , idCmdTarget , Val1 , Val2 , Val3 , Val4 ) ;
// return effect - may be 0 if the effect has been denied by another effect
2010-12-21 00:40:40 +00:00
if ( ! pEffect ) return C4Value ( ) ;
return C4VPropList ( pEffect ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static C4Effect * FnGetEffect ( C4PropList * _this , C4String * psEffectName , C4Object * pTarget , int index , int iMaxPriority )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
const char * szEffect = FnStringPar ( psEffectName ) ;
// get effects
C4Effect * pEffect = pTarget ? pTarget - > pEffects : Game . pGlobalEffects ;
2010-12-24 14:10:39 +00:00
if ( ! pEffect ) return NULL ;
2009-05-08 13:28:41 +00:00
// name/wildcard given: find effect by name and index
if ( szEffect & & * szEffect )
2010-12-24 14:10:39 +00:00
return pEffect - > Get ( szEffect , index , iMaxPriority ) ;
return NULL ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnRemoveEffect ( C4PropList * _this , C4String * psEffectName , C4Object * pTarget , C4Effect * pEffect2 , bool fDoNoCalls )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// evaluate parameters
const char * szEffect = FnStringPar ( psEffectName ) ;
2014-04-03 17:35:22 +00:00
// if the user passed an effect, it can be used straight-away
C4Effect * pEffect = pEffect2 ;
// otherwise, the correct effect will be searched in the target's effects or in the global ones
if ( ! pEffect )
{
pEffect = pTarget ? pTarget - > pEffects : Game . pGlobalEffects ;
2015-03-06 09:37:54 +00:00
// the object has no effects attached, nothing to look for
if ( ! pEffect ) return 0 ;
2014-04-03 17:35:22 +00:00
// name/wildcard given: find effect by name
if ( szEffect & & * szEffect )
pEffect = pEffect - > Get ( szEffect , 0 ) ;
}
// neither passed nor found - nothing to remove!
2009-05-08 13:28:41 +00:00
if ( ! pEffect ) return 0 ;
2014-04-03 17:35:22 +00:00
2009-05-08 13:28:41 +00:00
// kill it
if ( fDoNoCalls )
pEffect - > SetDead ( ) ;
else
pEffect - > Kill ( pTarget ) ;
// done, success
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-20 00:04:46 +00:00
static C4Value FnCheckEffect ( C4PropList * _this , C4String * psEffectName , C4Object * pTarget ,
int iPrio , int iTimerInterval ,
const C4Value & Val1 , const C4Value & Val2 , const C4Value & Val3 , const C4Value & Val4 )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
const char * szEffect = FnStringPar ( psEffectName ) ;
// safety
if ( pTarget & & ! pTarget - > Status ) return C4Value ( ) ;
if ( ! szEffect | | ! * szEffect ) return C4Value ( ) ;
// get effects
C4Effect * pEffect = pTarget ? pTarget - > pEffects : Game . pGlobalEffects ;
if ( ! pEffect ) return C4Value ( ) ;
// let them check
2012-05-20 00:04:46 +00:00
C4Effect * r = pEffect - > Check ( pTarget , szEffect , iPrio , iTimerInterval , Val1 , Val2 , Val3 , Val4 ) ;
2011-03-16 16:51:03 +00:00
if ( r = = ( C4Effect * ) C4Fx_Effect_Deny ) return C4VInt ( C4Fx_Effect_Deny ) ;
if ( r = = ( C4Effect * ) C4Fx_Effect_Annul ) return C4VInt ( C4Fx_Effect_Annul ) ;
return C4VPropList ( r ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetEffectCount ( C4PropList * _this , C4String * psEffectName , C4Object * pTarget , long iMaxPriority )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// evaluate parameters
const char * szEffect = FnStringPar ( psEffectName ) ;
// get effects
C4Effect * pEffect = pTarget ? pTarget - > pEffects : Game . pGlobalEffects ;
2009-08-15 18:50:32 +00:00
if ( ! pEffect ) return false ;
2009-05-08 13:28:41 +00:00
// count effects
if ( ! * szEffect ) szEffect = 0 ;
return pEffect - > GetCount ( szEffect , iMaxPriority ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-20 00:04:46 +00:00
static C4Value FnEffectCall ( C4PropList * _this , C4Value * Pars )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// evaluate parameters
2012-05-20 00:04:46 +00:00
C4Object * pTarget = Pars [ 0 ] . getObj ( ) ;
C4Effect * pEffect = Pars [ 1 ] . getPropList ( ) ? Pars [ 1 ] . getPropList ( ) - > GetEffect ( ) : 0 ;
C4String * psCallFn = Pars [ 2 ] . getStr ( ) ;
2009-05-08 13:28:41 +00:00
const char * szCallFn = FnStringPar ( psCallFn ) ;
// safety
if ( pTarget & & ! pTarget - > Status ) return C4Value ( ) ;
if ( ! szCallFn | | ! * szCallFn ) return C4Value ( ) ;
if ( ! pEffect ) return C4Value ( ) ;
// do call
2012-05-20 00:04:46 +00:00
return pEffect - > DoCall ( pTarget , szCallFn , Pars [ 3 ] , Pars [ 4 ] , Pars [ 5 ] , Pars [ 6 ] , Pars [ 7 ] , Pars [ 8 ] , Pars [ 9 ] ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetViewOffset ( C4PropList * _this , long iPlayer , long iX , long iY )
2010-03-28 18:58:01 +00:00
{
2015-01-04 21:07:30 +00:00
if ( ! ValidPlr ( iPlayer ) ) return false ;
2010-03-27 16:05:02 +00:00
// get player viewport
2010-09-29 01:44:05 +00:00
C4Viewport * pView = : : Viewports . GetViewport ( iPlayer ) ;
2010-03-28 18:58:01 +00:00
if ( ! pView ) return 1 ; // sync safety
2010-03-27 16:05:02 +00:00
// set
2015-01-03 21:51:02 +00:00
pView - > SetViewOffset ( iX , iY ) ;
2010-03-27 16:05:02 +00:00
// ok
2015-01-04 21:07:30 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static bool FnSetPreSend ( C4PropList * _this , long iToVal , C4String * pNewName )
2010-03-28 18:58:01 +00:00
{
2009-08-15 18:50:32 +00:00
if ( ! : : Control . isNetwork ( ) ) return true ;
2009-05-08 13:28:41 +00:00
// dbg: manual presend
const char * szClient = FnStringPar ( pNewName ) ;
if ( ! szClient | | ! * szClient | | WildcardMatch ( szClient , Game . Clients . getLocalName ( ) ) )
2010-03-28 18:58:01 +00:00
{
2009-06-15 22:06:37 +00:00
: : Control . Network . setTargetFPS ( iToVal ) ;
2009-06-05 15:14:20 +00:00
: : GraphicsSystem . FlashMessage ( FormatString ( " TargetFPS: %ld " , iToVal ) . getData ( ) ) ;
2010-03-27 16:05:02 +00:00
}
2010-03-28 18:58:01 +00:00
return true ;
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetPlayerID ( C4PropList * _this , long iPlayer )
2010-03-28 18:58:01 +00:00
{
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iPlayer ) ;
2009-05-08 13:28:41 +00:00
return pPlr ? pPlr - > ID : 0 ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetPlayerTeam ( C4PropList * _this , long iPlayer )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// get player
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iPlayer ) ;
2009-05-08 13:28:41 +00:00
if ( ! pPlr ) return 0 ;
// search team containing this player
C4Team * pTeam = Game . Teams . GetTeamByPlayerID ( pPlr - > ID ) ;
if ( pTeam ) return pTeam - > GetID ( ) ;
// special value of -1 indicating that the team is still to be chosen
if ( pPlr - > IsChosingTeam ( ) ) return - 1 ;
// No team.
return 0 ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetPlayerTeam ( C4PropList * _this , long iPlayer , long idNewTeam , bool fNoCalls )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// no team changing in league games
if ( Game . Parameters . isLeague ( ) ) return false ;
// get player
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iPlayer ) ;
2009-05-08 13:28:41 +00:00
if ( ! pPlr ) return false ;
C4PlayerInfo * pPlrInfo = pPlr - > GetInfo ( ) ;
if ( ! pPlrInfo ) return false ;
// already in that team?
if ( pPlr - > Team = = idNewTeam ) return true ;
// ask team setting if it's allowed (also checks for valid team)
if ( ! Game . Teams . IsJoin2TeamAllowed ( idNewTeam ) ) return false ;
// ask script if it's allowed
if ( ! fNoCalls )
2010-03-28 18:58:01 +00:00
{
2014-05-30 23:03:23 +00:00
if ( ! ! : : Game . GRBroadcast ( PSF_RejectTeamSwitch , & C4AulParSet ( iPlayer , idNewTeam ) , true , true ) )
2009-05-08 13:28:41 +00:00
return false ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// exit previous team
C4Team * pOldTeam = Game . Teams . GetTeamByPlayerID ( pPlr - > ID ) ;
int32_t idOldTeam = 0 ;
if ( pOldTeam )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
idOldTeam = pOldTeam - > GetID ( ) ;
pOldTeam - > RemovePlayerByID ( pPlr - > ID ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// enter new team
if ( idNewTeam )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4Team * pNewTeam = Game . Teams . GetGenerateTeamByID ( idNewTeam ) ;
if ( pNewTeam )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
pNewTeam - > AddPlayer ( * pPlrInfo , true ) ;
idNewTeam = pNewTeam - > GetID ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// unknown error
pPlr - > Team = idNewTeam = 0 ;
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// update hositlities if this is not a "silent" change
if ( ! fNoCalls )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
pPlr - > SetTeamHostility ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// do callback to reflect change in scenario
if ( ! fNoCalls )
2014-05-30 23:03:23 +00:00
: : Game . GRBroadcast ( PSF_OnTeamSwitch , & C4AulParSet ( iPlayer , idNewTeam , idOldTeam ) , true ) ;
2009-05-08 13:28:41 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static long FnGetTeamConfig ( C4PropList * _this , long iConfigValue )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// query value
switch ( iConfigValue )
2010-03-28 18:58:01 +00:00
{
case C4TeamList : : TEAM_Custom : return Game . Teams . IsCustom ( ) ;
case C4TeamList : : TEAM_Active : return Game . Teams . IsMultiTeams ( ) ;
case C4TeamList : : TEAM_AllowHostilityChange : return Game . Teams . IsHostilityChangeAllowed ( ) ;
case C4TeamList : : TEAM_Dist : return Game . Teams . GetTeamDist ( ) ;
case C4TeamList : : TEAM_AllowTeamSwitch : return Game . Teams . IsTeamSwitchAllowed ( ) ;
case C4TeamList : : TEAM_AutoGenerateTeams : return Game . Teams . IsAutoGenerateTeams ( ) ;
case C4TeamList : : TEAM_TeamColors : return Game . Teams . IsTeamColors ( ) ;
}
2009-05-08 13:28:41 +00:00
// undefined value
DebugLogF ( " GetTeamConfig: Unknown config value: %ld " , iConfigValue ) ;
return 0 ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static C4String * FnGetTeamName ( C4PropList * _this , long iTeam )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4Team * pTeam = Game . Teams . GetTeamByID ( iTeam ) ;
if ( ! pTeam ) return NULL ;
return String ( pTeam - > GetName ( ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetTeamColor ( C4PropList * _this , long iTeam )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4Team * pTeam = Game . Teams . GetTeamByID ( iTeam ) ;
return pTeam ? pTeam - > GetColor ( ) : 0u ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetTeamByIndex ( C4PropList * _this , long iIndex )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4Team * pTeam = Game . Teams . GetTeamByIndex ( iIndex ) ;
return pTeam ? pTeam - > GetID ( ) : 0 ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static long FnGetTeamCount ( C4PropList * _this )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
return Game . Teams . GetTeamCount ( ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static bool FnInitScenarioPlayer ( C4PropList * _this , long iPlayer , long idTeam )
2010-03-28 18:58:01 +00:00
{
2009-06-12 23:09:32 +00:00
C4Player * pPlr = : : Players . Get ( iPlayer ) ;
2009-05-08 13:28:41 +00:00
if ( ! pPlr ) return false ;
return pPlr - > ScenarioAndTeamInit ( idTeam ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetScoreboardData ( C4PropList * _this , long iRowID , long iColID , C4String * pText , long iData )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
Game . Scoreboard . SetCell ( iColID , iRowID , pText ? pText - > GetCStr ( ) : NULL , iData ) ;
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static C4String * FnGetScoreboardString ( C4PropList * _this , long iRowID , long iColID )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
return String ( Game . Scoreboard . GetCellString ( iColID , iRowID ) ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static int32_t FnGetScoreboardData ( C4PropList * _this , long iRowID , long iColID )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
return Game . Scoreboard . GetCellData ( iColID , iRowID ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnDoScoreboardShow ( C4PropList * _this , long iChange , long iForPlr )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
C4Player * pPlr ;
if ( iForPlr )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// abort if the specified player is not local - but always return if the player exists,
// to ensure sync safety
2009-08-15 18:50:32 +00:00
if ( ! ( pPlr = : : Players . Get ( iForPlr - 1 ) ) ) return false ;
if ( ! pPlr - > LocalControl ) return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
Game . Scoreboard . DoDlgShow ( iChange , false ) ;
2015-03-25 18:04:04 +00:00
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSortScoreboard ( C4PropList * _this , long iByColID , bool fReverse )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
return Game . Scoreboard . SortBy ( iByColID , ! ! fReverse ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static bool FnAddEvaluationData ( C4PropList * _this , C4String * pText , long idPlayer )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// safety
if ( ! pText ) return false ;
if ( ! pText - > GetCStr ( ) ) return false ;
if ( idPlayer & & ! Game . PlayerInfos . GetPlayerInfoByID ( idPlayer ) ) return false ;
// add data
Game . RoundResults . AddCustomEvaluationString ( pText - > GetCStr ( ) , idPlayer ) ;
return true ;
2010-03-28 18:58:01 +00:00
}
2009-09-04 14:09:05 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2016-01-03 01:39:11 +00:00
static void FnHideSettlementScoreInEvaluation ( C4PropList * _this , bool fHide )
2009-09-04 14:09:05 +00:00
{
Game . RoundResults . HideSettlementScore ( fHide ) ;
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnCustomMessage ( C4PropList * _this , C4String * pMsg , C4Object * pObj , Nillable < long > iOwner , long iOffX , long iOffY , long dwClr , C4ID idDeco , C4PropList * pSrc , long dwFlags , long iHSize )
2010-03-28 18:58:01 +00:00
{
2013-02-02 20:37:08 +00:00
// safeties: for global messages pSrc needs to be object/definition. For object-local messages, any proplist is OK
2011-08-05 12:58:16 +00:00
if ( pSrc )
2014-08-13 09:28:22 +00:00
if ( ! pSrc - > GetDef ( ) & & ! pSrc - > GetObject ( ) & & ! pSrc - > GetPropertyPropList ( P_Source ) & & ! pObj ) return false ;
2009-05-08 13:28:41 +00:00
if ( ! pMsg ) return false ;
if ( pObj & & ! pObj - > Status ) return false ;
const char * szMsg = pMsg - > GetCStr ( ) ;
if ( ! szMsg ) return false ;
if ( idDeco & & ! C4Id2Def ( idDeco ) ) return false ;
2011-07-30 23:32:02 +00:00
if ( iOwner . IsNil ( ) ) iOwner = NO_OWNER ;
2009-05-08 13:28:41 +00:00
// only one positioning flag per direction allowed
uint32_t hpos = dwFlags & ( C4GM_Left | C4GM_HCenter | C4GM_Right ) ;
uint32_t vpos = dwFlags & ( C4GM_Top | C4GM_VCenter | C4GM_Bottom ) ;
2010-01-25 04:00:59 +00:00
if ( ( ( hpos | ( hpos - 1 ) ) + 1 ) > > 1 ! = hpos )
2010-03-28 18:58:01 +00:00
{
2015-12-07 14:15:49 +00:00
throw C4AulExecError ( " CustomMessage: Only one horizontal positioning flag allowed " ) ;
2010-03-28 18:58:01 +00:00
}
2010-01-25 04:00:59 +00:00
if ( ( ( vpos | ( vpos - 1 ) ) + 1 ) > > 1 ! = vpos )
2010-03-28 18:58:01 +00:00
{
2015-12-07 14:15:49 +00:00
throw C4AulExecError ( " CustomMessage: Only one vertical positioning flag allowed " ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// message color
2009-08-23 21:46:56 +00:00
if ( ! dwClr ) dwClr = 0xffffffff ;
2010-02-07 17:18:25 +00:00
else dwClr = ( dwClr & 0xffffff ) | ( 0xff000000u - uint32_t ( dwClr | 0xff000000 ) ) ; // message internals use inverted alpha channel
2009-05-08 13:28:41 +00:00
// message type
int32_t iType ;
if ( pObj )
if ( iOwner ! = NO_OWNER )
iType = C4GM_TargetPlayer ;
else
iType = C4GM_Target ;
2010-03-28 18:58:01 +00:00
else if ( iOwner ! = NO_OWNER )
iType = C4GM_GlobalPlayer ;
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
iType = C4GM_Global ;
2009-05-08 13:28:41 +00:00
// remove speech?
StdStrBuf sMsg ;
sMsg . Ref ( szMsg ) ;
if ( dwFlags & C4GM_DropSpeech ) sMsg . SplitAtChar ( ' $ ' , NULL ) ;
// create it!
2011-08-05 12:58:16 +00:00
return : : Messages . New ( iType , sMsg , pObj , iOwner , iOffX , iOffY , ( uint32_t ) dwClr , idDeco , pSrc , dwFlags , iHSize ) ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2014-10-11 09:51:26 +00:00
static int FnGuiOpen ( C4PropList * _this , C4PropList * menu )
2013-02-12 19:39:20 +00:00
{
2014-10-13 16:48:03 +00:00
C4ScriptGuiWindow * window = new C4ScriptGuiWindow ;
2013-02-12 19:39:20 +00:00
2014-10-13 16:48:03 +00:00
: : Game . ScriptGuiRoot - > AddChild ( window ) ;
2013-02-12 19:39:20 +00:00
2013-04-07 20:52:45 +00:00
if ( ! window - > CreateFromPropList ( menu , true ) )
2013-02-12 19:39:20 +00:00
{
2014-10-13 16:48:03 +00:00
: : Game . ScriptGuiRoot - > RemoveChild ( window , false ) ;
2013-02-12 19:39:20 +00:00
return 0 ;
}
return window - > GetID ( ) ;
}
2014-10-13 16:48:03 +00:00
static bool FnGuiUpdateTag ( C4PropList * _this , C4String * tag , int32_t guiID , int32_t childID , C4Object * target )
2013-02-12 19:39:20 +00:00
{
2014-10-13 16:48:03 +00:00
C4ScriptGuiWindow * window = : : Game . ScriptGuiRoot - > GetChildByID ( guiID ) ;
2013-02-12 19:39:20 +00:00
if ( ! window ) return false ;
if ( childID ) // note: valid child IDs are always non-zero
{
2014-10-13 16:48:03 +00:00
C4ScriptGuiWindow * subwindow = window - > GetSubWindow ( childID , target ) ;
2013-02-12 19:39:20 +00:00
if ( ! subwindow ) return false ;
subwindow - > SetTag ( tag ) ;
return true ;
}
window - > SetTag ( tag ) ;
return true ;
}
2014-10-13 16:48:03 +00:00
static bool FnGuiClose ( C4PropList * _this , int32_t guiID , int32_t childID , C4Object * target )
2013-02-12 19:39:20 +00:00
{
2014-10-13 16:48:03 +00:00
C4ScriptGuiWindow * window = : : Game . ScriptGuiRoot - > GetChildByID ( guiID ) ;
2013-02-12 19:39:20 +00:00
if ( ! window ) return false ;
if ( childID ) // note: valid child IDs are always non-zero
{
2014-10-13 16:48:03 +00:00
C4ScriptGuiWindow * subwindow = window - > GetSubWindow ( childID , target ) ;
2013-02-12 19:39:20 +00:00
if ( ! subwindow ) return false ;
subwindow - > Close ( ) ;
return true ;
}
window - > Close ( ) ;
return true ;
}
2015-01-03 14:29:14 +00:00
static bool FnGuiUpdate ( C4PropList * _this , C4PropList * update , int32_t guiID , int32_t childID , C4Object * target )
2013-02-12 19:39:20 +00:00
{
if ( ! update ) return false ;
2014-10-13 16:48:03 +00:00
C4ScriptGuiWindow * window = : : Game . ScriptGuiRoot - > GetChildByID ( guiID ) ;
2013-02-12 19:39:20 +00:00
if ( ! window ) return false ;
if ( childID ) // note: valid child IDs are always non-zero
{
2014-10-13 16:48:03 +00:00
C4ScriptGuiWindow * subwindow = window - > GetSubWindow ( childID , target ) ;
2013-02-12 19:39:20 +00:00
if ( ! subwindow ) return false ;
2013-04-07 20:52:45 +00:00
subwindow - > CreateFromPropList ( update , false , true ) ;
2013-02-12 19:39:20 +00:00
return true ;
}
2013-04-07 20:52:45 +00:00
window - > CreateFromPropList ( update , false , true ) ;
2013-02-12 19:39:20 +00:00
return true ;
}
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static bool FnPauseGame ( C4PropList * _this , bool fToggle )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// not in replay (film)
2009-06-15 22:06:37 +00:00
if ( : : Control . isReplay ( ) ) return true ;
2009-05-08 13:28:41 +00:00
// script method for halting game (for films)
if ( fToggle )
Console . TogglePause ( ) ;
else
Console . DoHalt ( ) ;
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
2012-05-15 01:03:47 +00:00
static bool FnSetNextMission ( C4PropList * _this , C4String * szNextMission , C4String * szNextMissionText , C4String * szNextMissionDesc )
2010-03-28 18:58:01 +00:00
{
2009-04-01 21:36:58 +00:00
if ( ! szNextMission | | ! szNextMission - > GetData ( ) . getLength ( ) )
2009-05-08 13:28:41 +00:00
{
// param empty: clear next mission
Game . NextMission . Clear ( ) ;
Game . NextMissionText . Clear ( ) ;
}
else
{
// set next mission, button and button desc if given
2009-04-01 21:36:58 +00:00
Game . NextMission . Copy ( szNextMission - > GetData ( ) ) ;
2009-05-08 13:28:41 +00:00
if ( szNextMissionText & & szNextMissionText - > GetCStr ( ) )
{
2009-04-01 21:36:58 +00:00
Game . NextMissionText . Copy ( szNextMissionText - > GetData ( ) ) ;
2009-05-08 13:28:41 +00:00
}
else
{
Game . NextMissionText . Copy ( LoadResStr ( " IDS_BTN_NEXTMISSION " ) ) ;
}
if ( szNextMissionDesc & & szNextMissionDesc - > GetCStr ( ) )
{
2009-04-01 21:36:58 +00:00
Game . NextMissionDesc . Copy ( szNextMissionDesc - > GetData ( ) ) ;
2009-05-08 13:28:41 +00:00
}
else
{
Game . NextMissionDesc . Copy ( LoadResStr ( " IDS_DESC_NEXTMISSION " ) ) ;
}
}
return true ;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
Make GetPlayerControlState() query the current controller state
To keep compatibility with scripts which expect only binary buttons,
this adds a third parameter to the function which enables the new
functionality.
Bonus /script to test the controller stick x axis:
Schedule(GetCursor(), "Message(\"%d / %d\", GetPlayerControlState(0, CON_Left, true), GetPlayerControlState(0, CON_Right, true))", 10, 100000000)
Note that the values will be inconsistent if multiple analog sticks are
bound to the same control, as values from one stick will overwrite those
from the other one. This can happen even if you move only one stick.
2016-02-15 23:21:19 +00:00
static long FnGetPlayerControlState ( C4PropList * _this , long iPlr , long iControl , bool fMovedState )
2010-03-28 18:58:01 +00:00
{
2009-06-16 00:38:39 +00:00
// get control set to check
C4PlayerControl * pCheckCtrl = NULL ;
2015-03-25 18:04:04 +00:00
if ( iPlr ! = NO_OWNER )
2010-03-28 18:58:01 +00:00
{
2009-08-10 14:48:25 +00:00
C4Player * pPlr = : : Players . Get ( iPlr ) ;
2009-06-16 00:38:39 +00:00
if ( pPlr )
2010-03-28 18:58:01 +00:00
{
2009-06-16 00:38:39 +00:00
pCheckCtrl = & ( pPlr - > Control ) ;
}
2010-03-28 18:58:01 +00:00
}
2009-06-16 00:38:39 +00:00
// invalid player or no controls
if ( ! pCheckCtrl ) return 0 ;
// query control
const C4PlayerControl : : CSync : : ControlDownState * pControlState = pCheckCtrl - > GetControlDownState ( iControl ) ;
// no state means not down
if ( ! pControlState ) return 0 ;
Make GetPlayerControlState() query the current controller state
To keep compatibility with scripts which expect only binary buttons,
this adds a third parameter to the function which enables the new
functionality.
Bonus /script to test the controller stick x axis:
Schedule(GetCursor(), "Message(\"%d / %d\", GetPlayerControlState(0, CON_Left, true), GetPlayerControlState(0, CON_Right, true))", 10, 100000000)
Note that the values will be inconsistent if multiple analog sticks are
bound to the same control, as values from one stick will overwrite those
from the other one. This can happen even if you move only one stick.
2016-02-15 23:21:19 +00:00
// otherwise take either down-value or moved-value
return fMovedState ? pControlState - > MovedState . iStrength : pControlState - > DownState . iStrength ;
2010-03-28 18:58:01 +00:00
}
2009-06-16 00:38:39 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static bool FnSetPlayerControlEnabled ( C4PropList * _this , long iplr , long ctrl , bool is_enabled )
2009-12-27 18:11:14 +00:00
{
// get control set to check
C4PlayerControl * plrctrl = NULL ;
2015-03-25 18:04:04 +00:00
if ( iplr ! = NO_OWNER )
2010-03-28 18:58:01 +00:00
{
2009-12-27 18:11:14 +00:00
C4Player * plr = : : Players . Get ( iplr ) ;
if ( plr )
2010-03-28 18:58:01 +00:00
{
2009-12-27 18:11:14 +00:00
plrctrl = & ( plr - > Control ) ;
}
2010-03-28 18:58:01 +00:00
}
2009-12-27 18:11:14 +00:00
// invalid player or no controls
if ( ! plrctrl ) return false ;
// invalid control
2010-04-21 19:12:49 +00:00
if ( ctrl > = int32_t ( Game . PlayerControlDefs . GetCount ( ) ) ) return false ;
2009-12-27 18:11:14 +00:00
// query
return plrctrl - > SetControlDisabled ( ctrl , ! is_enabled ) ;
2010-03-28 18:58:01 +00:00
}
2009-12-27 18:11:14 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static bool FnGetPlayerControlEnabled ( C4PropList * _this , long iplr , long ctrl )
2009-12-27 18:11:14 +00:00
{
// get control set to check
C4PlayerControl * plrctrl = NULL ;
2015-03-25 18:04:04 +00:00
if ( iplr ! = NO_OWNER )
2010-03-28 18:58:01 +00:00
{
2009-12-27 18:11:14 +00:00
C4Player * plr = : : Players . Get ( iplr ) ;
if ( plr )
2010-03-28 18:58:01 +00:00
{
2009-12-27 18:11:14 +00:00
plrctrl = & ( plr - > Control ) ;
}
2010-03-28 18:58:01 +00:00
}
2009-12-27 18:11:14 +00:00
// invalid player or no controls
if ( ! plrctrl ) return false ;
return ! plrctrl - > IsControlDisabled ( ctrl ) ;
2010-03-28 18:58:01 +00:00
}
2009-12-27 18:11:14 +00:00
2014-01-22 07:00:37 +00:00
// undocumented!
2012-05-15 01:03:47 +00:00
static C4String * FnGetPlayerControlAssignment ( C4PropList * _this , long player , long control , bool human_readable , bool short_name )
2012-04-17 15:06:16 +00:00
{
// WARNING: As many functions returning strings, the result is not sync safe!
// "" is returned for invalid controls to make the obvious if(GetPlayerControlAssignmentName(...)) not cause a sync loss
// get desired assignment from parameters
C4Player * plr = : : Players . Get ( player ) ;
if ( ! plr ) return NULL ; // invalid player
if ( ! plr - > ControlSet ) return String ( " " ) ; // player has no control (remote player)
C4PlayerControlAssignment * assignment = plr - > ControlSet - > GetAssignmentByControl ( control ) ;
if ( ! assignment ) return String ( " " ) ;
// get assignment as readable string
return String ( assignment - > GetKeysAsString ( human_readable , short_name ) . getData ( ) ) ;
}
2016-02-17 20:44:01 +00:00
// strength: 0-1000, length: milliseconds
static bool FnPlayRumble ( C4PropList * _this , long player , long strength , long length )
{
// Check parameters.
if ( strength < = 0 | | strength > 1000 ) return false ;
if ( length < = 0 ) return false ;
// NO_OWNER: play rumble for all players (e.g. earthquakes)
if ( player = = NO_OWNER )
{
for ( C4Player * plr = : : Players . First ; plr ; plr = plr - > Next )
if ( plr - > Number ! = NO_OWNER ) // can't happen, but would be a crash if it did...
FnPlayRumble ( _this , plr - > Number , strength , length ) ;
return true ;
}
C4Player * plr = : : Players . Get ( player ) ;
if ( ! plr ) return false ;
if ( plr - > pGamepad )
plr - > pGamepad - > PlayRumble ( strength / 1000.f , length ) ;
// We can't return whether the rumble was actually played.
return true ;
}
static bool FnStopRumble ( C4PropList * _this , long player )
{
// NO_OWNER: stop rumble for all players
// Not sure whether this makes sense to do - mainly provided for symmetry with PlayRumble().
if ( player = = NO_OWNER )
{
for ( C4Player * plr = : : Players . First ; plr ; plr = plr - > Next )
if ( plr - > Number ! = NO_OWNER ) // can't happen, but would be a crash if it did...
FnStopRumble ( _this , plr - > Number ) ;
return true ;
}
C4Player * plr = : : Players . Get ( player ) ;
if ( ! plr ) return false ;
if ( plr - > pGamepad )
plr - > pGamepad - > StopRumble ( ) ;
return true ;
}
2013-03-18 23:23:37 +00:00
static int32_t FnGetStartupPlayerCount ( C4PropList * _this )
{
// returns number of players when game was initially started
return : : Game . StartupPlayerCount ;
}
2015-09-07 03:20:24 +00:00
static int32_t FnGetStartupTeamCount ( C4PropList * _this )
{
// returns number of non-empty teams when game was initially started
return : : Game . StartupTeamCount ;
}
2014-09-24 21:08:40 +00:00
static bool FnGainScenarioAchievement ( C4PropList * _this , C4String * achievement_name , Nillable < long > avalue , Nillable < long > player , C4String * for_scenario )
{
// safety
if ( ! achievement_name | | ! achievement_name - > GetData ( ) . getLength ( ) ) return false ;
// default parameter
2014-09-24 21:41:36 +00:00
long value = avalue . IsNil ( ) ? 1 : ( long ) avalue ;
2014-09-24 21:08:40 +00:00
// gain achievement
bool result = true ;
if ( ! player . IsNil ( ) & & player ! = NO_OWNER )
{
C4Player * plr = : : Players . Get ( player ) ;
if ( ! plr ) return false ;
result = plr - > GainScenarioAchievement ( achievement_name - > GetCStr ( ) , value , for_scenario ? for_scenario - > GetCStr ( ) : NULL ) ;
}
else
{
for ( C4Player * plr = : : Players . First ; plr ; plr = plr - > Next )
if ( ! plr - > GainScenarioAchievement ( achievement_name - > GetCStr ( ) , value , for_scenario ? for_scenario - > GetCStr ( ) : NULL ) )
result = false ;
}
2015-09-04 01:23:01 +00:00
return result ;
2014-09-24 21:08:40 +00:00
}
2014-12-07 18:51:40 +00:00
static long FnGetPXSCount ( C4PropList * _this , Nillable < long > iMaterial , Nillable < long > iX0 , Nillable < long > iY0 , Nillable < long > iWdt , Nillable < long > iHgt )
{
if ( iX0 . IsNil ( ) )
{
// Search everywhere
// All materials everywhere
if ( iMaterial . IsNil ( ) | | iMaterial = = MNone ) return : : PXS . GetCount ( ) ;
// Specific material everywhere
return : : PXS . GetCount ( iMaterial ) ;
}
else
{
// Material in area; offset by caller
int32_t x = iX0 , y = iY0 ;
if ( Object ( _this ) ) { x + = Object ( _this ) - > GetX ( ) ; y + = Object ( _this ) - > GetY ( ) ; }
2014-12-07 19:59:38 +00:00
return : : PXS . GetCount ( iMaterial . IsNil ( ) ? MNone : static_cast < int32_t > ( iMaterial ) , x , y , iWdt , iHgt ) ;
2014-12-07 18:51:40 +00:00
}
}
2011-03-04 12:49:41 +00:00
extern C4ScriptConstDef C4ScriptGameConstMap [ ] ;
extern C4ScriptFnDef C4ScriptGameFnMap [ ] ;
2010-07-30 18:50:35 +00:00
2011-03-04 12:49:41 +00:00
void InitGameFunctionMap ( C4AulScriptEngine * pEngine )
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// add all def constants (all Int)
2011-03-04 12:49:41 +00:00
for ( C4ScriptConstDef * pCDef = & C4ScriptGameConstMap [ 0 ] ; pCDef - > Identifier ; pCDef + + )
2010-03-28 18:58:01 +00:00
{
2009-07-20 21:04:29 +00:00
assert ( pCDef - > ValType = = C4V_Int ) ; // only int supported currently
2011-01-20 00:56:01 +00:00
pEngine - > RegisterGlobalConstant ( pCDef - > Identifier , C4VInt ( pCDef - > Data ) ) ;
2010-03-28 18:58:01 +00:00
}
2016-01-03 16:14:18 +00:00
C4PropListStatic * p = pEngine - > GetPropList ( ) ;
2009-05-08 13:28:41 +00:00
// add all def script funcs
2011-03-04 12:49:41 +00:00
for ( C4ScriptFnDef * pDef = & C4ScriptGameFnMap [ 0 ] ; pDef - > Identifier ; pDef + + )
2016-01-03 16:14:18 +00:00
new C4AulDefFunc ( p , pDef ) ;
# define F(f) ::AddFunc(p, #f, Fn##f)
F ( GetX ) ;
F ( GetY ) ;
F ( GetDefinition ) ;
F ( GetPlayerName ) ;
F ( GetPlayerType ) ;
F ( GetPlayerColor ) ;
F ( GetPlrClonkSkin ) ;
F ( CreateObject ) ;
F ( CreateObjectAbove ) ;
F ( CreateConstruction ) ;
F ( FindConstructionSite ) ;
F ( CheckConstructionSite ) ;
F ( Sound ) ;
F ( SoundAt ) ;
F ( ChangeSoundModifier ) ;
F ( SetGlobalSoundModifier ) ;
F ( Music ) ;
F ( MusicLevel ) ;
F ( SetPlayList ) ;
F ( SetPlrView ) ;
F ( SetPlrKnowledge ) ;
F ( GetPlrViewMode ) ;
F ( ResetCursorView ) ;
F ( GetPlrView ) ;
F ( GetWealth ) ;
F ( SetWealth ) ;
F ( DoPlayerScore ) ;
F ( GetPlayerScore ) ;
F ( GetPlayerScoreGain ) ;
F ( GetWind ) ;
F ( SetWind ) ;
F ( GetTemperature ) ;
F ( SetTemperature ) ;
F ( ShakeFree ) ;
F ( DigFree ) ;
F ( DigFreeRect ) ;
F ( ClearFreeRect ) ;
F ( Hostile ) ;
F ( SetHostility ) ;
F ( PlaceVegetation ) ;
F ( PlaceAnimal ) ;
F ( GameOver ) ;
F ( GetHiRank ) ;
F ( GetCrew ) ;
F ( GetCrewCount ) ;
F ( GetPlayerCount ) ;
F ( GetPlayerByIndex ) ;
F ( EliminatePlayer ) ;
F ( SurrenderPlayer ) ;
F ( GetLeagueScore ) ;
F ( SetLeaguePerformance ) ;
F ( SetLeagueProgressData ) ;
F ( GetLeagueProgressData ) ;
F ( CreateScriptPlayer ) ;
F ( GetCursor ) ;
F ( GetViewCursor ) ;
F ( SetCursor ) ;
F ( SetViewCursor ) ;
F ( GetMaterial ) ;
F ( GetBackMaterial ) ;
F ( GetTexture ) ;
F ( GetBackTexture ) ;
F ( GetAverageTextureColor ) ;
F ( GetMaterialCount ) ;
F ( GBackSolid ) ;
F ( GBackSemiSolid ) ;
F ( GBackLiquid ) ;
F ( GBackSky ) ;
F ( Material ) ;
F ( BlastFree ) ;
F ( InsertMaterial ) ;
F ( CanInsertMaterial ) ;
F ( LandscapeWidth ) ;
F ( LandscapeHeight ) ;
F ( SetAmbientBrightness ) ;
F ( GetAmbientBrightness ) ;
F ( SetSeason ) ;
F ( GetSeason ) ;
F ( SetClimate ) ;
F ( GetClimate ) ;
F ( SetPlayerZoomByViewRange ) ;
F ( GetPlayerZoomLimits ) ;
F ( SetPlayerZoom ) ;
F ( SetPlayerViewLock ) ;
F ( DoBaseMaterial ) ;
F ( DoBaseProduction ) ;
F ( GainMissionAccess ) ;
F ( IsNetwork ) ;
F ( GetLeague ) ;
: : AddFunc ( p , " TestMessageBoard " , FnTestMessageBoard , false ) ;
: : AddFunc ( p , " CallMessageBoard " , FnCallMessageBoard , false ) ;
: : AddFunc ( p , " AbortMessageBoard " , FnAbortMessageBoard , false ) ;
F ( SetFoW ) ;
F ( SetMaxPlayer ) ;
F ( Object ) ;
F ( GetTime ) ;
F ( GetMissionAccess ) ;
F ( MaterialName ) ;
F ( DrawMap ) ;
F ( DrawDefMap ) ;
F ( CreateParticle ) ;
F ( ClearParticles ) ;
F ( SetSkyAdjust ) ;
F ( SetMatAdjust ) ;
F ( GetSkyAdjust ) ;
F ( GetMatAdjust ) ;
F ( SetSkyParallax ) ;
F ( ReloadDef ) ;
F ( ReloadParticle ) ;
F ( SetGamma ) ;
F ( ResetGamma ) ;
F ( FrameCounter ) ;
F ( DrawMaterialQuad ) ;
F ( SetFilmView ) ;
F ( AddMsgBoardCmd ) ;
: : AddFunc ( p , " SetGameSpeed " , FnSetGameSpeed , false ) ;
: : AddFunc ( p , " DrawMatChunks " , FnDrawMatChunks , false ) ;
F ( GetPathLength ) ;
F ( SetTextureIndex ) ;
F ( RemoveUnusedTexMapEntries ) ;
F ( SimFlight ) ;
F ( LoadScenarioSection ) ;
F ( RemoveEffect ) ;
F ( GetEffect ) ;
F ( SetViewOffset ) ;
: : AddFunc ( p , " SetPreSend " , FnSetPreSend , false ) ;
F ( GetPlayerID ) ;
F ( GetPlayerTeam ) ;
F ( SetPlayerTeam ) ;
F ( GetTeamConfig ) ;
F ( GetTeamName ) ;
F ( GetTeamColor ) ;
F ( GetTeamByIndex ) ;
F ( GetTeamCount ) ;
: : AddFunc ( p , " InitScenarioPlayer " , FnInitScenarioPlayer , false ) ;
F ( SetScoreboardData ) ;
: : AddFunc ( p , " GetScoreboardString " , FnGetScoreboardString , false ) ;
: : AddFunc ( p , " GetScoreboardData " , FnGetScoreboardData , false ) ;
F ( DoScoreboardShow ) ;
F ( SortScoreboard ) ;
F ( AddEvaluationData ) ;
F ( HideSettlementScoreInEvaluation ) ;
F ( ExtractMaterialAmount ) ;
F ( GetEffectCount ) ;
F ( CustomMessage ) ;
F ( GuiOpen ) ;
F ( GuiUpdateTag ) ;
F ( GuiClose ) ;
F ( GuiUpdate ) ;
: : AddFunc ( p , " PauseGame " , FnPauseGame , false ) ;
F ( PathFree ) ;
F ( PathFree2 ) ;
F ( SetNextMission ) ;
F ( GetPlayerControlState ) ;
F ( SetPlayerControlEnabled ) ;
F ( GetPlayerControlEnabled ) ;
F ( GetPlayerControlAssignment ) ;
2016-02-17 20:44:01 +00:00
F ( PlayRumble ) ;
F ( StopRumble ) ;
2016-01-03 16:14:18 +00:00
F ( GetStartupPlayerCount ) ;
F ( GetStartupTeamCount ) ;
F ( EditCursor ) ;
F ( GainScenarioAchievement ) ;
F ( GetPXSCount ) ;
2012-05-20 00:04:46 +00:00
F ( GetPlrKnowledge ) ;
F ( GetComponent ) ;
2014-04-16 12:06:30 +00:00
F ( GetBaseMaterial ) ;
F ( GetBaseProduction ) ;
2012-05-20 00:04:46 +00:00
F ( GetDefCoreVal ) ;
F ( GetObjectVal ) ;
F ( GetObjectInfoCoreVal ) ;
F ( GetScenarioVal ) ;
F ( GetPlayerVal ) ;
F ( GetPlayerInfoCoreVal ) ;
F ( GetMaterialVal ) ;
F ( SetPlrExtraData ) ;
F ( GetPlrExtraData ) ;
F ( AddEffect ) ;
F ( CheckEffect ) ;
2013-09-21 14:48:28 +00:00
F ( PV_Linear ) ;
F ( PV_Random ) ;
2013-09-24 18:36:49 +00:00
F ( PV_Direction ) ;
F ( PV_Step ) ;
2013-09-27 11:28:38 +00:00
F ( PV_Speed ) ;
2013-10-19 12:50:43 +00:00
F ( PV_Wind ) ;
F ( PV_Gravity ) ;
2013-09-21 15:22:46 +00:00
// F(PV_KeyFrames); added below
2014-06-29 23:00:15 +00:00
F ( PV_Sin ) ;
2016-02-27 10:33:19 +00:00
F ( PV_Cos ) ;
2013-09-27 14:06:25 +00:00
F ( PC_Die ) ;
F ( PC_Bounce ) ;
2013-10-19 12:50:43 +00:00
F ( PC_Stop ) ;
2016-01-03 16:14:18 +00:00
F ( IncinerateLandscape ) ;
F ( GetGravity ) ;
F ( SetGravity ) ;
# undef F
2009-08-16 13:18:07 +00:00
}
2009-05-08 13:28:41 +00:00
2011-03-04 12:49:41 +00:00
C4ScriptConstDef C4ScriptGameConstMap [ ] =
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
{ " FX_OK " , C4V_Int , C4Fx_OK } , // generic standard behaviour for all effect callbacks
{ " FX_Effect_Deny " , C4V_Int , C4Fx_Effect_Deny } , // delete effect
{ " FX_Effect_Annul " , C4V_Int , C4Fx_Effect_Annul } , // delete effect, because it has annulled a countereffect
{ " FX_Effect_AnnulDoCalls " , C4V_Int , C4Fx_Effect_AnnulCalls } , // delete effect, because it has annulled a countereffect; temp readd countereffect
{ " FX_Execute_Kill " , C4V_Int , C4Fx_Execute_Kill } , // execute callback: Remove effect now
{ " FX_Stop_Deny " , C4V_Int , C4Fx_Stop_Deny } , // deny effect removal
{ " FX_Start_Deny " , C4V_Int , C4Fx_Start_Deny } , // deny effect start
{ " FX_Call_Normal " , C4V_Int , C4FxCall_Normal } , // normal call; effect is being added or removed
{ " FX_Call_Temp " , C4V_Int , C4FxCall_Temp } , // temp call; effect is being added or removed in responce to a lower-level effect change
{ " FX_Call_TempAddForRemoval " , C4V_Int , C4FxCall_TempAddForRemoval } , // temp call; effect is being added because it had been temp removed and is now removed forever
{ " FX_Call_RemoveClear " , C4V_Int , C4FxCall_RemoveClear } , // effect is being removed because object is being removed
{ " FX_Call_RemoveDeath " , C4V_Int , C4FxCall_RemoveDeath } , // effect is being removed because object died - return -1 to avoid removal
{ " FX_Call_DmgScript " , C4V_Int , C4FxCall_DmgScript } , // damage through script call
{ " FX_Call_DmgBlast " , C4V_Int , C4FxCall_DmgBlast } , // damage through blast
{ " FX_Call_DmgFire " , C4V_Int , C4FxCall_DmgFire } , // damage through fire
2014-04-06 15:15:13 +00:00
{ " FX_Call_DmgChop " , C4V_Int , C4FxCall_DmgChop } , // damage through chopping
2009-05-08 13:28:41 +00:00
{ " FX_Call_Energy " , C4V_Int , 32 } , // bitmask for generic energy loss
{ " FX_Call_EngScript " , C4V_Int , C4FxCall_EngScript } , // energy loss through script call
{ " FX_Call_EngBlast " , C4V_Int , C4FxCall_EngBlast } , // energy loss through blast
{ " FX_Call_EngObjHit " , C4V_Int , C4FxCall_EngObjHit } , // energy loss through object hitting the living
{ " FX_Call_EngFire " , C4V_Int , C4FxCall_EngFire } , // energy loss through fire
{ " FX_Call_EngBaseRefresh " , C4V_Int , C4FxCall_EngBaseRefresh } , // energy reload in base (also by base object, but that's normally not called)
{ " FX_Call_EngAsphyxiation " , C4V_Int , C4FxCall_EngAsphyxiation } , // energy loss through asphyxiaction
{ " FX_Call_EngCorrosion " , C4V_Int , C4FxCall_EngCorrosion } , // energy loss through corrosion (acid)
2010-12-07 17:57:27 +00:00
{ " FX_Call_EngGetPunched " , C4V_Int , C4FxCall_EngGetPunched } , // energy loss from punch
2009-05-08 13:28:41 +00:00
{ " NO_OWNER " , C4V_Int , NO_OWNER } , // invalid player number
// material density
{ " C4M_Vehicle " , C4V_Int , C4M_Vehicle } ,
{ " C4M_Solid " , C4V_Int , C4M_Solid } ,
{ " C4M_SemiSolid " , C4V_Int , C4M_SemiSolid } ,
{ " C4M_Liquid " , C4V_Int , C4M_Liquid } ,
{ " C4M_Background " , C4V_Int , C4M_Background } ,
// scoreboard
{ " SBRD_Caption " , C4V_Int , C4Scoreboard : : TitleKey } , // used to set row/coloumn headers
// teams - constants for GetTeamConfig
{ " TEAM_Custom " , C4V_Int , C4TeamList : : TEAM_Custom } ,
{ " TEAM_Active " , C4V_Int , C4TeamList : : TEAM_Active } ,
{ " TEAM_AllowHostilityChange " , C4V_Int , C4TeamList : : TEAM_AllowHostilityChange } ,
{ " TEAM_Dist " , C4V_Int , C4TeamList : : TEAM_Dist } ,
{ " TEAM_AllowTeamSwitch " , C4V_Int , C4TeamList : : TEAM_AllowTeamSwitch } ,
{ " TEAM_AutoGenerateTeams " , C4V_Int , C4TeamList : : TEAM_AutoGenerateTeams } ,
{ " TEAM_TeamColors " , C4V_Int , C4TeamList : : TEAM_TeamColors } ,
2010-03-28 18:58:01 +00:00
{ " C4FO_Not " , C4V_Int , C4FO_Not } ,
{ " C4FO_And " , C4V_Int , C4FO_And } ,
{ " C4FO_Or " , C4V_Int , C4FO_Or } ,
{ " C4FO_Exclude " , C4V_Int , C4FO_Exclude } ,
{ " C4FO_InRect " , C4V_Int , C4FO_InRect } ,
{ " C4FO_AtPoint " , C4V_Int , C4FO_AtPoint } ,
{ " C4FO_AtRect " , C4V_Int , C4FO_AtRect } ,
{ " C4FO_OnLine " , C4V_Int , C4FO_OnLine } ,
{ " C4FO_Distance " , C4V_Int , C4FO_Distance } ,
{ " C4FO_ID " , C4V_Int , C4FO_ID } ,
{ " C4FO_OCF " , C4V_Int , C4FO_OCF } ,
{ " C4FO_Category " , C4V_Int , C4FO_Category } ,
{ " C4FO_Action " , C4V_Int , C4FO_Action } ,
{ " C4FO_ActionTarget " , C4V_Int , C4FO_ActionTarget } ,
2011-12-28 18:33:19 +00:00
{ " C4FO_Procedure " , C4V_Int , C4FO_Procedure } ,
2010-03-28 18:58:01 +00:00
{ " C4FO_Container " , C4V_Int , C4FO_Container } ,
{ " C4FO_AnyContainer " , C4V_Int , C4FO_AnyContainer } ,
{ " C4FO_Owner " , C4V_Int , C4FO_Owner } ,
2011-12-28 18:33:19 +00:00
{ " C4FO_Controller " , C4V_Int , C4FO_Controller } ,
2010-03-28 18:58:01 +00:00
{ " C4FO_Func " , C4V_Int , C4FO_Func } ,
{ " C4FO_Layer " , C4V_Int , C4FO_Layer } ,
2015-04-28 16:59:50 +00:00
{ " C4FO_InArray " , C4V_Int , C4FO_InArray } ,
2015-09-03 03:55:45 +00:00
{ " C4FO_Property " , C4V_Int , C4FO_Property } ,
2015-09-10 00:19:45 +00:00
{ " C4FO_AnyLayer " , C4V_Int , C4FO_AnyLayer } ,
2012-02-10 20:48:48 +00:00
2011-12-28 18:33:19 +00:00
{ " MD_DragSource " , C4V_Int , C4MC_MD_DragSource } ,
{ " MD_DropTarget " , C4V_Int , C4MC_MD_DropTarget } ,
{ " MD_NoClick " , C4V_Int , C4MC_MD_NoClick } ,
2010-03-28 18:58:01 +00:00
{ " C4SO_Reverse " , C4V_Int , C4SO_Reverse } ,
{ " C4SO_Multiple " , C4V_Int , C4SO_Multiple } ,
{ " C4SO_Distance " , C4V_Int , C4SO_Distance } ,
{ " C4SO_Random " , C4V_Int , C4SO_Random } ,
{ " C4SO_Speed " , C4V_Int , C4SO_Speed } ,
{ " C4SO_Mass " , C4V_Int , C4SO_Mass } ,
{ " C4SO_Value " , C4V_Int , C4SO_Value } ,
{ " C4SO_Func " , C4V_Int , C4SO_Func } ,
2009-05-08 13:28:41 +00:00
{ " C4SECT_SaveLandscape " , C4V_Int , C4S_SAVE_LANDSCAPE } ,
{ " C4SECT_SaveObjects " , C4V_Int , C4S_SAVE_OBJECTS } ,
{ " C4SECT_KeepEffects " , C4V_Int , C4S_KEEP_EFFECTS } ,
{ " TEAMID_New " , C4V_Int , TEAMID_New } ,
2010-03-27 16:05:02 +00:00
{ " MSG_NoLinebreak " , C4V_Int , C4GM_NoBreak } ,
2009-05-08 13:28:41 +00:00
{ " MSG_Bottom " , C4V_Int , C4GM_Bottom } ,
{ " MSG_Multiple " , C4V_Int , C4GM_Multiple } ,
{ " MSG_Top " , C4V_Int , C4GM_Top } ,
{ " MSG_Left " , C4V_Int , C4GM_Left } ,
{ " MSG_Right " , C4V_Int , C4GM_Right } ,
{ " MSG_HCenter " , C4V_Int , C4GM_HCenter } ,
{ " MSG_VCenter " , C4V_Int , C4GM_VCenter } ,
{ " MSG_DropSpeech " , C4V_Int , C4GM_DropSpeech } ,
{ " MSG_WidthRel " , C4V_Int , C4GM_WidthRel } ,
{ " MSG_XRel " , C4V_Int , C4GM_XRel } ,
{ " MSG_YRel " , C4V_Int , C4GM_YRel } ,
2013-02-02 20:37:08 +00:00
{ " MSG_Zoom " , C4V_Int , C4GM_Zoom } ,
2009-05-08 13:28:41 +00:00
{ " C4PT_User " , C4V_Int , C4PT_User } ,
{ " C4PT_Script " , C4V_Int , C4PT_Script } ,
{ " CSPF_FixedAttributes " , C4V_Int , CSPF_FixedAttributes } ,
{ " CSPF_NoScenarioInit " , C4V_Int , CSPF_NoScenarioInit } ,
{ " CSPF_NoEliminationCheck " , C4V_Int , CSPF_NoEliminationCheck } ,
{ " CSPF_Invisible " , C4V_Int , CSPF_Invisible } ,
2010-02-09 19:09:32 +00:00
{ " DMQ_Sky " , C4V_Int , DMQ_Sky } ,
{ " DMQ_Sub " , C4V_Int , DMQ_Sub } ,
{ " DMQ_Bridge " , C4V_Int , DMQ_Bridge } ,
2011-03-12 17:38:47 +00:00
2010-09-08 21:49:42 +00:00
{ " PLRZOOM_Direct " , C4V_Int , PLRZOOM_Direct } ,
{ " PLRZOOM_NoIncrease " , C4V_Int , PLRZOOM_NoIncrease } ,
{ " PLRZOOM_NoDecrease " , C4V_Int , PLRZOOM_NoDecrease } ,
{ " PLRZOOM_LimitMin " , C4V_Int , PLRZOOM_LimitMin } ,
{ " PLRZOOM_LimitMax " , C4V_Int , PLRZOOM_LimitMax } ,
2014-05-11 08:30:41 +00:00
{ " PLRZOOM_Set " , C4V_Int , PLRZOOM_Set } ,
2010-09-08 21:49:42 +00:00
2013-10-18 10:33:31 +00:00
{ " ATTACH_Front " , C4V_Int , C4ATTACH_Front } ,
{ " ATTACH_Back " , C4V_Int , C4ATTACH_Back } ,
{ " ATTACH_MoveRelative " , C4V_Int , C4ATTACH_MoveRelative } ,
2015-08-28 01:44:23 +00:00
// sound modifier type
{ " C4SMT_Reverb " , C4V_Int , C4SoundModifier : : C4SMT_Reverb } ,
{ " C4SMT_Echo " , C4V_Int , C4SoundModifier : : C4SMT_Echo } ,
{ " C4SMT_Equalizer " , C4V_Int , C4SoundModifier : : C4SMT_Equalizer } ,
2014-10-13 16:48:03 +00:00
{ " GUI_SetTag " , C4V_Int , C4ScriptGuiWindowActionID : : SetTag } ,
{ " GUI_Call " , C4V_Int , C4ScriptGuiWindowActionID : : Call } ,
{ " GUI_GridLayout " , C4V_Int , C4ScriptGuiWindowStyleFlag : : GridLayout } ,
{ " GUI_VerticalLayout " , C4V_Int , C4ScriptGuiWindowStyleFlag : : VerticalLayout } ,
{ " GUI_TextVCenter " , C4V_Int , C4ScriptGuiWindowStyleFlag : : TextVCenter } ,
{ " GUI_TextHCenter " , C4V_Int , C4ScriptGuiWindowStyleFlag : : TextHCenter } ,
{ " GUI_TextRight " , C4V_Int , C4ScriptGuiWindowStyleFlag : : TextRight } ,
{ " GUI_TextBottom " , C4V_Int , C4ScriptGuiWindowStyleFlag : : TextBottom } ,
{ " GUI_TextTop " , C4V_Int , C4ScriptGuiWindowStyleFlag : : None } , // note that top and left are considered default
{ " GUI_TextLeft " , C4V_Int , C4ScriptGuiWindowStyleFlag : : None } , // they are only included for completeness
{ " GUI_FitChildren " , C4V_Int , C4ScriptGuiWindowStyleFlag : : FitChildren } ,
{ " GUI_Multiple " , C4V_Int , C4ScriptGuiWindowStyleFlag : : Multiple } ,
{ " GUI_IgnoreMouse " , C4V_Int , C4ScriptGuiWindowStyleFlag : : IgnoreMouse } ,
{ " GUI_NoCrop " , C4V_Int , C4ScriptGuiWindowStyleFlag : : NoCrop } ,
2016-02-15 15:20:37 +00:00
// control states
{ " CONS_Down " , C4V_Int , C4PlayerControl : : CONS_Down } ,
{ " CONS_Up " , C4V_Int , C4PlayerControl : : CONS_Up } ,
{ " CONS_Moved " , C4V_Int , C4PlayerControl : : CONS_Moved } ,
2016-02-26 19:40:07 +00:00
{ " PLRCON_MaxStrength " , C4V_Int , C4GamePadControl : : MaxStrength } ,
2011-05-09 12:37:28 +00:00
{ NULL , C4V_Nil , 0 }
2010-03-28 18:58:01 +00:00
} ;
2009-05-08 13:28:41 +00:00
2011-03-04 12:49:41 +00:00
C4ScriptFnDef C4ScriptGameFnMap [ ] =
2010-03-28 18:58:01 +00:00
{
2012-05-20 00:39:57 +00:00
{ " FindObject " , 1 , C4V_Object , { C4V_Array , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any } , FnFindObject } ,
{ " FindObjects " , 1 , C4V_Array , { C4V_Array , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any } , FnFindObjects } ,
{ " ObjectCount " , 1 , C4V_Int , { C4V_Array , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any } , FnObjectCount } ,
{ " GameCallEx " , 1 , C4V_Any , { C4V_String , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any } , FnGameCallEx } ,
{ " PlayerMessage " , 1 , C4V_Int , { C4V_Int , C4V_String , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any } , FnPlayerMessage } ,
{ " Message " , 1 , C4V_Bool , { C4V_String , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any } , FnMessage } ,
{ " AddMessage " , 1 , C4V_Bool , { C4V_String , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any } , FnAddMessage } ,
{ " EffectCall " , 1 , C4V_Any , { C4V_Object , C4V_PropList , C4V_String , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any } , FnEffectCall } ,
2013-09-21 15:22:46 +00:00
{ " PV_KeyFrames " , 1 , C4V_Array , { C4V_Int , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any , C4V_Any } , FnPV_KeyFrames } ,
2012-05-20 00:39:57 +00:00
{ NULL , 0 , C4V_Nil , { C4V_Nil , C4V_Nil , C4V_Nil , C4V_Nil , C4V_Nil , C4V_Nil , C4V_Nil , C4V_Nil , C4V_Nil , C4V_Nil } , 0 }
2010-03-28 18:58:01 +00:00
} ;