.com.unity Forums
  The Official e-Store of Shrapnel Games

This Month's Specials

Air Assault Task Force- Save $8.00
Bronze- Save $10.00

   







Go Back   .com.unity Forums > Illwinter Game Design > Dominions 3: The Awakening > Scenarios, Maps and Mods

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old January 14th, 2007, 07:20 AM
Jack_Trowell's Avatar

Jack_Trowell Jack_Trowell is offline
Second Lieutenant
 
Join Date: Oct 2006
Location: Toulouse, FRANCE
Posts: 436
Thanks: 150
Thanked 21 Times in 13 Posts
Jack_Trowell is on a distinguished road
Default Re: Simple Terrain Calculator...

For those that prefer Perl, here's my similar function (from my perl dom library project).

The function return an array with the list of all types.

Quote:

# extract list of terrain types from the numeric code
sub get_terrain_types_from_code($); # function prototype, prevent warning when the function try to call itself recursively in strict mode
sub get_terrain_types_from_code($)
{
my $terrain_code = shift;

if ($terrain_code !~ /^[0-9]+$/)
{
error("[get_terrain_types_from_code] terrain code must be numeric value ('$terrain_code')");
}

my @terrain_types = ();

# terrain code is the sum of the successives individual terrain type code values
if ($terrain_code >= 4194304) # "edgemount" 4194304
{
# code >= 4194304 means that province type include "edgemount"
push (@terrain_types, "edgemount");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 4194304));
}
elsif ($terrain_code >= 2097152) # "priestsite" 2097152
{
# code >= 2097152 means that province type include "priestsite"
push (@terrain_types, "priestsite");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 2097152));
}
elsif ($terrain_code >= 1048576) # "bloodsite" 1048576
{
# now you should know how it works ... ^_^
push (@terrain_types, "bloodsite");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 1048576));
}
elsif ($terrain_code >= 524288) # "naturesite" 524288
{
# add the type to the list
push (@terrain_types, "naturesite");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 524288));
}
elsif ($terrain_code >= 262144) # "deathsite" 262144
{
# add the type to the list
push (@terrain_types, "deathsite");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 262144));
}
elsif ($terrain_code >= 131072) # "astralsite" 131072
{
# add the type to the list
push (@terrain_types, "astralsite");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 131072));
}
elsif ($terrain_code >= 65536) # "earthsite" 65536
{
# add the type to the list
push (@terrain_types, "earthsite");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 65536));
}
elsif ($terrain_code >= 32768) # "watersite" 32768
{
# add the type to the list
push (@terrain_types, "watersite");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 32768));
}
elsif ($terrain_code >= 16384) # "airsite" 16384
{
# add the type to the list
push (@terrain_types, "airsite");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 16384));
}
elsif ($terrain_code >= 8192) # "firesite" 8192
{
# add the type to the list
push (@terrain_types, "firesite");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 8192));
}
elsif ($terrain_code >= 4096) # "cave" 4096
{
# add the type to the list (at last : a true terrain type !)
push (@terrain_types, "cave");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 4096));
}
elsif ($terrain_code >= 2048) # "deep" 2048
{
# add the type to the list
push (@terrain_types, "deep");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 2048));
}
elsif ($terrain_code >= 1024) # "manysites" 1024
{
# add the type to the list
push (@terrain_types, "manysites");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 1024));
}
elsif ($terrain_code >= 512) # "nostart" 512
{
# add the type to the list
push (@terrain_types, "nostart");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 512));
}
elsif ($terrain_code >= 256) # "farm" 256
{
# add the type to the list
push (@terrain_types, "farm");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 256));
}
elsif ($terrain_code >= 128) # "forest" 128
{
# add the type to the list
push (@terrain_types, "forest");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 128));
}
elsif ($terrain_code >= 64) # "waste" 64
{
# add the type to the list
push (@terrain_types, "waste");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 64));
}
elsif ($terrain_code >= 32) # "swamp" 32
{
# add the type to the list
push (@terrain_types, "swamp");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 32));
}
elsif ($terrain_code >= 16) # "mountain" 16
{
# add the type to the list
push (@terrain_types, "mountain");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 16));
}
elsif ($terrain_code >= 8) # "somewater" 8
{
# add the type to the list
push (@terrain_types, "somewater");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 8));
}
elsif ($terrain_code >= 4) # "sea" 4
{
# add the type to the list
push (@terrain_types, "sea");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 4));
}
elsif ($terrain_code >= 2) # "large" 2
{
# add the type to the list
push (@terrain_types, "large");
# now get the other types (if any) by recursive call
push (@terrain_types, get_terrain_types_from_code($terrain_code - 2));
}
elsif ($terrain_code >= 1) # "small" 1
{
# add the type to the list
push (@terrain_types, "small");
# no other type, we're done
}

return @terrain_types;
}

__________________
Q: "How many Vorlons does it takes to change a lightbulb ?"
A: "Yes !" <stranges noises>
--
Dominions Map validator and randomizer : http://dominions.realites.org
Dominions Map editor v0.75b : http://dominions.realites.org/map_editor
Reply With Quote
 

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 02:26 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.