hedgewars/uGearsHandlersMess.pas
changeset 13151 deab88f1f6f7
parent 13147 7040506c831f
child 13152 34ca90c2ffad
equal deleted inserted replaced
13150:2f7c25bf4201 13151:deab88f1f6f7
    45 procedure doStepGrave(Gear: PGear);
    45 procedure doStepGrave(Gear: PGear);
    46 procedure doStepBeeWork(Gear: PGear);
    46 procedure doStepBeeWork(Gear: PGear);
    47 procedure doStepBee(Gear: PGear);
    47 procedure doStepBee(Gear: PGear);
    48 procedure doStepShotIdle(Gear: PGear);
    48 procedure doStepShotIdle(Gear: PGear);
    49 procedure doStepShotgunShot(Gear: PGear);
    49 procedure doStepShotgunShot(Gear: PGear);
    50 procedure spawnBulletTrail(Bullet: PGear; bulletX, bulletY: hwFloat);
    50 procedure spawnBulletTrail(Bullet: PGear; bulletX, bulletY: hwFloat; fadeIn: Boolean);
    51 procedure doStepBulletWork(Gear: PGear);
    51 procedure doStepBulletWork(Gear: PGear);
    52 procedure doStepDEagleShot(Gear: PGear);
    52 procedure doStepDEagleShot(Gear: PGear);
    53 procedure doStepSniperRifleShot(Gear: PGear);
    53 procedure doStepSniperRifleShot(Gear: PGear);
    54 procedure doStepActionTimer(Gear: PGear);
    54 procedure doStepActionTimer(Gear: PGear);
    55 procedure doStepPickHammerWork(Gear: PGear);
    55 procedure doStepPickHammerWork(Gear: PGear);
  1205     if (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then
  1205     if (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then
  1206         Gear^.doStep := @doStepShotIdle
  1206         Gear^.doStep := @doStepShotIdle
  1207 end;
  1207 end;
  1208 
  1208 
  1209 ////////////////////////////////////////////////////////////////////////////////
  1209 ////////////////////////////////////////////////////////////////////////////////
  1210 procedure spawnBulletTrail(Bullet: PGear; bulletX, bulletY: hwFloat);
  1210 procedure spawnBulletTrail(Bullet: PGear; bulletX, bulletY: hwFloat; fadeIn: Boolean);
  1211 var oX, oY: hwFloat;
  1211 var oX, oY: hwFloat;
       
  1212     fromX, fromY, toX, toY, dX, dY, length, stepLength: real;
  1212     VGear: PVisualGear;
  1213     VGear: PVisualGear;
       
  1214     i, steps: LongWord;
  1213 begin
  1215 begin
  1214     if Bullet^.PortalCounter = 0 then
  1216     if Bullet^.PortalCounter = 0 then
  1215         begin
  1217         begin
  1216         ox:= CurrentHedgehog^.Gear^.X + Int2hwFloat(GetLaunchX(CurrentHedgehog^.CurAmmoType, hwSign(CurrentHedgehog^.Gear^.dX), CurrentHedgehog^.Gear^.Angle));
  1218         ox:= CurrentHedgehog^.Gear^.X + Int2hwFloat(GetLaunchX(CurrentHedgehog^.CurAmmoType, hwSign(CurrentHedgehog^.Gear^.dX), CurrentHedgehog^.Gear^.Angle));
  1217         oy:= CurrentHedgehog^.Gear^.Y + Int2hwFloat(GetLaunchY(CurrentHedgehog^.CurAmmoType, CurrentHedgehog^.Gear^.Angle));
  1219         oy:= CurrentHedgehog^.Gear^.Y + Int2hwFloat(GetLaunchY(CurrentHedgehog^.CurAmmoType, CurrentHedgehog^.Gear^.Angle));
  1220         begin
  1222         begin
  1221         ox:= Bullet^.Elasticity;
  1223         ox:= Bullet^.Elasticity;
  1222         oy:= Bullet^.Friction;
  1224         oy:= Bullet^.Friction;
  1223         end;
  1225         end;
  1224 
  1226 
  1225         // Bullet trail
  1227     fromX:= hwFloat2Float(ox);
  1226         VGear := AddVisualGear(hwRound(ox), hwRound(oy), vgtLineTrail);
  1228     fromY:= hwFloat2Float(oy);
  1227 
  1229     toX:= hwFloat2Float(bulletX);
  1228         if VGear <> nil then
  1230     toY:= hwFloat2Float(bulletY);
  1229             begin
  1231 
  1230             VGear^.X:= hwFloat2Float(ox);
  1232     dX:= toX - fromX;
  1231             VGear^.Y:= hwFloat2Float(oy);
  1233     dY:= toY - fromY;
  1232             VGear^.dX:= hwFloat2Float(bulletX);
  1234     length:= sqrt(dX * dX + dY * dY);
  1233             VGear^.dY:= hwFloat2Float(bulletY);
  1235     dX:= dX / length;
  1234 
  1236     dY:= dY / length;
  1235             // reached edge of land. assume infinite beam. Extend it way out past camera
  1237 
  1236             if (hwRound(bulletX) and LAND_WIDTH_MASK <> 0)
  1238     if fadeIn then
  1237             or (hwRound(bulletY) and LAND_HEIGHT_MASK <> 0) then
  1239         begin
  1238                     // only extend if not under water
  1240         steps:= 10;
  1239                     if not CheckCoordInWater(hwRound(bulletX), hwRound(bulletY)) then
  1241         stepLength:= 12;
       
  1242         fromX:= fromX + dX * 45;
       
  1243         fromY:= fromY + dY * 45;
       
  1244         length:= length - 45;
       
  1245         end
       
  1246     else steps:= 1;
       
  1247 
       
  1248     for i:= 0 to steps - 1 do
       
  1249         begin
       
  1250             if i < steps - 1 then
       
  1251                 begin
       
  1252                 toX:= fromX + dX * minD(stepLength, length);
       
  1253                 toY:= fromY + dY * minD(stepLength, length);
       
  1254                 end
       
  1255             else if steps > 1 then
       
  1256                 begin
       
  1257                 toX:= fromX + dX * length;
       
  1258                 toY:= fromY + dY * length;
       
  1259                 end;
       
  1260 
       
  1261             if length > 0 then
       
  1262                 begin
       
  1263                 VGear := AddVisualGear(round(fromX), round(fromY), vgtLineTrail);
       
  1264                 if VGear <> nil then
       
  1265                     begin
       
  1266                     VGear^.X:= fromX;
       
  1267                     VGear^.Y:= fromY;
       
  1268                     VGear^.dX:= toX;
       
  1269                     VGear^.dY:= toY;
       
  1270                     VGear^.Tint:= $FFFFFF00 or ($FF * (i + 1) div (steps));
       
  1271 
       
  1272                     // reached edge of land. assume infinite beam. Extend it way out past camera
       
  1273                     if (round(toX) and LAND_WIDTH_MASK <> 0)
       
  1274                     or (round(toY) and LAND_HEIGHT_MASK <> 0) then
       
  1275                         // only extend if not under water
       
  1276                         if not CheckCoordInWater(round(toX), round(toY)) then
  1240                         begin
  1277                         begin
  1241                         VGear^.dX := VGear^.dX + max(LAND_WIDTH,4096) * (VGear^.dX - VGear^.X);
  1278                             VGear^.dX := VGear^.dX + max(LAND_WIDTH,4096) * (VGear^.dX - VGear^.X);
  1242                         VGear^.dY := VGear^.dY + max(LAND_WIDTH,4096) * (VGear^.dY - VGear^.Y);
  1279                             VGear^.dY := VGear^.dY + max(LAND_WIDTH,4096) * (VGear^.dY - VGear^.Y);
  1243                         end;
  1280                         end;
  1244 
  1281                     VGear^.Timer := 200;
  1245             VGear^.Timer := 200;
  1282                     end;
  1246             end;
  1283                 end;
       
  1284 
       
  1285             if i < steps - 1 then
       
  1286                 begin
       
  1287                 fromX:= toX;
       
  1288                 fromY:= toY;
       
  1289                 length:= length - stepLength;
       
  1290                 end
       
  1291         end;
  1247 end;
  1292 end;
  1248 
  1293 
  1249 procedure LineShoveHelp(Gear: PGear; oX, oY, tX, tY, dX, dY: hwFloat; count: LongWord);
  1294 procedure LineShoveHelp(Gear: PGear; oX, oY, tX, tY, dX, dY: hwFloat; count: LongWord);
  1250 var dmg,power: LongInt;
  1295 var dmg,power: LongInt;
  1251 begin
  1296 begin
  1295         tDx:= Gear^.dX;
  1340         tDx:= Gear^.dX;
  1296         tDy:= Gear^.dY;
  1341         tDy:= Gear^.dY;
  1297         if (Gear^.PortalCounter < 30) and WorldWrap(Gear) then
  1342         if (Gear^.PortalCounter < 30) and WorldWrap(Gear) then
  1298             begin
  1343             begin
  1299             LineShoveHelp(Gear, oX, oY, tX, tY, tDx, tDy, iInit + 2 - i);
  1344             LineShoveHelp(Gear, oX, oY, tX, tY, tDx, tDy, iInit + 2 - i);
  1300             SpawnBulletTrail(Gear, tX, tY);
  1345             SpawnBulletTrail(Gear, tX, tY, Gear^.FlightTime = 0);
       
  1346             Gear^.FlightTime:= 1;
  1301             iInit:= i;
  1347             iInit:= i;
  1302             oX:= Gear^.X;
  1348             oX:= Gear^.X;
  1303             oY:= Gear^.Y;
  1349             oY:= Gear^.Y;
  1304             inc(Gear^.PortalCounter);
  1350             inc(Gear^.PortalCounter);
  1305             Gear^.Elasticity:= Gear^.X;
  1351             Gear^.Elasticity:= Gear^.X;
  1306             Gear^.Friction:= Gear^.Y;
  1352             Gear^.Friction:= Gear^.Y;
  1307             SpawnBulletTrail(Gear, Gear^.X, Gear^.Y);
  1353             SpawnBulletTrail(Gear, Gear^.X, Gear^.Y, false);
  1308             end;
  1354             end;
  1309         x := hwRound(Gear^.X);
  1355         x := hwRound(Gear^.X);
  1310         y := hwRound(Gear^.Y);
  1356         y := hwRound(Gear^.Y);
  1311 
  1357 
  1312         if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) then
  1358         if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) then
  1330 
  1376 
  1331         //Shove static gears to remove the mask and stop damaging the bullet
  1377         //Shove static gears to remove the mask and stop damaging the bullet
  1332         if (not isDigging) and (Gear^.Damage > 5) and (Gear^.Kind <> gtMinigunBullet) then
  1378         if (not isDigging) and (Gear^.Damage > 5) and (Gear^.Kind <> gtMinigunBullet) then
  1333             begin
  1379             begin
  1334             LineShoveHelp(Gear, oX, oY, tX, tY, tDx, tDy, iInit + 2 - i);
  1380             LineShoveHelp(Gear, oX, oY, tX, tY, tDx, tDy, iInit + 2 - i);
  1335             SpawnBulletTrail(Gear, tX, tY);
  1381             SpawnBulletTrail(Gear, tX, tY, Gear^.FlightTime = 0);
       
  1382             Gear^.FlightTime:= 1;
  1336             iInit:= i;
  1383             iInit:= i;
  1337             oX:= Gear^.X;
  1384             oX:= Gear^.X;
  1338             oY:= Gear^.Y;
  1385             oY:= Gear^.Y;
  1339             end;
  1386             end;
  1340 
  1387 
  1391                     begin
  1438                     begin
  1392                     VGear^.Angle := DxDy2Angle(-Gear^.dX, Gear^.dY);
  1439                     VGear^.Angle := DxDy2Angle(-Gear^.dX, Gear^.dY);
  1393                     end;
  1440                     end;
  1394                 end;
  1441                 end;
  1395 
  1442 
  1396             spawnBulletTrail(Gear, Gear^.X, Gear^.Y);
  1443             spawnBulletTrail(Gear, Gear^.X, Gear^.Y, Gear^.FlightTime = 0);
       
  1444             Gear^.FlightTime:= 1;
  1397             if Gear^.Kind = gtMinigunBullet then
  1445             if Gear^.Kind = gtMinigunBullet then
  1398                 ClearHitOrderLeq(Gear^.Tag);
  1446                 ClearHitOrderLeq(Gear^.Tag);
  1399             Gear^.doStep := @doStepShotIdle
  1447             Gear^.doStep := @doStepShotIdle
  1400             end;
  1448             end;
  1401 end;
  1449 end;
  1409 
  1457 
  1410     PlaySound(sndGun);
  1458     PlaySound(sndGun);
  1411     // add 2 initial steps to avoid problem with ammoshove related to calculation of radius + 1 radius as gear widths, and also just plain old weird angles
  1459     // add 2 initial steps to avoid problem with ammoshove related to calculation of radius + 1 radius as gear widths, and also just plain old weird angles
  1412     Gear^.X := Gear^.X + Gear^.dX * 2;
  1460     Gear^.X := Gear^.X + Gear^.dX * 2;
  1413     Gear^.Y := Gear^.Y + Gear^.dY * 2;
  1461     Gear^.Y := Gear^.Y + Gear^.dY * 2;
       
  1462     Gear^.FlightTime := 0;
  1414     Gear^.doStep := @doStepBulletWork
  1463     Gear^.doStep := @doStepBulletWork
  1415 end;
  1464 end;
  1416 
  1465 
  1417 procedure doStepSniperRifleShot(Gear: PGear);
  1466 procedure doStepSniperRifleShot(Gear: PGear);
  1418 var HHGear: PGear;
  1467 var HHGear: PGear;
  1450         Gear^.dY := -AngleCos(HHGear^.Angle) * _0_5;
  1499         Gear^.dY := -AngleCos(HHGear^.Angle) * _0_5;
  1451         PlaySound(sndGun);
  1500         PlaySound(sndGun);
  1452         // add 2 initial steps to avoid problem with ammoshove related to calculation of radius + 1 radius as gear widths, and also just weird angles
  1501         // add 2 initial steps to avoid problem with ammoshove related to calculation of radius + 1 radius as gear widths, and also just weird angles
  1453         Gear^.X := Gear^.X + Gear^.dX * 2;
  1502         Gear^.X := Gear^.X + Gear^.dX * 2;
  1454         Gear^.Y := Gear^.Y + Gear^.dY * 2;
  1503         Gear^.Y := Gear^.Y + Gear^.dY * 2;
       
  1504         Gear^.FlightTime := 0;
  1455         Gear^.doStep := @doStepBulletWork;
  1505         Gear^.doStep := @doStepBulletWork;
  1456         end
  1506         end
  1457     else
  1507     else
  1458         if (GameTicks mod 32) = 0 then
  1508         if (GameTicks mod 32) = 0 then
  1459             if (GameTicks mod 4096) < 2048 then
  1509             if (GameTicks mod 4096) < 2048 then
  4542             end;
  4592             end;
  4543 
  4593 
  4544         if (iterator^.Kind in [gtDEagleShot, gtSniperRifleShot, gtMinigunBullet]) then
  4594         if (iterator^.Kind in [gtDEagleShot, gtSniperRifleShot, gtMinigunBullet]) then
  4545             begin
  4595             begin
  4546             // draw bullet trail
  4596             // draw bullet trail
  4547             spawnBulletTrail(iterator, iterator^.X, iterator^.Y);
  4597             spawnBulletTrail(iterator, iterator^.X, iterator^.Y, iterator^.FlightTime = 0);
       
  4598             iterator^.FlightTime := 1;
  4548             // the bullet can now hurt the hog that fired it
  4599             // the bullet can now hurt the hog that fired it
  4549             iterator^.Data:= nil;
  4600             iterator^.Data:= nil;
  4550             end;
  4601             end;
  4551 
  4602 
  4552         // calc gear offset in portal vector direction
  4603         // calc gear offset in portal vector direction
  6700         Gear^.Data:= Pointer(Gear^.Hedgehog^.Gear);
  6751         Gear^.Data:= Pointer(Gear^.Hedgehog^.Gear);
  6701 
  6752 
  6702     PlaySound(sndGun);
  6753     PlaySound(sndGun);
  6703     Gear^.X := Gear^.X + Gear^.dX * 2;
  6754     Gear^.X := Gear^.X + Gear^.dX * 2;
  6704     Gear^.Y := Gear^.Y + Gear^.dY * 2;
  6755     Gear^.Y := Gear^.Y + Gear^.dY * 2;
       
  6756     Gear^.FlightTime := 0;
  6705     Gear^.doStep := @doStepBulletWork
  6757     Gear^.doStep := @doStepBulletWork
  6706 end;
  6758 end;
  6707 
  6759 
  6708 (*
  6760 (*
  6709  This didn't end up getting used, but, who knows, might be reasonable for javellin or something
  6761  This didn't end up getting used, but, who knows, might be reasonable for javellin or something