hedgewars/uWorld.pas
changeset 2948 3f21a9dc93d0
parent 2931 97f75507e1cb
child 2958 e6f7620da87e
equal deleted inserted replaced
2947:803b277e4894 2948:3f21a9dc93d0
    44 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
    44 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
    45 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
    45 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
    46 procedure HideMission;
    46 procedure HideMission;
    47 
    47 
    48 implementation
    48 implementation
    49 uses	uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, uAmmos, uVisualGears, uChat, uLandTexture, uLand,
    49 uses    uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, uAmmos, uVisualGears, uChat, uLandTexture, uLand,
    50 {$IFDEF GLES11}
    50 {$IFDEF GLES11}
    51 	gles11;
    51     gles11;
    52 {$ELSE}
    52 {$ELSE}
    53 	GL;
    53     GL;
    54 {$ENDIF}
    54 {$ENDIF}
    55 
    55 
    56 type TCaptionStr = record
    56 type TCaptionStr = record
    57                    Tex: PTexture;
    57                    Tex: PTexture;
    58                    EndTime: LongWord;
    58                    EndTime: LongWord;
    66     timeTexture: PTexture;
    66     timeTexture: PTexture;
    67     FPS: Longword;
    67     FPS: Longword;
    68     CountTicks: Longword;
    68     CountTicks: Longword;
    69     SoundTimerTicks: Longword;
    69     SoundTimerTicks: Longword;
    70     prevPoint: TPoint;
    70     prevPoint: TPoint;
    71 	amSel: TAmmoType = amNothing;
    71     amSel: TAmmoType = amNothing;
    72 	missionTex: PTexture;
    72     missionTex: PTexture;
    73 	missionTimer: LongInt;
    73     missionTimer: LongInt;
    74 
    74 
    75 procedure InitWorld;
    75 procedure InitWorld;
    76 var i, t: LongInt;
    76 var i, t: LongInt;
    77     cp: PClan;
    77     cp: PClan;
    78     g: ansistring;
    78     g: ansistring;
   120 // if special game flags/settings are changed, add them to the game mode notice window and then show it
   120 // if special game flags/settings are changed, add them to the game mode notice window and then show it
   121 g:= ''; // no text/things to note yet
   121 g:= ''; // no text/things to note yet
   122 
   122 
   123 // modified damage modificator?
   123 // modified damage modificator?
   124 if cDamagePercent <> 100 then
   124 if cDamagePercent <> 100 then
   125 	g:= AddGoal(g, gfAny, gidDamageModifier, cDamagePercent);
   125     g:= AddGoal(g, gfAny, gidDamageModifier, cDamagePercent);
   126 
   126 
   127 // modified mine timers?
   127 // modified mine timers?
   128 if cMinesTime <> 3000 then
   128 if cMinesTime <> 3000 then
   129 	begin
   129     begin
   130 	if cMinesTime = 0 then
   130     if cMinesTime = 0 then
   131 		g:= AddGoal(g, gfMines, gidNoMineTimer)
   131         g:= AddGoal(g, gfMines, gidNoMineTimer)
   132 	else if cMinesTime < 0 then
   132     else if cMinesTime < 0 then
   133 		g:= AddGoal(g, gfMines, gidRandomMineTimer)
   133         g:= AddGoal(g, gfMines, gidRandomMineTimer)
   134 	else
   134     else
   135 		g:= AddGoal(g, gfMines, gidMineTimer, cMinesTime div 1000);
   135         g:= AddGoal(g, gfMines, gidMineTimer, cMinesTime div 1000);
   136 	end;
   136     end;
   137 
   137 
   138 // check different game flags
   138 // check different game flags
   139 g:= AddGoal(g, gfForts, gidForts); // forts?
   139 g:= AddGoal(g, gfForts, gidForts); // forts?
   140 g:= AddGoal(g, gfLowGravity, gidLowGravity); // low gravity?
   140 g:= AddGoal(g, gfLowGravity, gidLowGravity); // low gravity?
   141 g:= AddGoal(g, gfInvulnerable, gidInvulnerable); // invulnerability?
   141 g:= AddGoal(g, gfInvulnerable, gidInvulnerable); // invulnerability?
   208 dec(y);
   208 dec(y);
   209 DrawSprite(sprAMBorders, x, y, 1);
   209 DrawSprite(sprAMBorders, x, y, 1);
   210 dec(y, 33);
   210 dec(y, 33);
   211 DrawSprite(sprAMSlotName, x, y, 0);
   211 DrawSprite(sprAMSlotName, x, y, 0);
   212 for i:= cMaxSlotIndex downto 0 do
   212 for i:= cMaxSlotIndex downto 0 do
   213 	if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
   213     if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
   214 		begin
   214         begin
   215 		if (cScreenHeight - CursorPoint.Y >= y - 33) and (cScreenHeight - CursorPoint.Y < y) then Slot:= i;
   215         if (cScreenHeight - CursorPoint.Y >= y - 33) and (cScreenHeight - CursorPoint.Y < y) then Slot:= i;
   216 		dec(y, 33);
   216         dec(y, 33);
   217 		inc(SlotsNum);
   217         inc(SlotsNum);
   218 		DrawSprite(sprAMSlot, x, y, 0);
   218         DrawSprite(sprAMSlot, x, y, 0);
   219 		DrawSprite(sprAMSlotKeys, x + 2, y + 1, i);
   219         DrawSprite(sprAMSlotKeys, x + 2, y + 1, i);
   220 		t:= 0;
   220         t:= 0;
   221                     g:= 0;
   221                     g:= 0;
   222 		while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do
   222         while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do
   223 			begin
   223             begin
   224 			if (Ammo^[i, t].AmmoType <> amNothing) then
   224             if (Ammo^[i, t].AmmoType <> amNothing) then
   225 				begin
   225                 begin
   226 				l:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
   226                 l:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
   227 
   227 
   228 				if l >= 0 then
   228                 if l >= 0 then
   229 					begin
   229                     begin
   230 					DrawSprite(sprAMAmmosBW, x + g * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
   230                     DrawSprite(sprAMAmmosBW, x + g * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
   231                     if l < 100 then DrawSprite(sprTurnsLeft, x + g * 33 + 51, y + 17, l);
   231                     if l < 100 then DrawSprite(sprTurnsLeft, x + g * 33 + 51, y + 17, l);
   232 					end else
   232                     end else
   233 					DrawSprite(sprAMAmmos, x + g * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
   233                     DrawSprite(sprAMAmmos, x + g * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
   234 				if (Slot = i)
   234                 if (Slot = i)
   235 				and (CursorPoint.X >= x + g * 33 + 35)
   235                 and (CursorPoint.X >= x + g * 33 + 35)
   236 				and (CursorPoint.X < x + g * 33 + 68) then
   236                 and (CursorPoint.X < x + g * 33 + 68) then
   237 					begin
   237                     begin
   238 					if (l < 0) then DrawSprite(sprAMSelection, x + g * 33 + 35, y + 1, 0);
   238                     if (l < 0) then DrawSprite(sprAMSelection, x + g * 33 + 35, y + 1, 0);
   239 					Pos:= t;
   239                     Pos:= t;
   240 					end;
   240                     end;
   241 				inc(g)
   241                 inc(g)
   242 				end;
   242                 end;
   243 				inc(t)
   243                 inc(t)
   244 			end
   244             end
   245 		end;
   245         end;
   246 dec(y, 1);
   246 dec(y, 1);
   247 DrawSprite(sprAMBorders, x, y, 0);
   247 DrawSprite(sprAMBorders, x, y, 0);
   248 
   248 
   249 if (Pos >= 0) then
   249 if (Pos >= 0) then
   250 	begin
   250     begin
   251 	if (Ammo^[Slot, Pos].Count > 0) and (Ammo^[Slot, Pos].AmmoType <> amNothing) then
   251     if (Ammo^[Slot, Pos].Count > 0) and (Ammo^[Slot, Pos].AmmoType <> amNothing) then
   252 		if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
   252         if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
   253 			begin
   253             begin
   254 			amSel:= Ammo^[Slot, Pos].AmmoType;
   254             amSel:= Ammo^[Slot, Pos].AmmoType;
   255 			RenderWeaponTooltip(amSel)
   255             RenderWeaponTooltip(amSel)
   256 			end;
   256             end;
   257 		
   257         
   258 		DrawTexture(cScreenWidth div 2 - 200 + AMxShift, cScreenHeight - 68, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex);
   258         DrawTexture(cScreenWidth div 2 - 200 + AMxShift, cScreenHeight - 68, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex);
   259 
   259 
   260 		if Ammo^[Slot, Pos].Count < AMMO_INFINITE then
   260         if Ammo^[Slot, Pos].Count < AMMO_INFINITE then
   261 			DrawTexture(cScreenWidth div 2 + AMxShift - 35, cScreenHeight - 68, CountTexz[Ammo^[Slot, Pos].Count]);
   261             DrawTexture(cScreenWidth div 2 + AMxShift - 35, cScreenHeight - 68, CountTexz[Ammo^[Slot, Pos].Count]);
   262 
   262 
   263 		if bSelected and (Ammoz[Ammo^[Slot, Pos].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber < 0) then
   263         if bSelected and (Ammoz[Ammo^[Slot, Pos].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber < 0) then
   264 			begin
   264             begin
   265 			bShowAmmoMenu:= false;
   265             bShowAmmoMenu:= false;
   266 			SetWeapon(Ammo^[Slot, Pos].AmmoType);
   266             SetWeapon(Ammo^[Slot, Pos].AmmoType);
   267 			bSelected:= false;
   267             bSelected:= false;
   268 			FreeWeaponTooltip;
   268             FreeWeaponTooltip;
   269 			exit
   269             exit
   270 			end;
   270             end;
   271 	end
   271     end
   272 else
   272 else
   273 	FreeWeaponTooltip;
   273     FreeWeaponTooltip;
   274 
   274 
   275 if (WeaponTooltipTex <> nil) and (AMxShift = 0) then
   275 if (WeaponTooltipTex <> nil) and (AMxShift = 0) then
   276 	ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, y);
   276     ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, y);
   277 
   277 
   278 bSelected:= false;
   278 bSelected:= false;
   279 if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
   279 if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
   280 end;
   280 end;
   281 
   281 
   294 lw:= cScreenWidth / cScaleFactor;
   294 lw:= cScreenWidth / cScaleFactor;
   295 lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
   295 lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
   296 // Water
   296 // Water
   297 r.y:= WorldDy + cWaterLine;
   297 r.y:= WorldDy + cWaterLine;
   298 if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
   298 if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
   299 	begin
   299     begin
   300 	if r.y < 0 then r.y:= 0;
   300     if r.y < 0 then r.y:= 0;
   301 
   301 
   302 	glDisable(GL_TEXTURE_2D);
   302     glDisable(GL_TEXTURE_2D);
   303 	VertexBuffer[0].X:= -lw;
   303     VertexBuffer[0].X:= -lw;
   304 	VertexBuffer[0].Y:= r.y;
   304     VertexBuffer[0].Y:= r.y;
   305 	VertexBuffer[1].X:= lw;
   305     VertexBuffer[1].X:= lw;
   306 	VertexBuffer[1].Y:= r.y;
   306     VertexBuffer[1].Y:= r.y;
   307 	VertexBuffer[2].X:= lw;
   307     VertexBuffer[2].X:= lw;
   308 	VertexBuffer[2].Y:= lh;
   308     VertexBuffer[2].Y:= lh;
   309 	VertexBuffer[3].X:= -lw;
   309     VertexBuffer[3].X:= -lw;
   310 	VertexBuffer[3].Y:= lh;
   310     VertexBuffer[3].Y:= lh;
   311 
   311 
   312 	glEnableClientState (GL_COLOR_ARRAY);
   312     glEnableClientState (GL_COLOR_ARRAY);
   313 	glColorPointer(4, GL_UNSIGNED_BYTE, 0, @WaterColorArray[0]);
   313     glColorPointer(4, GL_UNSIGNED_BYTE, 0, @WaterColorArray[0]);
   314 
   314 
   315 	glEnableClientState(GL_VERTEX_ARRAY);
   315     glEnableClientState(GL_VERTEX_ARRAY);
   316 	glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   316     glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   317 
   317 
   318 	glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   318     glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   319 
   319 
   320 	glDisableClientState(GL_VERTEX_ARRAY);
   320     glDisableClientState(GL_VERTEX_ARRAY);
   321 	glDisableClientState(GL_COLOR_ARRAY);
   321     glDisableClientState(GL_COLOR_ARRAY);
   322 
   322 
   323 	glColor4f(1, 1, 1, 1); // disable coloring
   323     glColor4f(1, 1, 1, 1); // disable coloring
   324 	glEnable(GL_TEXTURE_2D)
   324     glEnable(GL_TEXTURE_2D)
   325 	end
   325     end
   326 end;
   326 end;
   327 
   327 
   328 procedure DrawWaves(Dir, dX, dY: LongInt);
   328 procedure DrawWaves(Dir, dX, dY: LongInt);
   329 var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   329 var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   330 	lw, waves, shift: GLfloat;
   330     lw, waves, shift: GLfloat;
   331 begin
   331 begin
   332 lw:= cScreenWidth / cScaleFactor;
   332 lw:= cScreenWidth / cScaleFactor;
   333 waves:= lw * 2 / cWaveWidth;
   333 waves:= lw * 2 / cWaveWidth;
   334 
   334 
   335 glBindTexture(GL_TEXTURE_2D, SpritesData[sprWater].Texture^.id);
   335 glBindTexture(GL_TEXTURE_2D, SpritesData[sprWater].Texture^.id);
   363 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   363 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   364 glDisableClientState(GL_VERTEX_ARRAY);
   364 glDisableClientState(GL_VERTEX_ARRAY);
   365 
   365 
   366 
   366 
   367 {for i:= -1 to cWaterSprCount do
   367 {for i:= -1 to cWaterSprCount do
   368 	DrawSprite(sprWater,
   368     DrawSprite(sprWater,
   369 		i * cWaveWidth + ((WorldDx + (RealTicks shr 6) * Dir + dX) mod cWaveWidth) - (cScreenWidth div 2),
   369         i * cWaveWidth + ((WorldDx + (RealTicks shr 6) * Dir + dX) mod cWaveWidth) - (cScreenWidth div 2),
   370 		cWaterLine + WorldDy + dY,
   370         cWaterLine + WorldDy + dY,
   371 		0)}
   371         0)}
   372 end;
   372 end;
   373 
   373 
   374 procedure DrawRepeated(spr, sprL, sprR: TSprite; Shift: LongInt);
   374 procedure DrawRepeated(spr, sprL, sprR: TSprite; Shift: LongInt);
   375 var i, w, sw: LongInt;
   375 var i, w, sw: LongInt;
   376 begin
   376 begin
   377 sw:= round(cScreenWidth / cScaleFactor);
   377 sw:= round(cScreenWidth / cScaleFactor);
   378 if (SpritesData[sprL].Texture = nil) or (SpritesData[sprR].Texture = nil) then
   378 if (SpritesData[sprL].Texture = nil) or (SpritesData[sprR].Texture = nil) then
   379 	begin
   379     begin
   380 	w:= SpritesData[spr].Width;
   380     w:= SpritesData[spr].Width;
   381 	i:= Shift mod w;
   381     i:= Shift mod w;
   382 	if i > 0 then dec(i, w);
   382     if i > 0 then dec(i, w);
   383 	dec(i, w * (sw div w + 1));
   383     dec(i, w * (sw div w + 1));
   384 	repeat
   384     repeat
   385 		DrawSprite(spr, i, WorldDy + LAND_HEIGHT - SpritesData[spr].Height, 0);
   385         DrawSprite(spr, i, WorldDy + LAND_HEIGHT - SpritesData[spr].Height, 0);
   386 		inc(i, w)
   386         inc(i, w)
   387 	until i > sw
   387     until i > sw
   388 	end else
   388     end else
   389 	begin
   389     begin
   390 	w:= SpritesData[spr].Width;
   390     w:= SpritesData[spr].Width;
   391 	dec(Shift, w div 2);
   391     dec(Shift, w div 2);
   392 	DrawSprite(spr, Shift, WorldDy + LAND_HEIGHT - SpritesData[spr].Height, 0);
   392     DrawSprite(spr, Shift, WorldDy + LAND_HEIGHT - SpritesData[spr].Height, 0);
   393 
   393 
   394 	sw:= round(cScreenWidth / cScaleFactor);
   394     sw:= round(cScreenWidth / cScaleFactor);
   395 	
   395     
   396 	i:= Shift - SpritesData[sprL].Width;
   396     i:= Shift - SpritesData[sprL].Width;
   397 	while i >= -sw - SpritesData[sprL].Width do
   397     while i >= -sw - SpritesData[sprL].Width do
   398 		begin
   398         begin
   399 		DrawSprite(sprL, i, WorldDy + LAND_HEIGHT - SpritesData[sprL].Height, 0);
   399         DrawSprite(sprL, i, WorldDy + LAND_HEIGHT - SpritesData[sprL].Height, 0);
   400 		dec(i, SpritesData[sprL].Width);
   400         dec(i, SpritesData[sprL].Width);
   401 		end;
   401         end;
   402 		
   402         
   403 	i:= Shift + w;
   403     i:= Shift + w;
   404 	while i <= sw do
   404     while i <= sw do
   405 		begin
   405         begin
   406 		DrawSprite(sprR, i, WorldDy + LAND_HEIGHT - SpritesData[sprR].Height, 0);
   406         DrawSprite(sprR, i, WorldDy + LAND_HEIGHT - SpritesData[sprR].Height, 0);
   407 		inc(i, SpritesData[sprR].Width)
   407         inc(i, SpritesData[sprR].Width)
   408 		end
   408         end
   409 	end
   409     end
   410 end;
   410 end;
   411 
   411 
   412 
   412 
   413 procedure DrawWorld(Lag: LongInt);
   413 procedure DrawWorld(Lag: LongInt);
   414 var i, t: LongInt;
   414 var i, t: LongInt;
   419     highlight: Boolean;
   419     highlight: Boolean;
   420     offset, offsetX, offsetY: LongInt;
   420     offset, offsetX, offsetY: LongInt;
   421     scale: GLfloat;
   421     scale: GLfloat;
   422 begin
   422 begin
   423 if ZoomValue < zoom then
   423 if ZoomValue < zoom then
   424 	begin
   424     begin
   425 	zoom:= zoom - 0.002 * Lag;
   425     zoom:= zoom - 0.002 * Lag;
   426 	if ZoomValue > zoom then zoom:= ZoomValue
   426     if ZoomValue > zoom then zoom:= ZoomValue
   427 	end else
   427     end else
   428 if ZoomValue > zoom then
   428 if ZoomValue > zoom then
   429 	begin
   429     begin
   430 	zoom:= zoom + 0.002 * Lag;
   430     zoom:= zoom + 0.002 * Lag;
   431 	if ZoomValue < zoom then zoom:= ZoomValue
   431     if ZoomValue < zoom then zoom:= ZoomValue
   432 	end;
   432     end;
   433 
   433 
   434 // Sky
   434 // Sky
   435 glClear(GL_COLOR_BUFFER_BIT);
   435 glClear(GL_COLOR_BUFFER_BIT);
   436 glEnable(GL_BLEND);
   436 glEnable(GL_BLEND);
   437 glEnable(GL_TEXTURE_2D);
   437 glEnable(GL_TEXTURE_2D);
   458 
   458 
   459 DrawWater(255);
   459 DrawWater(255);
   460 
   460 
   461 // Attack bar
   461 // Attack bar
   462 if CurrentTeam <> nil then
   462 if CurrentTeam <> nil then
   463 	case AttackBar of
   463     case AttackBar of
   464 (*        1: begin
   464 (*        1: begin
   465 		r:= StuffPoz[sPowerBar];
   465         r:= StuffPoz[sPowerBar];
   466 		{$WARNINGS OFF}
   466         {$WARNINGS OFF}
   467 		r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor;
   467         r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor;
   468 		{$WARNINGS ON}
   468         {$WARNINGS ON}
   469 		DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface);
   469         DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface);
   470 		end;*)
   470         end;*)
   471 		2: with CurrentHedgehog^ do
   471         2: with CurrentHedgehog^ do
   472 				begin
   472                 begin
   473 				tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle);
   473                 tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle);
   474 				tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle);
   474                 tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle);
   475 				for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do
   475                 for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do
   476 					DrawSprite(sprPower,
   476                     DrawSprite(sprPower,
   477 							hwRound(Gear^.X) + round(WorldDx + tdx * (24 + i * 2)) - 16,
   477                             hwRound(Gear^.X) + round(WorldDx + tdx * (24 + i * 2)) - 16,
   478 							hwRound(Gear^.Y) + round(WorldDy + tdy * (24 + i * 2)) - 12,
   478                             hwRound(Gear^.Y) + round(WorldDy + tdy * (24 + i * 2)) - 12,
   479 							i)
   479                             i)
   480 				end
   480                 end
   481 		end;
   481         end;
   482 
   482 
   483 DrawVisualGears(1);
   483 DrawVisualGears(1);
   484 
   484 
   485 DrawGears;
   485 DrawGears;
   486 
   486 
   495 
   495 
   496 
   496 
   497 {$WARNINGS OFF}
   497 {$WARNINGS OFF}
   498 // Target
   498 // Target
   499 if TargetPoint.X <> NoPointX then
   499 if TargetPoint.X <> NoPointX then
   500 	DrawRotatedF(sprTargetP, TargetPoint.X + WorldDx, TargetPoint.Y + WorldDy, 0, 0, (RealTicks shr 3) mod 360);
   500     DrawRotatedF(sprTargetP, TargetPoint.X + WorldDx, TargetPoint.Y + WorldDy, 0, 0, (RealTicks shr 3) mod 360);
   501 {$WARNINGS ON}
   501 {$WARNINGS ON}
   502 
   502 
   503 {$IFDEF IPHONEOS}
   503 {$IFDEF IPHONEOS}
   504 scale:= 1.5;
   504 scale:= 1.5;
   505 {$ELSE}
   505 {$ELSE}
   531    end;
   531    end;
   532 
   532 
   533 {$IFNDEF IPHONEOS}
   533 {$IFNDEF IPHONEOS}
   534 // Timetrial
   534 // Timetrial
   535 if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then
   535 if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then
   536 	begin
   536     begin
   537 	if TimeTrialStopTime = 0 then i:= RealTicks - TimeTrialStartTime else i:= TimeTrialStopTime - TimeTrialStartTime;
   537     if TimeTrialStopTime = 0 then i:= RealTicks - TimeTrialStartTime else i:= TimeTrialStopTime - TimeTrialStartTime;
   538 	t:= 272;
   538     t:= 272;
   539 	// right frame
   539     // right frame
   540 	DrawSprite(sprFrame, -cScreenWidth div 2 + t, 8, 1);
   540     DrawSprite(sprFrame, -cScreenWidth div 2 + t, 8, 1);
   541     dec(t, 32);
   541     dec(t, 32);
   542 	// 1 ms
   542     // 1 ms
   543     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10); 
   543     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10); 
   544     dec(t, 32);
   544     dec(t, 32);
   545 	i:= i div 10;
   545     i:= i div 10;
   546 	// 10 ms
   546     // 10 ms
   547     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   547     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   548     dec(t, 32);
   548     dec(t, 32);
   549 	i:= i div 10;
   549     i:= i div 10;
   550 	// 100 ms
   550     // 100 ms
   551     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   551     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   552 	dec(t, 16);
   552     dec(t, 16);
   553 	// Point
   553     // Point
   554 	DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, 11);
   554     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, 11);
   555     dec(t, 32);
   555     dec(t, 32);
   556 	i:= i div 10;
   556     i:= i div 10;
   557 	// 1 s
   557     // 1 s
   558     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   558     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   559     dec(t, 32);
   559     dec(t, 32);
   560 	i:= i div 10;
   560     i:= i div 10;
   561 	// 10s
   561     // 10s
   562     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 6);
   562     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 6);
   563 	dec(t, 16);
   563     dec(t, 16);
   564 	// Point
   564     // Point
   565 	DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, 10);
   565     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, 10);
   566     dec(t, 32);
   566     dec(t, 32);
   567 	i:= i div 6;
   567     i:= i div 6;
   568 	// 1 m
   568     // 1 m
   569     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   569     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   570     dec(t, 32);
   570     dec(t, 32);
   571 	i:= i div 10;
   571     i:= i div 10;
   572 	// 10 m
   572     // 10 m
   573     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   573     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   574 	// left frame
   574     // left frame
   575 	DrawSprite(sprFrame, -cScreenWidth div 2 + t - 4, 8, 0);
   575     DrawSprite(sprFrame, -cScreenWidth div 2 + t - 4, 8, 0);
   576 	end;
   576     end;
   577 {$ENDIF}
   577 {$ENDIF}
   578 
   578 
   579 // Captions
   579 // Captions
   580 {$IFDEF IPHONEOS}
   580 {$IFDEF IPHONEOS}
   581 offset:= 40;
   581 offset:= 40;
   582 {$ELSE}
   582 {$ELSE}
   583 if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then offset:= 48
   583 if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then offset:= 48
   584 else offset:= 8;
   584 else offset:= 8;
   585 {$ENDIF}
   585 {$ENDIF}
   586 
   586 
   587 	for grp:= Low(TCapGroup) to High(TCapGroup) do
   587     for grp:= Low(TCapGroup) to High(TCapGroup) do
   588 		with Captions[grp] do
   588         with Captions[grp] do
   589 			if Tex <> nil then
   589             if Tex <> nil then
   590 			begin
   590             begin
   591 				DrawCentered(0, offset, Tex);
   591                 DrawCentered(0, offset, Tex);
   592 				inc(offset, Tex^.h + 2);
   592                 inc(offset, Tex^.h + 2);
   593 				if EndTime <= RealTicks then
   593                 if EndTime <= RealTicks then
   594 				begin
   594                 begin
   595 					FreeTexture(Tex);
   595                     FreeTexture(Tex);
   596 					Tex:= nil;
   596                     Tex:= nil;
   597 					EndTime:= 0
   597                     EndTime:= 0
   598 				end;
   598                 end;
   599 			end;
   599             end;
   600 
   600 
   601 // Teams Healths
   601 // Teams Healths
   602 
   602 
   603 for t:= 0 to Pred(TeamsCount) do
   603 for t:= 0 to Pred(TeamsCount) do
   604    with TeamsArray[t]^ do
   604    with TeamsArray[t]^ do
   692 
   692 
   693 if fastUntilLag then DrawCentered(0, (cScreenHeight shr 1), SyncTexture);
   693 if fastUntilLag then DrawCentered(0, (cScreenHeight shr 1), SyncTexture);
   694 if isPaused then DrawCentered(0, (cScreenHeight shr 1), PauseTexture);
   694 if isPaused then DrawCentered(0, (cScreenHeight shr 1), PauseTexture);
   695 
   695 
   696 if missionTimer <> 0 then
   696 if missionTimer <> 0 then
   697 	begin
   697     begin
   698 	if missionTimer > 0 then dec(missionTimer, Lag);
   698     if missionTimer > 0 then dec(missionTimer, Lag);
   699 	if missionTimer < 0 then missionTimer:= 0; // avoid subtracting below 0
   699     if missionTimer < 0 then missionTimer:= 0; // avoid subtracting below 0
   700 	if missionTex <> nil then
   700     if missionTex <> nil then
   701 		DrawCentered(0, min((cScreenHeight shr 1) + 100, cScreenHeight - 48 - missionTex^.h), missionTex);
   701         DrawCentered(0, min((cScreenHeight shr 1) + 100, cScreenHeight - 48 - missionTex^.h), missionTex);
   702 	end;
   702     end;
   703 
   703 
   704 // fps
   704 // fps
   705 {$IFDEF IPHONEOS}
   705 {$IFDEF IPHONEOS}
   706 offset:= 300;
   706 offset:= 300;
   707 {$ELSE}
   707 {$ELSE}
   760       AddCaption(Format(trmsg[sidVolume], s), cWhiteColor, capgrpVolume)
   760       AddCaption(Format(trmsg[sidVolume], s), cWhiteColor, capgrpVolume)
   761       end
   761       end
   762    end;
   762    end;
   763 
   763 
   764 if GameState = gsConfirm then
   764 if GameState = gsConfirm then
   765 	DrawCentered(0, cScreenHeight div 2, ConfirmTexture);
   765     DrawCentered(0, cScreenHeight div 2, ConfirmTexture);
   766 
   766 
   767 SetScale(zoom);
   767 SetScale(zoom);
   768 
   768 
   769 // Cursor
   769 // Cursor
   770 if isCursorVisible then
   770 if isCursorVisible then
   794 if Captions[Group].Tex <> nil then FreeTexture(Captions[Group].Tex);
   794 if Captions[Group].Tex <> nil then FreeTexture(Captions[Group].Tex);
   795 
   795 
   796 Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
   796 Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
   797 
   797 
   798 case Group of
   798 case Group of
   799 	capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200
   799     capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200
   800 	else
   800     else
   801 	Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3;
   801     Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3;
   802 	end;
   802     end;
   803 end;
   803 end;
   804 
   804 
   805 procedure MoveCamera;
   805 procedure MoveCamera;
   806 const PrevSentPointTime: LongWord = 0;
   806 const PrevSentPointTime: LongWord = 0;
   807 var EdgesDist,  wdy: LongInt;
   807 var EdgesDist,  wdy: LongInt;
   808 begin
   808 begin
   809 if (not (CurrentTeam^.ExtDriven and isCursorVisible)) and cHasFocus then
   809 if (not (CurrentTeam^.ExtDriven and isCursorVisible)) and cHasFocus then
   810 	begin
   810     begin
   811 	SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y);
   811     SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y);
   812 	CursorPoint.X:= CursorPoint.X - (cScreenWidth shr 1);
   812     CursorPoint.X:= CursorPoint.X - (cScreenWidth shr 1);
   813 	CursorPoint.Y:= cScreenHeight - CursorPoint.Y;
   813     CursorPoint.Y:= cScreenHeight - CursorPoint.Y;
   814 	end;
   814     end;
   815 
   815 
   816 if (not PlacingHogs) and (FollowGear <> nil) and (not isCursorVisible) and (not fastUntilLag) then
   816 if (not PlacingHogs) and (FollowGear <> nil) and (not isCursorVisible) and (not fastUntilLag) then
   817 	if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then
   817     if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then
   818 		begin
   818         begin
   819 		FollowGear:= nil;
   819         FollowGear:= nil;
   820 		prevPoint:= CursorPoint;
   820         prevPoint:= CursorPoint;
   821 		exit
   821         exit
   822 		end
   822         end
   823 		else begin
   823         else begin
   824 		CursorPoint.x:= (prevPoint.x * 7 + hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100 + WorldDx) div 8;
   824         CursorPoint.x:= (prevPoint.x * 7 + hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100 + WorldDx) div 8;
   825 		CursorPoint.y:= (prevPoint.y * 7 + cScreenHeight - (hwRound(FollowGear^.Y) + WorldDy)) div 8;
   825         CursorPoint.y:= (prevPoint.y * 7 + cScreenHeight - (hwRound(FollowGear^.Y) + WorldDy)) div 8;
   826 		end;
   826         end;
   827 
   827 
   828 wdy:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine - cVisibleWater;
   828 wdy:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine - cVisibleWater;
   829 if WorldDy < wdy then WorldDy:= wdy;
   829 if WorldDy < wdy then WorldDy:= wdy;
   830 
   830 
   831 if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then exit;
   831 if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then exit;
   832 
   832 
   833 if AMxShift < 210 then
   833 if AMxShift < 210 then
   834 	begin
   834     begin
   835 	if CursorPoint.X < cScreenWidth div 2 + AMxShift - 175 then CursorPoint.X:= cScreenWidth div 2 + AMxShift - 175;
   835     if CursorPoint.X < cScreenWidth div 2 + AMxShift - 175 then CursorPoint.X:= cScreenWidth div 2 + AMxShift - 175;
   836 	if CursorPoint.X > cScreenWidth div 2 + AMxShift - 10 then CursorPoint.X:= cScreenWidth div 2 + AMxShift - 10;
   836     if CursorPoint.X > cScreenWidth div 2 + AMxShift - 10 then CursorPoint.X:= cScreenWidth div 2 + AMxShift - 10;
   837 	if CursorPoint.Y > 75 + SlotsNum * 33 then CursorPoint.Y:= 75 + SlotsNum * 33;
   837     if CursorPoint.Y > 75 + SlotsNum * 33 then CursorPoint.Y:= 75 + SlotsNum * 33;
   838 	if CursorPoint.Y < 76 then CursorPoint.Y:= 76;
   838     if CursorPoint.Y < 76 then CursorPoint.Y:= 76;
   839 	prevPoint:= CursorPoint;
   839     prevPoint:= CursorPoint;
   840 	if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
   840     if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
   841 	exit
   841     exit
   842 	end;
   842     end;
   843 
   843 
   844 if isCursorVisible then
   844 if isCursorVisible then
   845 	begin
   845     begin
   846 	if (not CurrentTeam^.ExtDriven) and (GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
   846     if (not CurrentTeam^.ExtDriven) and (GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
   847 		begin
   847         begin
   848 		SendIPCXY('P', CursorPoint.X - WorldDx, cScreenHeight - CursorPoint.Y - WorldDy);
   848         SendIPCXY('P', CursorPoint.X - WorldDx, cScreenHeight - CursorPoint.Y - WorldDy);
   849 		PrevSentPointTime:= GameTicks
   849         PrevSentPointTime:= GameTicks
   850 		end;
   850         end;
   851 	end;
   851     end;
   852 
   852 
   853 if isCursorVisible or (FollowGear <> nil) then
   853 if isCursorVisible or (FollowGear <> nil) then
   854    begin
   854    begin
   855    if isCursorVisible then EdgesDist:= cCursorEdgesDist
   855    if isCursorVisible then EdgesDist:= cCursorEdgesDist
   856                       else EdgesDist:= cGearScrEdgesDist;
   856                       else EdgesDist:= cGearScrEdgesDist;
   900 if time = 0 then time:= 5000;
   900 if time = 0 then time:= 5000;
   901 missionTimer:= time;
   901 missionTimer:= time;
   902 if missionTex <> nil then FreeTexture(missionTex);
   902 if missionTex <> nil then FreeTexture(missionTex);
   903 
   903 
   904 if icon > -1 then
   904 if icon > -1 then
   905 	begin
   905     begin
   906 	r.x:= 0;
   906     r.x:= 0;
   907 	r.y:= icon * 32;
   907     r.y:= icon * 32;
   908 	missionTex:= RenderHelpWindow(caption, subcaption, text, '', 0, MissionIcons, @r)
   908     missionTex:= RenderHelpWindow(caption, subcaption, text, '', 0, MissionIcons, @r)
   909 	end
   909     end
   910 else
   910 else
   911 	begin
   911     begin
   912 	r.x:= ((-icon - 1) shr 5) * 32;
   912     r.x:= ((-icon - 1) shr 5) * 32;
   913 	r.y:= ((-icon - 1) mod 32) * 32;
   913     r.y:= ((-icon - 1) mod 32) * 32;
   914 	missionTex:= RenderHelpWindow(caption, subcaption, text, '', 0, SpritesData[sprAMAmmos].Surface, @r)
   914     missionTex:= RenderHelpWindow(caption, subcaption, text, '', 0, SpritesData[sprAMAmmos].Surface, @r)
   915 	end;
   915     end;
   916 end;
   916 end;
   917 
   917 
   918 procedure HideMission;
   918 procedure HideMission;
   919 begin
   919 begin
   920 missionTimer:= 0
   920 missionTimer:= 0
   921 end;
   921 end;
   922 
   922 
   923 procedure init_uWorld;
   923 procedure init_uWorld;
   924 begin
   924 begin
   925 	fpsTexture:= nil;
   925     fpsTexture:= nil;
   926 	FollowGear:= nil;
   926     FollowGear:= nil;
   927 	WindBarWidth:= 0;
   927     WindBarWidth:= 0;
   928 	bShowAmmoMenu:= false;
   928     bShowAmmoMenu:= false;
   929 	bSelected:= false;
   929     bSelected:= false;
   930 	bShowFinger:= false;
   930     bShowFinger:= false;
   931 	Frames:= 0;
   931     Frames:= 0;
   932 	WorldDx:= -512;
   932     WorldDx:= -512;
   933 	WorldDy:= -256;
   933     WorldDy:= -256;
   934     
   934     
   935 	FPS:= 0;
   935     FPS:= 0;
   936 	CountTicks:= 0;
   936     CountTicks:= 0;
   937 	SoundTimerTicks:= 0;
   937     SoundTimerTicks:= 0;
   938 	prevPoint.X:= 0;
   938     prevPoint.X:= 0;
   939 	prevPoint.Y:= 0;
   939     prevPoint.Y:= 0;
   940 	missionTimer:= 0;
   940     missionTimer:= 0;
   941 	
   941     
   942 	FillChar(Captions, sizeof(Captions), 0)
   942     FillChar(Captions, sizeof(Captions), 0)
   943 end;
   943 end;
   944 
   944 
   945 procedure free_uWorld;
   945 procedure free_uWorld;
   946 begin
   946 begin
   947 if missionTex <> nil then FreeTexture(missionTex);
   947 if missionTex <> nil then FreeTexture(missionTex);