Goto https://www.stucuk.netGoto https://www.atlanticaonlinewiki.comGoto


It is currently Fri Apr 19, 2019 9:24 pm

All times are UTC [ DST ]

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Placing environment objects in an area
PostPosted: Sat Jul 25, 2009 12:58 am 
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1130
Location: Denmark
If you want to randomize your map or make a stone sledge (like I wanted in my mod :P ) this function could come in useful. It places a specified amount of environment objects in an area. If it is not possible to place all the wanted environment objects in the area because of lack of space or obstacles like buildings, units or other environment objects, the function will only generate the possible amount of environment objects (not causing the program to freeze).

Export Function PlaceEnvironmentArea(environment,numbers_list,amount,area);
     var area_list, area_list_x, area_list_y, a, rand_num, rand_hex_x, rand_hex_y;
          area_list = AreaToList(area,0);
          if area_list = 0 or amount = 0 then exit;

          area_list_x = area_list[1];
          area_list_y = area_list[2];

          a = 0;

          a = a + 1;

          if not ValidHex(area_list_x[a], area_list_y[a]) or HexInfo(area_list_x[a], area_list_y[a]) <> 0 then
                    area_list_x = Delete(area_list_x, a);
                    area_list_y = Delete(area_list_y, a);
                    a = a - 1;
          until a = area_list_x;

          //hvis der skal placeres flere environments end der er plads til nedsættes antallet der skal placeres
          if amount > area_list_x then amount = area_list_x;

          rand_num = Rand(1,area_list_x);
          rand_hex_x = area_list_x[rand_num];
          rand_hex_y = area_list_y[rand_num];

          if numbers_list = 0 then
          else PlaceEnvironment(rand_hex_x,rand_hex_y,environment,numbers_list[Rand(1,numbers_list)]);

          if IsEnvironment(rand_hex_x,rand_hex_y) then amount = amount - 1;

          area_list_x = Delete(area_list_x, rand_num);
          area_list_y = Delete(area_list_y, rand_num);
          until amount = 0;

"environment" must be an integer telling from which environment cathegory the objects should be chosen.
"numbers_list" must be a list of numbers (the numbers of the objects in the specified environment cathegory). The function will (randomly) place these objects only. If "numbers_list" if set to 0/false, the function will pick random objects from the whole environment cathegory.
"amount" is of course the amount if objects you want to place.
"area" - hmm... I wonder... :)

Note: The program may lagg a bit if the function must place > 50 objects.

EDIT1: Function improved so it's now about 60% faster than b4 (!)
EDIT2: Fixed function so it now places the right amount of objects if there isn't any units in the area
EDIT3: Minor function speed improvement

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Original War is an RTS / RPG game by Altar Games
Original War Support is not part of Altar Games but is maintaining Original War for Altar Games

Privacy Policy