hedgewars/uGears.pas
changeset 11702 08cbd57ffb1a
parent 11700 ea1097d7bd27
child 11703 607e2e43acf0
equal deleted inserted replaced
11701:e71435e046a1 11702:08cbd57ffb1a
   736         ry:=GetRandom(750);
   736         ry:=GetRandom(750);
   737         AddGear(rx + snowLeft, LongInt(LAND_HEIGHT) + ry - 1300, gtFlake, 0, _0, _0, 0)
   737         AddGear(rx + snowLeft, LongInt(LAND_HEIGHT) + ry - 1300, gtFlake, 0, _0, _0, 0)
   738         end
   738         end
   739 end;
   739 end;
   740 
   740 
       
   741 // sort clans horizontally (bubble-sort, because why not)
       
   742 procedure SortHHsByColor();
       
   743 var n, newn, i, j, k, p: LongInt;
       
   744     ar, clar: array[0..Pred(cMaxHHs)] of PHedgehog;
       
   745     Count, clCount: Longword;
       
   746     tmpX, tmpY: hwFloat;
       
   747     hh1, hh2: PHedgehog;
       
   748 begin
       
   749 Count:= 0;
       
   750 // add hedgehogs to the array in clan order
       
   751 for p:= 0 to (ClansCount - 1) do
       
   752     with ClansArray[p]^ do
       
   753         begin
       
   754         // count hogs in this clan
       
   755         clCount:= 0;
       
   756         for j:= 0 to Pred(TeamsNumber) do
       
   757             with Teams[j]^ do
       
   758                 for i:= 0 to cMaxHHIndex do
       
   759                     if Hedgehogs[i].Gear <> nil then
       
   760                         begin
       
   761                         clar[clCount]:= @Hedgehogs[i];
       
   762                         inc(clCount);
       
   763                         end;
       
   764 
       
   765         // shuffle all hogs of this clan
       
   766         for i:= 0 to clCount - 1 do
       
   767             begin
       
   768             j:= GetRandom(clCount);
       
   769             k:= GetRandom(clCount);
       
   770             if clar[j] <> clar[k] then
       
   771                 begin
       
   772                 hh1:= clar[j];
       
   773                 clar[j]:= clar[k];
       
   774                 clar[k]:= hh1;
       
   775                 end;
       
   776             end;
       
   777 
       
   778         // add clan's hog to sorting array
       
   779         for i:= 0 to clCount - 1 do
       
   780             begin
       
   781             ar[Count]:= clar[i];
       
   782             inc(Count);
       
   783             end;
       
   784         end;
       
   785 
       
   786 n:= Count - 1;
       
   787 
       
   788 repeat
       
   789     newn:= 0;
       
   790     for i:= 1 to n do
       
   791         begin
       
   792         hh1:= ar[i-1];
       
   793         hh2:= ar[i];
       
   794         if hwRound(hh1^.Gear^.X) > hwRound(hh2^.Gear^.X) then
       
   795             begin
       
   796             tmpX:= hh1^.Gear^.X;
       
   797             tmpY:= hh1^.Gear^.Y;
       
   798             hh1^.Gear^.X:= hh2^.Gear^.X;
       
   799             hh1^.Gear^.Y:= hh2^.Gear^.Y;
       
   800             hh2^.Gear^.X:= tmpX;
       
   801             hh2^.Gear^.Y:= tmpY;
       
   802             newn:= i;
       
   803             end;
       
   804         end;
       
   805     n:= newn;
       
   806 until n = 0;
       
   807 
       
   808 end;
       
   809 
   741 procedure AssignHHCoords;
   810 procedure AssignHHCoords;
   742 var i, t, p, j: LongInt;
   811 var i, t, p, j: LongInt;
   743     ar: array[0..Pred(cMaxHHs)] of PHedgehog;
   812     ar: array[0..Pred(cMaxHHs)] of PHedgehog;
   744     Count: Longword;
   813     Count: Longword;
   745 begin
   814 begin
   746 if (GameFlags and gfPlaceHog) <> 0 then
   815 if (GameFlags and gfPlaceHog) <> 0 then
   747     PlacingHogs:= true;
   816     PlacingHogs:= true;
   748 // in divided-teams mode, slice map into vertical stripes of identical length and spawn one clan in each slice
   817 // in divided-teams mode, slice map into vertical stripes of identical length and spawn one clan in each slice
   749 if {((ClansCount = 2) or ((GameFlags and gfForts) <> 0)) and} ((GameFlags and gfDivideTeams) <> 0) then
   818 // this code is only for 2-clans and fort-mode games
       
   819 if ((ClansCount = 2) or ((GameFlags and gfForts) <> 0)) and ((GameFlags and gfDivideTeams) <> 0) then
   750     begin
   820     begin
   751     t:= 0;
   821     t:= 0;
   752     for p:= 0 to (ClansCount - 1) do
   822     for p:= 0 to (ClansCount - 1) do
   753         begin
   823         begin
   754         with ClansArray[p]^ do
   824         with ClansArray[p]^ do
   825                                      hwRound(Gear^.Y) - SpritesData[sprTargetBee].Height div 2, 
   895                                      hwRound(Gear^.Y) - SpritesData[sprTargetBee].Height div 2, 
   826                                      sprTargetBee, 0, lfBasic, $FFFFFFFF, false, false, false);
   896                                      sprTargetBee, 0, lfBasic, $FFFFFFFF, false, false, false);
   827                     Gear^.Y:= int2hwFloat(hwRound(Gear^.Y) - 16 - Gear^.Radius);
   897                     Gear^.Y:= int2hwFloat(hwRound(Gear^.Y) - 16 - Gear^.Radius);
   828                     Gear^.State:= Gear^.State and (not gsttmpFlag);
   898                     Gear^.State:= Gear^.State and (not gsttmpFlag);
   829                     AddFileLog('Carved a hole for hog at coordinates (' + inttostr(hwRound(Gear^.X)) + ',' + inttostr(hwRound(Gear^.Y)) + ')')
   899                     AddFileLog('Carved a hole for hog at coordinates (' + inttostr(hwRound(Gear^.X)) + ',' + inttostr(hwRound(Gear^.Y)) + ')')
   830                     end
   900                     end;
       
   901 
       
   902 
       
   903 // divided teams: in non-fort-modes with more than 2 clans, sort the hedgehogs from left to right by color
       
   904 if (ClansCount > 2) and ((GameFlags and gfForts) = 0) and ((GameFlags and gfDivideTeams) <> 0) then
       
   905     begin
       
   906     SortHHsByColor();
       
   907     end;
   831 end;
   908 end;
   832 
   909 
   833 
   910 
   834 {procedure AmmoFlameWork(Ammo: PGear);
   911 {procedure AmmoFlameWork(Ammo: PGear);
   835 var t: PGear;
   912 var t: PGear;