hedgewars/uGears.pas
changeset 2362 ef4abaf2d5cc
parent 2333 f53a208e9637
child 2363 5304fa032d9b
equal deleted inserted replaced
2361:f980f40e83f5 2362:ef4abaf2d5cc
    94                 ar: array[0..MAXROPEPOINTS] of record
    94                 ar: array[0..MAXROPEPOINTS] of record
    95                                   X, Y: hwFloat;
    95                                   X, Y: hwFloat;
    96                                   dLen: hwFloat;
    96                                   dLen: hwFloat;
    97                                   b: boolean;
    97                                   b: boolean;
    98                                   end;
    98                                   end;
    99                  end;
    99                 rounded: array[0..MAXROPEPOINTS] of TVertex2i;
       
   100                 end;
   100 
   101 
   101 procedure DeleteGear(Gear: PGear); forward;
   102 procedure DeleteGear(Gear: PGear); forward;
   102 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); forward;
   103 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); forward;
   103 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
   104 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
   104 //procedure AmmoFlameWork(Ammo: PGear); forward;
   105 //procedure AmmoFlameWork(Ammo: PGear); forward;
   854 			//if (abs(lx-tx)>8) or (abs(ly-ty)>8) then
   855 			//if (abs(lx-tx)>8) or (abs(ly-ty)>8) then
   855 				begin
   856 				begin
   856 				glDisable(GL_TEXTURE_2D);
   857 				glDisable(GL_TEXTURE_2D);
   857 				glEnable(GL_LINE_SMOOTH);
   858 				glEnable(GL_LINE_SMOOTH);
   858 
   859 
       
   860 				glLineWidth(1.0);
       
   861 				
   859 				glColor4ub($FF, $00, $00, $C0);
   862 				glColor4ub($FF, $00, $00, $C0);
   860 				VertexBuffer[0].X:= hx + WorldDx;
   863 				VertexBuffer[0].X:= hx + WorldDx;
   861 				VertexBuffer[0].Y:= hy + WorldDy;
   864 				VertexBuffer[0].Y:= hy + WorldDy;
   862 				VertexBuffer[1].X:= tx + WorldDx;
   865 				VertexBuffer[1].X:= tx + WorldDx;
   863 				VertexBuffer[1].Y:= ty + WorldDy;
   866 				VertexBuffer[1].Y:= ty + WorldDy;
  1254     begin
  1257     begin
  1255     DrawSprite(sprVampiric, sx - 24, sy - 24, 0);
  1258     DrawSprite(sprVampiric, sx - 24, sy - 24, 0);
  1256     end;
  1259     end;
  1257 end;
  1260 end;
  1258 
  1261 
       
  1262 procedure DrawRopeLinesRQ(Gear: PGear);
       
  1263 var i, cnt: LongInt;
       
  1264 	px, py: LongInt;
       
  1265 begin
       
  1266 // FIXME: store rounded coordinates in second points array
       
  1267 cnt:= 0;
       
  1268 with RopePoints do
       
  1269 	if RopePoints.Count > 0 then
       
  1270 		begin
       
  1271 		i:= 0;
       
  1272 		cnt:= 0;
       
  1273 		px:= hwRound(ar[0].X) - 1;
       
  1274 		while i < Count do
       
  1275 			begin
       
  1276 			rounded[cnt].X:= hwRound(ar[i].X) + WorldDx;
       
  1277 			rounded[cnt].Y:= hwRound(ar[i].Y) + WorldDy;
       
  1278 			// prevent equal points
       
  1279 			if (px <> rounded[cnt].X) or (py <> rounded[cnt].Y) then
       
  1280 				begin
       
  1281 				px:= rounded[cnt].X;
       
  1282 				py:= rounded[cnt].Y;
       
  1283 				inc(cnt)
       
  1284 				end;
       
  1285 			inc(i)
       
  1286 			end;
       
  1287 		rounded[cnt].X:= hwRound(Gear^.X) + WorldDx;
       
  1288 		rounded[cnt].Y:= hwRound(Gear^.Y) + WorldDy;
       
  1289 		inc(cnt);
       
  1290 		rounded[cnt].X:= hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx;
       
  1291 		rounded[cnt].Y:= hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy;
       
  1292 		end else
       
  1293 		if Gear^.Elasticity.QWordValue > 0 then
       
  1294 			begin
       
  1295 			cnt:= 1;
       
  1296 			rounded[0].X:= hwRound(Gear^.X) + WorldDx;
       
  1297 			rounded[0].Y:= hwRound(Gear^.Y) + WorldDy;
       
  1298 			rounded[1].X:= hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx;
       
  1299 			rounded[1].Y:= hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy;
       
  1300 			end;
       
  1301 
       
  1302 if cnt > 0 then
       
  1303 	begin
       
  1304 	glDisable(GL_TEXTURE_2D);
       
  1305 	glEnable(GL_LINE_SMOOTH);
       
  1306 	
       
  1307 	glLineWidth(4.0);
       
  1308 
       
  1309 	glColor4ub($A0, $A0, $A0, $C0);
       
  1310 
       
  1311 	glEnableClientState(GL_VERTEX_ARRAY);
       
  1312 	glVertexPointer(2, GL_INT, 0, @RopePoints.rounded[0]);
       
  1313 	glDrawArrays(GL_LINES, 0, cnt + 1);
       
  1314 	glColor4f(1, 1, 1, 1);
       
  1315 	glEnable(GL_TEXTURE_2D);
       
  1316 	glDisable(GL_LINE_SMOOTH);
       
  1317 	end
       
  1318 end;
       
  1319 
       
  1320 procedure DrawRope(Gear: PGear);
       
  1321 var roplen: LongInt;
       
  1322 	i: LongInt;
       
  1323 
       
  1324 	procedure DrawRopeLine(X1, Y1, X2, Y2: LongInt);
       
  1325 	var  eX, eY, dX, dY: LongInt;
       
  1326 		i, sX, sY, x, y, d: LongInt;
       
  1327 		b: boolean;
       
  1328 	begin
       
  1329 	if (X1 = X2) and (Y1 = Y2) then
       
  1330 	begin
       
  1331 	//OutError('WARNING: zero length rope line!', false);
       
  1332 	exit
       
  1333 	end;
       
  1334 	eX:= 0;
       
  1335 	eY:= 0;
       
  1336 	dX:= X2 - X1;
       
  1337 	dY:= Y2 - Y1;
       
  1338 
       
  1339 	if (dX > 0) then sX:= 1
       
  1340 	else
       
  1341 	if (dX < 0) then
       
  1342 		begin
       
  1343 		sX:= -1;
       
  1344 		dX:= -dX
       
  1345 		end else sX:= dX;
       
  1346 
       
  1347 	if (dY > 0) then sY:= 1
       
  1348 	else
       
  1349 	if (dY < 0) then
       
  1350 		begin
       
  1351 		sY:= -1;
       
  1352 		dY:= -dY
       
  1353 		end else sY:= dY;
       
  1354 
       
  1355 		if (dX > dY) then d:= dX
       
  1356 					else d:= dY;
       
  1357 
       
  1358 		x:= X1;
       
  1359 		y:= Y1;
       
  1360 
       
  1361 		for i:= 0 to d do
       
  1362 			begin
       
  1363 			inc(eX, dX);
       
  1364 			inc(eY, dY);
       
  1365 			b:= false;
       
  1366 			if (eX > d) then
       
  1367 				begin
       
  1368 				dec(eX, d);
       
  1369 				inc(x, sX);
       
  1370 				b:= true
       
  1371 				end;
       
  1372 			if (eY > d) then
       
  1373 				begin
       
  1374 				dec(eY, d);
       
  1375 				inc(y, sY);
       
  1376 				b:= true
       
  1377 				end;
       
  1378 			if b then
       
  1379 				begin
       
  1380 				inc(roplen);
       
  1381 				if (roplen mod 4) = 0 then DrawSprite(sprRopeNode, x - 2, y - 2, 0)
       
  1382 				end
       
  1383 		end
       
  1384 	end;
       
  1385 begin
       
  1386 	if cReducedQuality then
       
  1387 		DrawRopeLinesRQ(Gear)
       
  1388 	else
       
  1389 		begin
       
  1390 		roplen:= 0;
       
  1391 		if RopePoints.Count > 0 then
       
  1392 			begin
       
  1393 			i:= 0;
       
  1394 			while i < Pred(RopePoints.Count) do
       
  1395 					begin
       
  1396 					DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy,
       
  1397 								hwRound(RopePoints.ar[Succ(i)].X) + WorldDx, hwRound(RopePoints.ar[Succ(i)].Y) + WorldDy);
       
  1398 					inc(i)
       
  1399 					end;
       
  1400 			DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy,
       
  1401 						hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy);
       
  1402 			DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy,
       
  1403 						hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy);
       
  1404 			end else
       
  1405 			if Gear^.Elasticity.QWordValue > 0 then
       
  1406 			DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy,
       
  1407 						hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy);
       
  1408 		end;
       
  1409 
       
  1410 
       
  1411 if RopePoints.Count > 0 then
       
  1412 	DrawRotated(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx, hwRound(RopePoints.ar[0].Y) + WorldDy, 1, RopePoints.HookAngle)
       
  1413 	else
       
  1414 	if Gear^.Elasticity.QWordValue > 0 then
       
  1415 		DrawRotated(sprRopeHook, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX));
       
  1416 end;
       
  1417 
  1259 procedure DrawGears;
  1418 procedure DrawGears;
  1260 var Gear, HHGear: PGear;
  1419 var Gear, HHGear: PGear;
  1261     i: Longword;
  1420     i: Longword;
  1262     roplen: LongInt;
       
  1263 
       
  1264     procedure DrawRopeLine(X1, Y1, X2, Y2: LongInt);
       
  1265     var  eX, eY, dX, dY: LongInt;
       
  1266          i, sX, sY, x, y, d: LongInt;
       
  1267          b: boolean;
       
  1268     begin
       
  1269     if (X1 = X2) and (Y1 = Y2) then
       
  1270        begin
       
  1271        //OutError('WARNING: zero length rope line!', false);
       
  1272        exit
       
  1273        end;
       
  1274     eX:= 0;
       
  1275     eY:= 0;
       
  1276     dX:= X2 - X1;
       
  1277     dY:= Y2 - Y1;
       
  1278 
       
  1279     if (dX > 0) then sX:= 1
       
  1280     else
       
  1281       if (dX < 0) then
       
  1282          begin
       
  1283          sX:= -1;
       
  1284          dX:= -dX
       
  1285          end else sX:= dX;
       
  1286 
       
  1287     if (dY > 0) then sY:= 1
       
  1288        else
       
  1289     if (dY < 0) then
       
  1290        begin
       
  1291        sY:= -1;
       
  1292        dY:= -dY
       
  1293        end else sY:= dY;
       
  1294 
       
  1295     if (dX > dY) then d:= dX
       
  1296                  else d:= dY;
       
  1297 
       
  1298     x:= X1;
       
  1299     y:= Y1;
       
  1300 
       
  1301     for i:= 0 to d do
       
  1302         begin
       
  1303         inc(eX, dX);
       
  1304         inc(eY, dY);
       
  1305         b:= false;
       
  1306         if (eX > d) then
       
  1307            begin
       
  1308            dec(eX, d);
       
  1309            inc(x, sX);
       
  1310            b:= true
       
  1311            end;
       
  1312         if (eY > d) then
       
  1313            begin
       
  1314            dec(eY, d);
       
  1315            inc(y, sY);
       
  1316            b:= true
       
  1317            end;
       
  1318         if b then
       
  1319            begin
       
  1320            inc(roplen);
       
  1321            if (roplen mod 4) = 0 then DrawSprite(sprRopeNode, x - 2, y - 2, 0)
       
  1322            end
       
  1323        end
       
  1324     end;
       
  1325 
       
  1326 begin
  1421 begin
  1327 Gear:= GearsList;
  1422 Gear:= GearsList;
  1328 while Gear<>nil do
  1423 while Gear<>nil do
  1329 	begin
  1424 	begin
  1330 	case Gear^.Kind of
  1425 	case Gear^.Kind of
  1348            gtGrave: DrawSurfSprite(hwRound(Gear^.X) + WorldDx - 16, hwRound(Gear^.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, PHedgehog(Gear^.Hedgehog)^.Team^.GraveTex);
  1443            gtGrave: DrawSurfSprite(hwRound(Gear^.X) + WorldDx - 16, hwRound(Gear^.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, PHedgehog(Gear^.Hedgehog)^.Team^.GraveTex);
  1349              
  1444              
  1350              gtUFO: DrawSprite(sprUFO, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4);
  1445              gtUFO: DrawSprite(sprUFO, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4);
  1351       
  1446       
  1352       gtPickHammer: DrawSprite(sprPHammer, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 50 + LongInt(((GameTicks shr 5) and 1) * 2) + WorldDy, 0);
  1447       gtPickHammer: DrawSprite(sprPHammer, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 50 + LongInt(((GameTicks shr 5) and 1) * 2) + WorldDy, 0);
  1353             gtRope: begin
  1448             gtRope: DrawRope(Gear);
  1354                     roplen:= 0;
       
  1355                     if RopePoints.Count > 0 then
       
  1356                        begin
       
  1357                        i:= 0;
       
  1358                        while i < Pred(RopePoints.Count) do
       
  1359                              begin
       
  1360                              DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy,
       
  1361                                           hwRound(RopePoints.ar[Succ(i)].X) + WorldDx, hwRound(RopePoints.ar[Succ(i)].Y) + WorldDy);
       
  1362                              inc(i)
       
  1363                              end;
       
  1364                        DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy,
       
  1365                                     hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy);
       
  1366                        DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy,
       
  1367                                     hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy);
       
  1368                        DrawRotated(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx, hwRound(RopePoints.ar[0].Y) + WorldDy, 1, RopePoints.HookAngle)
       
  1369                        end else
       
  1370                        if Gear^.Elasticity.QWordValue > 0 then
       
  1371                        begin
       
  1372                        DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy,
       
  1373                                     hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy);
       
  1374                        DrawRotated(sprRopeHook, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX));
       
  1375                        end;
       
  1376                     end;
       
  1377       gtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State);
  1449       gtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State);
  1378        gtExplosion: DrawSprite(sprExplosion50, hwRound(Gear^.X) - 32 + WorldDx, hwRound(Gear^.Y) - 32 + WorldDy, Gear^.State);
  1450        gtExplosion: DrawSprite(sprExplosion50, hwRound(Gear^.X) - 32 + WorldDx, hwRound(Gear^.Y) - 32 + WorldDy, Gear^.State);
  1379             gtMine: if ((Gear^.State and gstAttacking) = 0)or((Gear^.Timer and $3FF) < 420)
  1451             gtMine: if ((Gear^.State and gstAttacking) = 0)or((Gear^.Timer and $3FF) < 420)
  1380                        then DrawRotated(sprMineOff, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle)
  1452                        then DrawRotated(sprMineOff, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle)
  1381                        else DrawRotated(sprMineOn, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle);
  1453                        else DrawRotated(sprMineOn, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle);