hedgewars/uWorld.pas
branchqmlfrontend
changeset 12855 1b2b84315d27
parent 12831 1fbc0d5a82d0
child 12890 9c259fb4d405
child 13018 0248cf0da834
child 13224 01ab48b253ef
equal deleted inserted replaced
11843:01f88c3b7b66 12855:1b2b84315d27
    30 
    30 
    31 procedure DrawWorld(Lag: LongInt);
    31 procedure DrawWorld(Lag: LongInt);
    32 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
    32 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
    33 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
    33 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
    34 procedure HideMission;
    34 procedure HideMission;
       
    35 procedure SetAmmoTexts(ammoType: TAmmoType; name: ansistring; caption: ansistring; description: ansistring);
    35 procedure ShakeCamera(amount: LongInt);
    36 procedure ShakeCamera(amount: LongInt);
    36 procedure InitCameraBorders;
    37 procedure InitCameraBorders;
    37 procedure InitTouchInterface;
    38 procedure InitTouchInterface;
    38 procedure SetUtilityWidgetState(ammoType: TAmmoType);
    39 procedure SetUtilityWidgetState(ammoType: TAmmoType);
    39 procedure animateWidget(widget: POnScreenWidget; fade, showWidget: boolean);
    40 procedure animateWidget(widget: POnScreenWidget; fade, showWidget: boolean);
    58     , uRender
    59     , uRender
    59     , uCaptions
    60     , uCaptions
    60     , uCursor
    61     , uCursor
    61     , uCommands
    62     , uCommands
    62     , uTeams
    63     , uTeams
       
    64     , uDebug
    63 {$IFDEF USE_VIDEO_RECORDING}
    65 {$IFDEF USE_VIDEO_RECORDING}
    64     , uVideoRec
    66     , uVideoRec
    65 {$ENDIF}
    67 {$ENDIF}
    66     ;
    68     ;
    67 
    69 
   167 
   169 
   168 // if special game flags/settings are changed, add them to the game mode notice window and then show it
   170 // if special game flags/settings are changed, add them to the game mode notice window and then show it
   169 g:= ''; // no text/things to note yet
   171 g:= ''; // no text/things to note yet
   170 
   172 
   171 // add custom goals from lua script if there are any
   173 // add custom goals from lua script if there are any
   172 if LuaGoals <> '' then
   174 if LuaGoals <> ansistring('') then
   173     g:= LuaGoals + '|';
   175     g:= LuaGoals + '|';
   174 
   176 
   175 // check different game flags (goals/game modes first for now)
   177 // check different game flags
       
   178 g:= AddGoal(g, gfPlaceHog, gidPlaceHog); // placement?
   176 g:= AddGoal(g, gfKing, gidKing); // king?
   179 g:= AddGoal(g, gfKing, gidKing); // king?
       
   180 if ((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0) then
       
   181     g:= AddGoal(g, gfAny, gidPlaceKing);
   177 g:= AddGoal(g, gfTagTeam, gidTagTeam); // tag team mode?
   182 g:= AddGoal(g, gfTagTeam, gidTagTeam); // tag team mode?
   178 
   183 g:= AddGoal(g, gfSharedAmmo, gidSharedAmmo); // shared ammo?
   179 // other important flags
   184 g:= AddGoal(g, gfPerHogAmmo, gidPerHogAmmo);
   180 g:= AddGoal(g, gfForts, gidForts); // forts?
   185 g:= AddGoal(g, gfMoreWind, gidMoreWind);
   181 g:= AddGoal(g, gfLowGravity, gidLowGravity); // low gravity?
   186 g:= AddGoal(g, gfLowGravity, gidLowGravity); // low gravity?
   182 g:= AddGoal(g, gfInvulnerable, gidInvulnerable); // invulnerability?
   187 g:= AddGoal(g, gfSolidLand, gidSolidLand); // solid land?
   183 g:= AddGoal(g, gfVampiric, gidVampiric); // vampirism?
       
   184 g:= AddGoal(g, gfKarma, gidKarma); // karma?
       
   185 g:= AddGoal(g, gfPlaceHog, gidPlaceHog); // placement?
       
   186 g:= AddGoal(g, gfArtillery, gidArtillery); // artillery?
   188 g:= AddGoal(g, gfArtillery, gidArtillery); // artillery?
   187 g:= AddGoal(g, gfSolidLand, gidSolidLand); // solid land?
       
   188 g:= AddGoal(g, gfSharedAmmo, gidSharedAmmo); // shared ammo?
       
   189 g:= AddGoal(g, gfResetHealth, gidResetHealth);
       
   190 g:= AddGoal(g, gfAISurvival, gidAISurvival);
       
   191 g:= AddGoal(g, gfInfAttack, gidInfAttack);
   189 g:= AddGoal(g, gfInfAttack, gidInfAttack);
   192 g:= AddGoal(g, gfResetWeps, gidResetWeps);
   190 g:= AddGoal(g, gfResetWeps, gidResetWeps);
   193 g:= AddGoal(g, gfPerHogAmmo, gidPerHogAmmo);
   191 g:= AddGoal(g, gfResetHealth, gidResetHealth);
       
   192 g:= AddGoal(g, gfKarma, gidKarma); // karma?
       
   193 g:= AddGoal(g, gfVampiric, gidVampiric); // vampirism?
       
   194 g:= AddGoal(g, gfInvulnerable, gidInvulnerable); // invulnerability?
       
   195 g:= AddGoal(g, gfAISurvival, gidAISurvival);
   194 
   196 
   195 // modified damage modificator?
   197 // modified damage modificator?
   196 if cDamagePercent <> 100 then
   198 if cDamagePercent <> 100 then
   197     g:= AddGoal(g, gfAny, gidDamageModifier, cDamagePercent);
   199     g:= AddGoal(g, gfAny, gidDamageModifier, cDamagePercent);
   198 
   200 
   420 begin
   422 begin
   421     if cOnlyStats then exit(nil);
   423     if cOnlyStats then exit(nil);
   422 
   424 
   423     SlotsNum:= 0;
   425     SlotsNum:= 0;
   424     for i:= 0 to cMaxSlotIndex do
   426     for i:= 0 to cMaxSlotIndex do
   425         if((i = 0) and (Ammo^[i,1].Count > 0)) or ((i <> 0) and (Ammo^[i,0].Count > 0)) then
   427         if (i <> cHiddenSlotIndex) and (Ammo^[i, 0].Count > 0) then
   426             inc(SlotsNum);
   428             inc(SlotsNum);
   427 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   429 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   428     SlotsNumX:= SlotsNum;
   430     SlotsNumX:= SlotsNum;
   429     SlotsNumY:= cMaxSlotAmmoIndex + 2;
   431     SlotsNumY:= cMaxSlotAmmoIndex + 2;
   430     {$IFDEF USE_AM_NUMCOLUMN}
   432     {$IFDEF USE_AM_NUMCOLUMN}
   451     SDL_FillRect(amSurface, @AMRect, SDL_MapRGB(amSurface^.format, 0,0,0));
   453     SDL_FillRect(amSurface, @AMRect, SDL_MapRGB(amSurface^.format, 0,0,0));
   452 
   454 
   453     x:= AMRect.x;
   455     x:= AMRect.x;
   454     y:= AMRect.y;
   456     y:= AMRect.y;
   455     for i:= 0 to cMaxSlotIndex do
   457     for i:= 0 to cMaxSlotIndex do
   456         if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
   458         if (i <> cHiddenSlotIndex) and (Ammo^[i, 0].Count > 0) then
   457             begin
   459             begin
   458 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   460 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   459             y:= AMRect.y;
   461             y:= AMRect.y;
   460 {$ELSE}
   462 {$ELSE}
   461             x:= AMRect.x;
   463             x:= AMRect.x;
   658 Pos:= -1;
   660 Pos:= -1;
   659 Slot:= -1;
   661 Slot:= -1;
   660 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   662 {$IFDEF USE_LANDSCAPE_AMMOMENU}
   661 c:= -1;
   663 c:= -1;
   662     for i:= 0 to cMaxSlotIndex do
   664     for i:= 0 to cMaxSlotIndex do
   663         if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
   665         if (i <> cHiddenSlotIndex) and (Ammo^[i, 0].Count > 0) then
   664             begin
   666             begin
   665             inc(c);
   667             inc(c);
   666     {$IFDEF USE_AM_NUMCOLUMN}
   668     {$IFDEF USE_AM_NUMCOLUMN}
   667             g:= 1;
   669             g:= 1;
   668     {$ELSE}
   670     {$ELSE}
   688                    end;
   690                    end;
   689             end;
   691             end;
   690 {$ELSE}
   692 {$ELSE}
   691 c:= -1;
   693 c:= -1;
   692     for i:= 0 to cMaxSlotIndex do
   694     for i:= 0 to cMaxSlotIndex do
   693         if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
   695         if (i <> cHiddenSlotIndex) and (Ammo^[i, 0].Count > 0) then
   694             begin
   696             begin
   695             inc(c);
   697             inc(c);
   696     {$IFDEF USE_AM_NUMCOLUMN}
   698     {$IFDEF USE_AM_NUMCOLUMN}
   697             g:= 1;
   699             g:= 1;
   698     {$ELSE}
   700     {$ELSE}
   716                         end;
   718                         end;
   717                         inc(g);
   719                         inc(g);
   718                    end;
   720                    end;
   719             end;
   721             end;
   720 {$ENDIF}
   722 {$ENDIF}
   721     if (Pos >= 0) and (Pos <= cMaxSlotAmmoIndex) and (Slot >= 0) and (Slot <= cMaxSlotIndex)then
   723     if (Pos >= 0) and (Pos <= cMaxSlotAmmoIndex) and (Slot >= 0) and (Slot <= cMaxSlotIndex) and (Slot <> cHiddenSlotIndex) then
   722         begin
   724         begin
   723         if (AMShiftX = 0) and (AMShiftY = 0) then
   725         if (AMShiftX = 0) and (AMShiftY = 0) then
   724         if (Ammo^[Slot, Pos].Count > 0) and (Ammo^[Slot, Pos].AmmoType <> amNothing) then
   726         if (Ammo^[Slot, Pos].Count > 0) and (Ammo^[Slot, Pos].AmmoType <> amNothing) then
   725             begin
   727             begin
   726             if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
   728             if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
  1023     end;
  1025     end;
  1024 end;
  1026 end;
  1025 
  1027 
  1026 
  1028 
  1027 procedure RenderTeamsHealth;
  1029 procedure RenderTeamsHealth;
  1028 var t, i, h, smallScreenOffset, TeamHealthBarWidth : LongInt;
  1030 var t, i,  h, smallScreenOffset, TeamHealthBarWidth : LongInt;
  1029     r: TSDL_Rect;
  1031     r: TSDL_Rect;
  1030     highlight: boolean;
  1032     highlight: boolean;
  1031     htex: PTexture;
  1033     htex: PTexture;
  1032 begin
  1034 begin
  1033 if TeamsCount * 20 > Longword(cScreenHeight) div 7 then  // take up less screen on small displays
  1035 if TeamsCount * 20 > Longword(cScreenHeight) div 7 then  // take up less screen on small displays
  1157     WorldDx:= preShiftWorldDx;
  1159     WorldDx:= preShiftWorldDx;
  1158 end;
  1160 end;
  1159 
  1161 
  1160 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
  1162 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
  1161 var i, t: LongInt;
  1163 var i, t: LongInt;
       
  1164     spr: TSprite;
  1162     r: TSDL_Rect;
  1165     r: TSDL_Rect;
  1163     tdx, tdy: Double;
  1166     tdx, tdy: Double;
  1164     s: shortstring;
  1167     s: shortstring;
  1165     offsetX, offsetY, screenBottom: LongInt;
  1168     offsetX, offsetY, screenBottom: LongInt;
  1166     replicateToLeft, replicateToRight, tmp: boolean;
  1169     replicateToLeft, replicateToRight, tmp: boolean;
       
  1170 {$IFDEF USE_VIDEO_RECORDING}
  1167     a: Byte;
  1171     a: Byte;
       
  1172 {$ENDIF}
  1168 begin
  1173 begin
  1169 if WorldEdge <> weWrap then
  1174 if WorldEdge <> weWrap then
  1170     begin
  1175     begin
  1171     replicateToLeft := false;
  1176     replicateToLeft := false;
  1172     replicateToRight:= false;
  1177     replicateToRight:= false;
  1191             HorizontOffset:= HorizontOffset + ((ScreenBottom-SkyOffset) div 20);
  1196             HorizontOffset:= HorizontOffset + ((ScreenBottom-SkyOffset) div 20);
  1192 
  1197 
  1193         // background
  1198         // background
  1194         ChangeDepth(RM, cStereo_Sky);
  1199         ChangeDepth(RM, cStereo_Sky);
  1195         if SuddenDeathDmg then
  1200         if SuddenDeathDmg then
  1196             Tint(SDTint, SDTint, SDTint, $FF);
  1201             Tint(SDTint.r, SDTint.g, SDTint.b, SDTint.a);
  1197         DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8, SkyOffset);
  1202         DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8, SkyOffset);
  1198         ChangeDepth(RM, -cStereo_Horizon);
  1203         ChangeDepth(RM, -cStereo_Horizon);
  1199         DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5, HorizontOffset);
  1204         DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5, HorizontOffset);
  1200         if SuddenDeathDmg then
  1205         if SuddenDeathDmg then
  1201             untint;
  1206             untint;
  1321         DrawWaves( -1, 25 + WorldDx div 3, - offsetY div 10, 59, 0);
  1326         DrawWaves( -1, 25 + WorldDx div 3, - offsetY div 10, 59, 0);
  1322         end
  1327         end
  1323     else
  1328     else
  1324         DrawWaves(-1, 50, cWaveHeight div 2, cWaveHeight div 2, 0);
  1329         DrawWaves(-1, 50, cWaveHeight div 2, cWaveHeight div 2, 0);
  1325 
  1330 
       
  1331 DrawGearsTimers;
       
  1332 
  1326 // everything after this ChangeDepth will be drawn outside the screen
  1333 // everything after this ChangeDepth will be drawn outside the screen
  1327 // note: negative parallax gears should last very little for a smooth stereo effect
  1334 // note: negative parallax gears should last very little for a smooth stereo effect
  1328     ChangeDepth(RM, cStereo_Outside);
  1335     ChangeDepth(RM, cStereo_Outside);
  1329 
  1336 
  1330     if replicateToLeft then
  1337     if replicateToLeft then
  1422     offsetX:= cScreenHeight - 13;
  1429     offsetX:= cScreenHeight - 13;
  1423 {$ELSE}
  1430 {$ELSE}
  1424     offsetX:= 48;
  1431     offsetX:= 48;
  1425 {$ENDIF}
  1432 {$ENDIF}
  1426     offsetY:= cOffsetY;
  1433     offsetY:= cOffsetY;
  1427     if ((TurnTimeLeft <> 0) and (TurnTimeLeft < 1000000)) or (ReadyTimeLeft <> 0) then
  1434     if ((TurnTimeLeft <> 0) and (TurnTimeLeft < 999000)) or (ReadyTimeLeft <> 0) then
  1428         begin
  1435         begin
  1429         if ReadyTimeLeft <> 0 then
  1436         if ReadyTimeLeft <> 0 then
  1430             i:= Succ(Pred(ReadyTimeLeft) div 1000)
  1437             i:= Succ(Pred(ReadyTimeLeft) div 1000)
  1431         else
  1438         else
  1432             i:= Succ(Pred(TurnTimeLeft) div 1000);
  1439             i:= Succ(Pred(TurnTimeLeft) div 1000);
  1439             t:= 80;
  1446             t:= 80;
  1440         DrawSprite(sprFrame, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, 1);
  1447         DrawSprite(sprFrame, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, 1);
  1441         while i > 0 do
  1448         while i > 0 do
  1442             begin
  1449             begin
  1443             dec(t, 32);
  1450             dec(t, 32);
  1444             DrawSprite(sprBigDigit, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, i mod 10);
  1451             if isPaused or (not IsClockRunning()) then
       
  1452                 spr := sprBigDigitGray
       
  1453             else if (ReadyTimeLeft <> 0) then
       
  1454                 spr := sprBigDigitGreen
       
  1455             else if IsGetAwayTime then
       
  1456                 spr := sprBigDigitRed
       
  1457             else
       
  1458                 spr := sprBigDigit;
       
  1459             DrawSprite(spr, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, i mod 10);
  1445             i:= i div 10
  1460             i:= i div 10
  1446             end;
  1461             end;
  1447         DrawSprite(sprFrame, -(cScreenWidth shr 1) + t - 4 + offsetY, cScreenHeight - offsetX, 0);
  1462         DrawSprite(sprFrame, -(cScreenWidth shr 1) + t - 4 + offsetY, cScreenHeight - offsetX, 0);
  1448         end;
  1463         end;
  1449 
  1464 
  1503         r.w:= - WindBarWidth;
  1518         r.w:= - WindBarWidth;
  1504         r.h:= 13;
  1519         r.h:= 13;
  1505         DrawSpriteFromRect(sprWindL, r, (cScreenWidth shr 1) - offsetY + 74 + WindBarWidth, cScreenHeight - offsetX + 2, 13, 0);
  1520         DrawSpriteFromRect(sprWindL, r, (cScreenWidth shr 1) - offsetY + 74 + WindBarWidth, cScreenHeight - offsetX + 2, 13, 0);
  1506         end
  1521         end
  1507     end;
  1522     end;
       
  1523 
       
  1524 {$IFNDEF USE_TOUCH_INTERFACE}
       
  1525 // Indicators for global effects (extra damage, low gravity)
       
  1526 // TODO: Add support for touch interface (need to find out correct offset)
       
  1527 if UIDisplay <> uiNone then
       
  1528     begin
       
  1529     offsetX:= 45;
       
  1530     offsetY:= 51;
       
  1531 
       
  1532     if cDamageModifier = _1_5 then
       
  1533         begin
       
  1534             DrawTextureF(ropeIconTex, 1, (cScreenWidth shr 1) - offsetX, cScreenHeight - offsetY, 0, 1, 32, 32);
       
  1535             DrawTextureF(SpritesData[sprAMAmmos].Texture, 0.90, (cScreenWidth shr 1) - offsetX, cScreenHeight - offsetY, ord(amExtraDamage) - 1, 1, 32, 32);
       
  1536             offsetX := offsetX + 33
       
  1537         end;
       
  1538     if (cLowGravity) or ((GameFlags and gfLowGravity) <> 0) then
       
  1539         begin
       
  1540             DrawTextureF(ropeIconTex, 1, (cScreenWidth shr 1) - offsetX, cScreenHeight - offsetY, 0, 1, 32, 32);
       
  1541             DrawTextureF(SpritesData[sprAMAmmos].Texture, 0.90, (cScreenWidth shr 1) - offsetX, cScreenHeight - offsetY, ord(amLowGravity) - 1, 1, 32, 32);
       
  1542         end;
       
  1543     end;
       
  1544 {$ENDIF}
  1508 
  1545 
  1509 // AmmoMenu
  1546 // AmmoMenu
  1510 if bShowAmmoMenu and ((AMState = AMHidden) or (AMState = AMHiding)) then
  1547 if bShowAmmoMenu and ((AMState = AMHidden) or (AMState = AMHiding)) then
  1511     begin
  1548     begin
  1512     if (AMState = AMHidden) then
  1549     if (AMState = AMHidden) then
  1915 procedure HideMission;
  1952 procedure HideMission;
  1916 begin
  1953 begin
  1917     missionTimer:= 0;
  1954     missionTimer:= 0;
  1918 end;
  1955 end;
  1919 
  1956 
       
  1957 procedure SetAmmoTexts(ammoType: TAmmoType; name: ansistring; caption: ansistring; description: ansistring);
       
  1958 var
       
  1959     ammoStrId: TAmmoStrId;
       
  1960     ammoStr: ansistring;
       
  1961     tmpsurf: PSDL_Surface;
       
  1962 begin
       
  1963     ammoStrId := Ammoz[ammoType].NameId;
       
  1964 
       
  1965     trluaammo[ammoStrId] := name;
       
  1966     if length(trluaammo[ammoStrId]) > 0 then
       
  1967         ammoStr:= trluaammo[ammoStrId]
       
  1968     else
       
  1969         ammoStr:= trammo[ammoStrId];
       
  1970 
       
  1971     if checkFails(length(ammoStr) > 0,'No default text/translation found for ammo type #' + intToStr(ord(ammoType)) + '!',true) then exit;
       
  1972         
       
  1973     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(ammoStr,fnt16)].Handle, PChar(ammoStr), cWhiteColorChannels);
       
  1974     if checkFails(tmpsurf <> nil,'Name-texture creation for ammo type #' + intToStr(ord(ammoType)) + ' failed!',true) then exit;
       
  1975     tmpsurf:= doSurfaceConversion(tmpsurf);
       
  1976     FreeAndNilTexture(Ammoz[ammoType].NameTex);
       
  1977     Ammoz[ammoType].NameTex:= Surface2Tex(tmpsurf, false);
       
  1978     SDL_FreeSurface(tmpsurf);
       
  1979 
       
  1980     trluaammoc[ammoStrId] := caption;
       
  1981     trluaammod[ammoStrId] := description;
       
  1982 end;
       
  1983 
  1920 procedure ShakeCamera(amount: LongInt);
  1984 procedure ShakeCamera(amount: LongInt);
  1921 begin
  1985 begin
  1922 if isCursorVisible then
  1986 if isCursorVisible then
  1923     exit;
  1987     exit;
  1924 amount:= Max(1, round(amount*zoom/2));
  1988 amount:= Max(1, round(amount*zoom/2));