Game Development Community

Console function to get Terrain Name / Type

by Swaroop Reddy · in RTS Starter Kit · 04/09/2008 (6:16 pm) · 2 replies

In case any one is interested. I am posting a console function that I made to get the name of the terrain for a given x y location. getTerrainName(X Y); Along with the other console function getTerrainHeight, I have been able to map out my grid before the game begins with an array that contains the Z positions and terrain heignts

ConsoleFunction(getTerrainName, const char *, 2, 2, "Gets the terrain Name at the specified position.")
{
Point3F pos;
dSscanf(argv[1],"%g %g",&pos.x,&pos.y);
TerrainBlock *terrBlock = dynamic_cast(Sim::findObject("Terrain"));
if (terrBlock)
{
S32 mapIndex = terrBlock->getTerrainMapIndex( pos);
if (mapIndex != -1)
{
MaterialPropertyMap* pMatMap = static_cast(Sim::findObject("MaterialPropertyMap"));
const MaterialPropertyMap::MapEntry* pEntry = pMatMap->getMapEntryFromIndex(mapIndex);
char *returnBuffer = Con::getReturnBuffer( 256 );
dSprintf( returnBuffer, 256, "%s", pEntry->name);
return returnBuffer;
}
}
return NULL;
}

#1
04/10/2008 (7:13 am)
Great! it was you who was asking for this some time ago?

btw, what do you exactly mean by "get the name of the terrain"?
#2
04/10/2008 (9:45 pm)
NO it wasnt me that was asking for it. Name of the terrain is the same as the names of the texture files used in the mission for the terrain.