hedgewars/uVisualGearsHandlers.pas
branchwebgl
changeset 9950 2759212a27de
parent 9521 8054d9d775fd
parent 9764 8dc9d268330f
child 9960 fac73b8a52d3
equal deleted inserted replaced
9521:8054d9d775fd 9950:2759212a27de
    69 procedure doStepBulletHit(Gear: PVisualGear; Steps: Longword);
    69 procedure doStepBulletHit(Gear: PVisualGear; Steps: Longword);
    70 procedure doStepCircle(Gear: PVisualGear; Steps: Longword);
    70 procedure doStepCircle(Gear: PVisualGear; Steps: Longword);
    71 procedure doStepSmoothWindBar(Gear: PVisualGear; Steps: Longword);
    71 procedure doStepSmoothWindBar(Gear: PVisualGear; Steps: Longword);
    72 procedure doStepStraightShot(Gear: PVisualGear; Steps: Longword);
    72 procedure doStepStraightShot(Gear: PVisualGear; Steps: Longword);
    73 
    73 
       
    74 function isSorterActive: boolean; inline;
    74 procedure initModule;
    75 procedure initModule;
    75 
    76 
    76 implementation
    77 implementation
    77 uses uVariables, Math, uConsts, uVisualGearsList, uFloat, uSound, uRenderUtils, uWorld;
    78 uses uVariables, Math, uConsts, uVisualGearsList, uFloat, uSound, uRenderUtils, uWorld;
    78 
    79 
   481 var thexchar: array[0..cMaxTeams] of
   482 var thexchar: array[0..cMaxTeams] of
   482             record
   483             record
   483             dy, ny, dw: LongInt;
   484             dy, ny, dw: LongInt;
   484             team: PTeam;
   485             team: PTeam;
   485             SortFactor: QWord;
   486             SortFactor: QWord;
       
   487             hdw: array[0..cMaxHHIndex] of LongInt;
   486             end;
   488             end;
   487     currsorter: PVisualGear = nil;
   489     currsorter: PVisualGear = nil;
   488 
   490 
       
   491 function isSorterActive: boolean; inline;
       
   492 begin
       
   493     isSorterActive:= currsorter <> nil
       
   494 end;
       
   495 
   489 procedure doStepTeamHealthSorterWork(Gear: PVisualGear; Steps: Longword);
   496 procedure doStepTeamHealthSorterWork(Gear: PVisualGear; Steps: Longword);
   490 var i, t: LongInt;
   497 var i, t, h: LongInt;
   491 begin
   498 begin
   492 for t:= 1 to min(Steps, Gear^.Timer) do
   499 for t:= 1 to min(Steps, Gear^.Timer) do
   493     begin
   500     begin
   494     dec(Gear^.Timer);
   501     dec(Gear^.Timer);
   495     if (Gear^.Timer and 15) = 0 then
   502     if (Gear^.Timer and 15) = 0 then
   496         for i:= 0 to Pred(TeamsCount) do
   503         for i:= 0 to Pred(TeamsCount) do
   497             with thexchar[i] do
   504             with thexchar[i] do
   498                 begin
   505                 begin
   499                 {$WARNINGS OFF}
   506                 {$WARNINGS OFF}
   500                 team^.DrawHealthY:= ny + dy * LongInt(Gear^.Timer) div cSorterWorkTime;
   507                 team^.DrawHealthY:= ny + dy * LongInt(Gear^.Timer) div cSorterWorkTime;
   501                 team^.TeamHealthBarWidth:= team^.NewTeamHealthBarWidth + dw * LongInt(Gear^.Timer) div cSorterWorkTime;
   508                 team^.TeamHealthBarHealth:= team^.TeamHealth + dw * LongInt(Gear^.Timer) div cSorterWorkTime;
       
   509 
       
   510                 for h:= 0 to cMaxHHIndex do
       
   511                     if (team^.Hedgehogs[h].Gear <> nil) then
       
   512                         team^.Hedgehogs[h].HealthBarHealth:= team^.Hedgehogs[h].Gear^.Health + hdw[h] * LongInt(Gear^.Timer) div cSorterWorkTime
       
   513                     else
       
   514                         team^.Hedgehogs[h].HealthBarHealth:= hdw[h] * LongInt(Gear^.Timer) div cSorterWorkTime;
   502                 {$WARNINGS ON}
   515                 {$WARNINGS ON}
   503                 end;
   516                 end;
   504     end;
   517     end;
   505 
   518 
   506 if (Gear^.Timer = 0) or (currsorter <> Gear) then
   519 if (Gear^.Timer = 0) or (currsorter <> Gear) then
   513 end;
   526 end;
   514 
   527 
   515 procedure doStepTeamHealthSorter(Gear: PVisualGear; Steps: Longword);
   528 procedure doStepTeamHealthSorter(Gear: PVisualGear; Steps: Longword);
   516 var i: Longword;
   529 var i: Longword;
   517     b: boolean;
   530     b: boolean;
   518     t: LongInt;
   531     t, h: LongInt;
   519 begin
   532 begin
   520 {$IFNDEF PAS2C}
   533 {$IFNDEF PAS2C}
   521 Steps:= Steps; // avoid compiler hint
   534 Steps:= Steps; // avoid compiler hint
   522 {$ENDIF}
   535 {$ENDIF}
   523 
   536 
   524 for t:= 0 to Pred(TeamsCount) do
   537 for t:= 0 to Pred(TeamsCount) do
   525     with thexchar[t] do
   538     with thexchar[t] do
   526         begin
   539         begin
   527         team:= TeamsArray[t];
   540         team:= TeamsArray[t];
   528         dy:= team^.DrawHealthY;
   541         dy:= team^.DrawHealthY;
   529         dw:= team^.TeamHealthBarWidth - team^.NewTeamHealthBarWidth;
   542         dw:= team^.TeamHealthBarHealth - team^.TeamHealth;
   530         if team^.TeamHealth > 0 then
   543         if team^.TeamHealth > 0 then
   531             begin
   544             begin
   532             SortFactor:= team^.Clan^.ClanHealth;
   545             SortFactor:= team^.Clan^.ClanHealth;
   533             SortFactor:= (SortFactor shl  3) + team^.Clan^.ClanIndex;
   546             SortFactor:= (SortFactor shl  3) + team^.Clan^.ClanIndex;
   534             SortFactor:= (SortFactor shl 30) + team^.TeamHealth;
   547             SortFactor:= (SortFactor shl 30) + team^.TeamHealth;
   535             end
   548             end
   536         else
   549         else
   537             SortFactor:= 0;
   550             SortFactor:= 0;
       
   551 
       
   552         for h:= 0 to cMaxHHIndex do
       
   553             if (team^.Hedgehogs[h].Gear <> nil) then
       
   554                 hdw[h]:= team^.Hedgehogs[h].HealthBarHealth - team^.Hedgehogs[h].Gear^.Health
       
   555             else
       
   556                 hdw[h]:= team^.Hedgehogs[h].HealthBarHealth;
   538         end;
   557         end;
   539 
   558 
   540 if TeamsCount > 1 then
   559 if TeamsCount > 1 then
   541     repeat
   560     repeat
   542     b:= true;
   561     b:= true;
   553 t:= - 4;
   572 t:= - 4;
   554 for i:= 0 to Pred(TeamsCount) do
   573 for i:= 0 to Pred(TeamsCount) do
   555         with thexchar[i] do
   574         with thexchar[i] do
   556           if team^.TeamHealth > 0 then
   575           if team^.TeamHealth > 0 then
   557             begin
   576             begin
   558             dec(t, team^.HealthTex^.h + 2);
   577             dec(t, team^.Clan^.HealthTex^.h + 2);
   559             ny:= t;
   578             ny:= t;
   560             dy:= dy - ny
   579             dy:= dy - ny
   561             end;
   580             end;
   562 
   581 
   563 Gear^.Timer:= cSorterWorkTime;
   582 Gear^.Timer:= cSorterWorkTime;
   571 begin
   590 begin
   572 if Gear^.Timer > Steps then dec(Gear^.Timer, Steps) else Gear^.Timer:= 0;
   591 if Gear^.Timer > Steps then dec(Gear^.Timer, Steps) else Gear^.Timer:= 0;
   573 
   592 
   574 if (Gear^.Hedgehog^.Gear <> nil) then
   593 if (Gear^.Hedgehog^.Gear <> nil) then
   575     begin
   594     begin
   576     Gear^.X:= hwFloat2Float(Gear^.Hedgehog^.Gear^.X) + (Gear^.Tex^.w div 2  - Gear^.FrameTicks);
   595     Gear^.X:= hwFloat2Float(Gear^.Hedgehog^.Gear^.X) + (Gear^.Tex^.w div 2  - Gear^.Tag);
   577     Gear^.Y:= hwFloat2Float(Gear^.Hedgehog^.Gear^.Y) - (16 + Gear^.Tex^.h);
   596     Gear^.Y:= hwFloat2Float(Gear^.Hedgehog^.Gear^.Y) - (16 + Gear^.Tex^.h);
   578     end;
   597     end;
   579 
   598 
   580 if Gear^.Timer = 0 then
   599 if Gear^.Timer = 0 then
   581     begin
   600     begin
   600 
   619 
   601 Gear^.Timer:= max(LongInt(Length(Gear^.Text)) * 150, 3000);
   620 Gear^.Timer:= max(LongInt(Length(Gear^.Text)) * 150, 3000);
   602 
   621 
   603 Gear^.Tex:= RenderSpeechBubbleTex(Gear^.Text, Gear^.FrameTicks, fnt16);
   622 Gear^.Tex:= RenderSpeechBubbleTex(Gear^.Text, Gear^.FrameTicks, fnt16);
   604 
   623 
       
   624 // FrameTicks cannot hold negative values
   605 case Gear^.FrameTicks of
   625 case Gear^.FrameTicks of
   606     1: Gear^.FrameTicks:= SpritesData[sprSpeechTail].Width-28;
   626     1: Gear^.Tag:= SpritesData[sprSpeechTail].Width-28;
   607     2: Gear^.FrameTicks:= SpritesData[sprThoughtTail].Width-20;
   627     2: Gear^.Tag:= SpritesData[sprThoughtTail].Width-20;
   608     3: Gear^.FrameTicks:= SpritesData[sprShoutTail].Width-10;
   628     3: Gear^.Tag:= SpritesData[sprShoutTail].Width-10;
   609     end;
   629     end;
   610 
   630 
   611 Gear^.doStep:= @doStepSpeechBubbleWork;
   631 Gear^.doStep:= @doStepSpeechBubbleWork;
   612 
   632 
   613 Gear^.Y:= Gear^.Y - Gear^.Tex^.h
   633 Gear^.Y:= Gear^.Y - Gear^.Tex^.h