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;
}
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
if (terrBlock)
{
S32 mapIndex = terrBlock->getTerrainMapIndex( pos);
if (mapIndex != -1)
{
MaterialPropertyMap* pMatMap = static_cast
const MaterialPropertyMap::MapEntry* pEntry = pMatMap->getMapEntryFromIndex(mapIndex);
char *returnBuffer = Con::getReturnBuffer( 256 );
dSprintf( returnBuffer, 256, "%s", pEntry->name);
return returnBuffer;
}
}
return NULL;
}
About the author
#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.
Torque 3D Owner Novack
CyberianSoftware
btw, what do you exactly mean by "get the name of the terrain"?