Announcement

Collapse
No announcement yet.

DESIGN: A couple of map good functions for SLIC

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DESIGN: A couple of map good functions for SLIC

    Haven't packaged yet, but has been compiled, and seems to work just fine.

    In slicfunc.h (prior to last #endif)

    Code:
    // New good slic function prototypes.  See cpp for details
    SLICFUNC(SFR_VOID, PlantSpecificGood);
    SLICFUNC(SFR_VOID, RemoveGood);
    In SlicEngine.cpp (at the end of AddBuiltinFunctions() )

    Code:
    	#if !defined(ACTIVISION_ORIGINAL)
    	// new good functions by MrBaggins
    	m_functionHash->Add(new Slic_PlantSpecificGood);
    	m_functionHash->Add(new Slic_RemoveGood);
    	#endif
    In SlicFunc.cpp (at the end)

    Code:
    //----------------------------------------------------------------------------
    //
    // Authored   : MrBaggins
    //
    // Name       : Slic_PlantSpecificGood
    //
    // Description: Rather than planting a random good, as per the standard SLIC
    //              function, this allows the specification of which good subtype
    //              to plant
    //
    // Parameters : SlicArg 0: location
    //              SlicArg 1: int
    //
    // Globals    : g_theWorld	: World gamestate functionality
    //                   g_tiledMap  : UI update functionality
    //
    // Returns    : SFN_ERROR		: execution result
    //
    // Remark(s)  : Allows for the specification of a good sub
    //		a range of 0 (no good), or 1-4 (the specific good subtype,
    //		as defined in ctp2_data\default\gamedata\goods.txt//
    //----------------------------------------------------------------------------
    
    SFN_ERROR Slic_PlantSpecificGood::Call(SlicArgList *args)
    {
    	#if !defined(ACTIVISION_ORIGINAL)
    
    	if(args->m_numArgs != 2)
    		return SFN_ERROR_NUM_ARGS;
    	
    	MapPoint pos;
    	if(!args->GetPos(0, pos))
    		return SFN_ERROR_TYPE_ARGS;
    	
    	sint32 goodsubtype;
    	if(!args->GetInt(1, goodsubtype))
    		return SFN_ERROR_TYPE_ARGS;
    	
    	if(goodsubtype<0 || goodsubtype>4)
    		return SFN_ERROR_OUT_OF_RANGE;
    
    
    	g_theWorld->SetGood(pos.x, pos.y, goodsubtype);
    	g_tiledMap->PostProcessTile(pos, g_theWorld->GetTileInfo(pos));
    	g_tiledMap->TileChanged(pos);
    	g_tiledMap->RedrawTile(&pos);
    
    	#endif
    
    	return SFN_ERROR_OK;	
    }
    
    //----------------------------------------------------------------------------
    //
    // Authored   : MrBaggins
    //
    // Name       : Slic_RemoveGood
    //
    // Description: New complimentary function to PlantGood
    //
    // Parameters : SlicArg 0: location
    //
    // Globals    : g_theWorld	: World gamestate functionality
    //				g_tiledMap  : UI update functionality
    //
    // Returns    : SFN_ERROR		: execution result
    //
    //----------------------------------------------------------------------------
    
    
    
    SFN_ERROR Slic_RemoveGood::Call(SlicArgList *args)
    {
    
    	#if !defined(ACTIVISION_ORIGINAL)
    
    	if(args->m_numArgs != 1)
    		return SFN_ERROR_NUM_ARGS;
    
    	MapPoint pos;
    	if(!args->GetPos(0, pos))
    		return SFN_ERROR_TYPE_ARGS;
    
    	g_theWorld->SetGood(pos.x, pos.y, 0);
    	// plants a good of subtype 0 AKA no good, at location x,y.
    	g_tiledMap->PostProcessTile(pos, g_theWorld->GetTileInfo(pos));
    	g_tiledMap->TileChanged(pos);
    	g_tiledMap->RedrawTile(&pos);
    	
    	#endif
    
    	return SFN_ERROR_OK;
    }

  • #2
    One note to the #if and #endif statements. These are precompiler derectives so first it is searched for such derectives, if the statement behind the #if is true the following code until an #endif or #else is left in otherwise it is removed. So you shouldn't place the precompiler derectives inside the functions if you added them entirely, but outside, and that should also be done for the other functions and code I added to the file, unfortunatly I didn't know it better at that time and therefore huge blocks of code are outside of these #if #else #endif blocks.

    -Martin
    Civ2 military advisor: "No complaints, Sir!"

    Comment

    Working...
    X