SAIL - A one little problem

Vše ohledně SAILu a tvorby modifikací do OW.
Post Reply
User avatar
Morphid
Site Administrator
Site Administrator
Czech Republic
Posts: 86
Joined: Sat Dec 25, 2010 12:48 am
Location: Czech Republic
Contact:

SAIL - A one little problem

Post by Morphid »

Hey, guys! I need some help.

I need a function that sorts indexes in the array according to the situation. I have 3 buildigns... I need to get them inside the array.. BUT!... First index will be a building that has the least of life. You have these buildings:

Code: Select all

arr[1] - Building 1: 580 lives
arr[2] - Building 2: 720 lives
arr[3] - Building 3: 1000 lives
Suddenly the enemy attacks to your base and building 3 needs repair more, than its sisters. The Building 1 is a little repaired.

Code: Select all

arr[1] - Building 1: 880 lives
arr[2] - Building 2: 720 lives
arr[3] - Building 3: 350 lives
Now, the Building 3 must be first and the Building 1 must be last. And now, I need a function for this.

Thanks.
Write your questions if you have them.
User avatar
Gwrhkhsh
Soldier level 6
Soldier level 6
Posts: 398
Joined: Fri May 21, 2010 5:56 pm
Location: Wrocław

Re: SAIL - A one little problem

Post by Gwrhkhsh »

Code: Select all

var a1, a2, b, i;
begin
   a1 = [580, 720, 1000]; a2 = [880, 720, 350];
   b = FilterAllUnits([[f_side, #side], [f_type, unit_building]]);

   for i = 1 to b do SetLives(b[i], a1[i]);

      // after the attack
      for i = 1 to b do SetLives(b[i], a2[i]); 
end;
I think that is what you need. If there are more buildings, just replace the filter in b with a list of the ones that should change.
User avatar
Morphid
Site Administrator
Site Administrator
Czech Republic
Posts: 86
Joined: Sat Dec 25, 2010 12:48 am
Location: Czech Republic
Contact:

Re: SAIL - A one little problem

Post by Morphid »

I don't want to set lives of buildings... I explain it again ;)

I have... e.g. 3 buildings [b1, b2, b3] in array BUILDS, these buildings are not sorted by lives.

Damage status of buildings:

Code: Select all

builds[1]: b1 = 720 (lives)
builds[2]: b2 = 580 (lives)
builds[3]: b3 = 1000 (lives)
And now, I need a function (or anything else) which sorts these buildings [b1, b2, b3] in BUILDS (array) according to their status. The most damaged building will be first, the second most damaged building will be second... etc.

Array after a function:

Code: Select all

builds[1]: b2 = 580 (lives)
builds[2]: b1 = 720 (lives)
builds[3]: b3 = 1000 (lives)
[ Added: 12:22 Sunday, 30-01-2011 +00:00(UTC) ]

I think... it's one of these functions:

Code: Select all

SortListByListAsc(items:tvalue values:tvalue)

SortListByListDesc(items:tvalue values:tvalue)
Radzio
Site Administrator
Site Administrator
Poland
Posts: 2898
Joined: Fri Jul 28, 2006 10:58 am
Location: Bialystok, Poland

Re: SAIL - A one little problem

Post by Radzio »

Code: Select all

var buildsHealth;
...
buildsHealth:= [];
for un in builds do
  buildsHealth:= buildsHealth ^ GetLives(un);
builds:= SortListByListAsc(builds, buildsHealth);
Post Reply