hedgewars/uWorld.pas
branchphysfslayer
changeset 7928 88fde28bbda6
parent 7858 2566fc2621d4
child 7946 a99a79bbd857
equal deleted inserted replaced
7778:3331b30e4ef1 7928:88fde28bbda6
   627     Tint($FF, $ff, $ff, $ff);
   627     Tint($FF, $ff, $ff, $ff);
   628 
   628 
   629 Pos:= -1;
   629 Pos:= -1;
   630 Slot:= -1;
   630 Slot:= -1;
   631 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   631 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   632     {$IFDEF USE_AM_NUMCOLUMN}
       
   633 c:= 0;
       
   634     {$ELSE}
       
   635 c:= -1;
   632 c:= -1;
   636     {$ENDIF}
       
   637     for i:= 0 to cMaxSlotIndex do
   633     for i:= 0 to cMaxSlotIndex do
   638         if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
   634         if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
   639             begin
   635             begin
   640             inc(c);
   636             inc(c);
   641     {$IFDEF USE_AM_NUMCOLUMN}
   637     {$IFDEF USE_AM_NUMCOLUMN}
   645     {$ENDIF}
   641     {$ENDIF}
   646             for t:=0 to cMaxSlotAmmoIndex do
   642             for t:=0 to cMaxSlotAmmoIndex do
   647                 if (Ammo^[i, t].Count > 0) and (Ammo^[i, t].AmmoType <> amNothing) then
   643                 if (Ammo^[i, t].Count > 0) and (Ammo^[i, t].AmmoType <> amNothing) then
   648                     begin
   644                     begin
   649                     if (CursorPoint.Y <= (cScreenHeight - AmmoRect.y) - ( g    * (AMSlotSize+1))) and
   645                     if (CursorPoint.Y <= (cScreenHeight - AmmoRect.y) - ( g    * (AMSlotSize+1))) and
   650                        (CursorPoint.Y >= (cScreenHeight - AmmoRect.y) - ((g+1) * (AMSlotSize+1))) and
   646                        (CursorPoint.Y >  (cScreenHeight - AmmoRect.y) - ((g+1) * (AMSlotSize+1))) and
   651                        (CursorPoint.X >= AmmoRect.x                   + ( c    * (AMSlotSize+1))) and 
   647                        (CursorPoint.X >  AmmoRect.x                   + ( c    * (AMSlotSize+1))) and 
   652                        (CursorPoint.X <= AmmoRect.x                   + ((c+1) * (AMSlotSize+1))) then
   648                        (CursorPoint.X <= AmmoRect.x                   + ((c+1) * (AMSlotSize+1))) then
   653                         begin
   649                         begin
   654                         Slot:= i;
   650                         Slot:= i;
   655                         Pos:= t;
   651                         Pos:= t;
   656                         STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
   652                         STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
   661                         end;
   657                         end;
   662                         inc(g);
   658                         inc(g);
   663                    end;
   659                    end;
   664             end;
   660             end;
   665 {$ELSE}
   661 {$ELSE}
   666     {$IFDEF USE_AM_NUMCOLUMN}
       
   667 c:= -1;
   662 c:= -1;
   668     {$ELSE}
       
   669 c:= 0;
       
   670     {$ENDIF}
       
   671     for i:= 0 to cMaxSlotIndex do
   663     for i:= 0 to cMaxSlotIndex do
   672         if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
   664         if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
   673             begin
   665             begin
   674             inc(c);
   666             inc(c);
   675     {$IFDEF USE_AM_NUMCOLUMN}
   667     {$IFDEF USE_AM_NUMCOLUMN}
   679     {$ENDIF}
   671     {$ENDIF}
   680             for t:=0 to cMaxSlotAmmoIndex do
   672             for t:=0 to cMaxSlotAmmoIndex do
   681                 if (Ammo^[i, t].Count > 0) and (Ammo^[i, t].AmmoType <> amNothing) then
   673                 if (Ammo^[i, t].Count > 0) and (Ammo^[i, t].AmmoType <> amNothing) then
   682                     begin
   674                     begin
   683                     if (CursorPoint.Y <= (cScreenHeight - AmmoRect.y) - ( c    * (AMSlotSize+1))) and
   675                     if (CursorPoint.Y <= (cScreenHeight - AmmoRect.y) - ( c    * (AMSlotSize+1))) and
   684                        (CursorPoint.Y >= (cScreenHeight - AmmoRect.y) - ((c+1) * (AMSlotSize+1))) and
   676                        (CursorPoint.Y >  (cScreenHeight - AmmoRect.y) - ((c+1) * (AMSlotSize+1))) and
   685                        (CursorPoint.X >= AmmoRect.x                   + ( g    * (AMSlotSize+1))) and 
   677                        (CursorPoint.X >  AmmoRect.x                   + ( g    * (AMSlotSize+1))) and 
   686                        (CursorPoint.X <= AmmoRect.x                   + ((g+1) * (AMSlotSize+1))) then
   678                        (CursorPoint.X <= AmmoRect.x                   + ((g+1) * (AMSlotSize+1))) then
   687                         begin
   679                         begin
   688                         Slot:= i;
   680                         Slot:= i;
   689                         Pos:= t;
   681                         Pos:= t;
   690                         STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
   682                         STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
  1165     changeDepth(RM, cStereo_Land);
  1157     changeDepth(RM, cStereo_Land);
  1166     DrawVisualGears(5);
  1158     DrawVisualGears(5);
  1167     DrawLand(WorldDx, WorldDy);
  1159     DrawLand(WorldDx, WorldDy);
  1168 
  1160 
  1169     DrawWater(255, 0);
  1161     DrawWater(255, 0);
  1170 
       
  1171 // Attack bar
       
  1172     if CurrentTeam <> nil then
       
  1173         case AttackBar of
       
  1174 (*        1: begin
       
  1175         r:= StuffPoz[sPowerBar];
       
  1176         {$WARNINGS OFF}
       
  1177         r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor;
       
  1178         {$WARNINGS ON}
       
  1179         DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface);
       
  1180         end;*)
       
  1181         2: with CurrentHedgehog^ do
       
  1182                 begin
       
  1183                 tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle);
       
  1184                 tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle);
       
  1185                 for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do
       
  1186                     DrawSprite(sprPower,
       
  1187                             hwRound(Gear^.X) + GetLaunchX(CurAmmoType, hwSign(Gear^.dX), Gear^.Angle) + LongInt(round(WorldDx + tdx * (24 + i * 2))) - 16,
       
  1188                             hwRound(Gear^.Y) + GetLaunchY(CurAmmoType, Gear^.Angle) + LongInt(round(WorldDy + tdy * (24 + i * 2))) - 16,
       
  1189                             i)
       
  1190                 end
       
  1191         end;
       
  1192 
  1162 
  1193 DrawVisualGears(1);
  1163 DrawVisualGears(1);
  1194 DrawGears;
  1164 DrawGears;
  1195 DrawVisualGears(6);
  1165 DrawVisualGears(6);
  1196 
  1166 
  1614     end;
  1584     end;
  1615 {$ENDIF}
  1585 {$ENDIF}
  1616 
  1586 
  1617 SetScale(zoom);
  1587 SetScale(zoom);
  1618 
  1588 
       
  1589 // Attack bar
       
  1590     if CurrentTeam <> nil then
       
  1591         case AttackBar of
       
  1592 (*        1: begin
       
  1593         r:= StuffPoz[sPowerBar];
       
  1594         {$WARNINGS OFF}
       
  1595         r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor;
       
  1596         {$WARNINGS ON}
       
  1597         DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface);
       
  1598         end;*)
       
  1599         2: with CurrentHedgehog^ do
       
  1600                 begin
       
  1601                 tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle);
       
  1602                 tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle);
       
  1603                 for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do
       
  1604                     DrawSprite(sprPower,
       
  1605                             hwRound(Gear^.X) + GetLaunchX(CurAmmoType, hwSign(Gear^.dX), Gear^.Angle) + LongInt(round(WorldDx + tdx * (24 + i * 2))) - 16,
       
  1606                             hwRound(Gear^.Y) + GetLaunchY(CurAmmoType, Gear^.Angle) + LongInt(round(WorldDy + tdy * (24 + i * 2))) - 16,
       
  1607                             i)
       
  1608                 end
       
  1609         end;
       
  1610 
       
  1611 
  1619 // Cursor
  1612 // Cursor
  1620 if isCursorVisible then
  1613 if isCursorVisible then
  1621     begin
  1614     begin
  1622     if not bShowAmmoMenu then
  1615     if not bShowAmmoMenu then
  1623         begin
  1616         begin
  1638 end;
  1631 end;
  1639 
  1632 
  1640 var PrevSentPointTime: LongWord = 0;
  1633 var PrevSentPointTime: LongWord = 0;
  1641 
  1634 
  1642 procedure MoveCamera;
  1635 procedure MoveCamera;
  1643 var EdgesDist, wdy, shs,z: LongInt;
  1636 var EdgesDist, wdy, shs,z, amNumOffsetX, amNumOffsetY: LongInt;
  1644 begin
  1637 begin
  1645 {$IFNDEF MOBILE}
  1638 {$IFNDEF MOBILE}
  1646 if (not (CurrentTeam^.ExtDriven and isCursorVisible and (not bShowAmmoMenu))) and cHasFocus and (GameState <> gsConfirm) then
  1639 if (not (CurrentTeam^.ExtDriven and isCursorVisible and (not bShowAmmoMenu))) and cHasFocus and (GameState <> gsConfirm) then
  1647     uCursor.updatePosition();
  1640     uCursor.updatePosition();
  1648 {$ENDIF}
  1641 {$ENDIF}
  1670 if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then
  1663 if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then
  1671     exit;
  1664     exit;
  1672 
  1665 
  1673 if (AMState = AMShowingUp) or (AMState = AMShowing) then
  1666 if (AMState = AMShowingUp) or (AMState = AMShowing) then
  1674 begin
  1667 begin
  1675     if CursorPoint.X < AmmoRect.x then//check left 
  1668 {$IFDEF USE_LANDSCAPE_AMMOMENU}
  1676         CursorPoint.X:= AmmoRect.x;
  1669     amNumOffsetX:= 0;
  1677     if CursorPoint.X > AmmoRect.x + AmmoRect.w then//check right
  1670     {$IFDEF USE_AM_NUMCOLUMN}
  1678         CursorPoint.X:= AmmoRect.x + AmmoRect.w;
  1671     amNumOffsetY:= AMSlotSize;
  1679     if CursorPoint.Y > cScreenHeight - AmmoRect.y then//check top
  1672     {$ELSE}
  1680         CursorPoint.Y:= cScreenHeight - AmmoRect.y;
  1673     amNumOffsetY:= 0;
  1681     if CursorPoint.Y < cScreenHeight - (AmmoRect.y + AmmoRect.h - AMSlotSize - 2) then//check bottom
  1674     {$ENDIF}
  1682         CursorPoint.Y:= cScreenHeight - (AmmoRect.y + AmmoRect.h - AMSlotSize - 2);
  1675 {$ELSE}
       
  1676     amNumOffsetY:= 0;
       
  1677     {$IFDEF USE_AM_NUMCOLUMN}
       
  1678     amNumOffsetX:= AMSlotSize;
       
  1679     {$ELSE}
       
  1680     amNumOffsetX:= 0;
       
  1681     {$ENDIF}
       
  1682 
       
  1683 {$ENDIF}
       
  1684     if CursorPoint.X < AmmoRect.x + amNumOffsetX + 3 then//check left 
       
  1685         CursorPoint.X:= AmmoRect.x + amNumOffsetX + 3;
       
  1686     if CursorPoint.X > AmmoRect.x + AmmoRect.w - 3 then//check right
       
  1687         CursorPoint.X:= AmmoRect.x + AmmoRect.w - 3;
       
  1688     if CursorPoint.Y > cScreenHeight - AmmoRect.y -amNumOffsetY - 1 then//check top
       
  1689         CursorPoint.Y:= cScreenHeight - AmmoRect.y - amNumOffsetY - 1;
       
  1690     if CursorPoint.Y < cScreenHeight - (AmmoRect.y + AmmoRect.h - AMSlotSize - 5) then//check bottom
       
  1691         CursorPoint.Y:= cScreenHeight - (AmmoRect.y + AmmoRect.h - AMSlotSize - 5);
  1683     prevPoint:= CursorPoint;
  1692     prevPoint:= CursorPoint;
  1684     //if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
  1693     //if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
  1685     exit
  1694     exit
  1686 end;
  1695 end;
  1687 
  1696 
  1791 
  1800 
  1792 procedure onFocusStateChanged;
  1801 procedure onFocusStateChanged;
  1793 begin
  1802 begin
  1794 if (not cHasFocus) and (GameState <> gsConfirm) then
  1803 if (not cHasFocus) and (GameState <> gsConfirm) then
  1795     ParseCommand('quit', true);
  1804     ParseCommand('quit', true);
       
  1805 {$IFDEF MOBILE}
       
  1806 // when created SDL receives an exposure event that calls UndampenAudio at full power, muting audio
       
  1807 exit;
       
  1808 {$ENDIF}
  1796 
  1809 
  1797 {$IFDEF USE_VIDEO_RECORDING}
  1810 {$IFDEF USE_VIDEO_RECORDING}
  1798 // do not change volume during prerecording as it will affect sound in video file
  1811 // do not change volume during prerecording as it will affect sound in video file
  1799 if not flagPrerecording then
  1812 if not flagPrerecording then
  1800 {$ENDIF}
  1813 {$ENDIF}
  1878     missionTex:= nil;
  1891     missionTex:= nil;
  1879     cOffsetY:= 0;
  1892     cOffsetY:= 0;
  1880     stereoDepth:= 0;
  1893     stereoDepth:= 0;
  1881     AMState:= AMHidden;
  1894     AMState:= AMHidden;
  1882     isFirstFrame:= true;
  1895     isFirstFrame:= true;
       
  1896     stereoDepth:= stereoDepth; // avoid hint
  1883 end;
  1897 end;
  1884 
  1898 
  1885 procedure freeModule;
  1899 procedure freeModule;
  1886 begin
  1900 begin
  1887     stereoDepth:= stereoDepth; // avoid hint
  1901     ResetWorldTex();
  1888     FreeTexture(fpsTexture);
       
  1889     fpsTexture:= nil;
       
  1890     FreeTexture(timeTexture);
       
  1891     timeTexture:= nil;
       
  1892     FreeTexture(missionTex);
       
  1893     missionTex:= nil;
       
  1894     FreeTexture(recTexture);
       
  1895     recTexture:= nil;
       
  1896 end;
  1902 end;
  1897 
  1903 
  1898 end.
  1904 end.