home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / control / server / weapons / weapon.cs < prev   
Encoding:
Text File  |  2006-09-24  |  2.7 KB  |  79 lines

  1. //============================================================================
  2. // control/server/weapons/weapon.cs
  3. // Copyright (c) 2003, 2006  Kenneth C. Finney2003, 2006 by Kenneth
  4. // Portions Copyright (c) 2001 GarageGames.com
  5. // Portions Copyright (c) 2001 by Sierra Online, Inc.
  6. //============================================================================
  7. $WeaponSlot = 0;
  8. function Weapon::OnUse(%data,%obj)
  9. {
  10.    if (%obj.GetMountedImage($WeaponSlot) != %data.image.GetId())
  11.    {
  12.       %obj.mountImage(%data.image, $WeaponSlot);
  13.       if (%obj.client)
  14.          MessageClient(%obj.client, 'MsgWeaponUsed', '\c0Weapon selected');
  15.    }
  16. }
  17. function Weapon::OnPickup(%this, %obj, %shape, %amount)
  18. {
  19.    if (Parent::OnPickup(%this, %obj, %shape, %amount))
  20.    {
  21.       if ( (%shape.GetClassName() $= "Player" ||
  22.             %shape.GetClassName() $= "AIPlayer"  )  &&
  23.             %shape.GetMountedImage($WeaponSlot) == 0)
  24.       {
  25.          %shape.Use(%this);
  26.       }
  27.    }
  28. }
  29. function Weapon::OnInventory(%this,%obj,%amount)
  30. {
  31.    if (!%amount && (%slot = %obj.GetMountSlot(%this.image)) != -1)
  32.       %obj.UnmountImage(%slot);
  33. }
  34. function WeaponImage::OnMount(%this,%obj,%slot)
  35. {
  36.    if (%obj.GetInventory(%this.ammo))
  37.       %obj.SetImageAmmo(%slot,true);
  38. }
  39. function Ammo::OnPickup(%this, %obj, %shape, %amount)
  40. {
  41.    if (Parent::OnPickup(%this, %obj, %shape, %amount))
  42.    {
  43.  
  44.    }
  45. }
  46. function Ammo::OnInventory(%this,%obj,%amount)
  47. {
  48.    for (%i = 0; %i < 8; %i++)
  49.    {
  50.       if ((%image = %obj.GetMountedImage(%i)) > 0)
  51.          if (IsObject(%image.ammo) && %image.ammo.GetId() == %this.GetId())
  52.             %obj.SetImageAmmo(%i,%amount != 0);
  53.    }
  54. }
  55. function RadiusDamage(%sourceObject, %position, %radius, %damage, %damageType, %impulse)
  56. {
  57.    InitContainerRadiusSearch(%position, %radius, $TypeMasks::ShapeBaseObjectType);
  58.  
  59.    %halfRadius = %radius / 2;
  60.    while ((%targetObject = ContainerSearchNext()) != 0) {
  61.       %coverage = CalcExplosionCoverage(%position, %targetObject,
  62.          $TypeMasks::InteriorObjectType |  $TypeMasks::TerrainObjectType |
  63.          $TypeMasks::ForceFieldObjectType | $TypeMasks::VehicleObjectType);
  64.       if (%coverage == 0)
  65.          continue;
  66.       %dist = ContainerSearchCurrRadiusDist();
  67.       %distScale = (%dist < %halfRadius)? 1.0:
  68.          1.0 - ((%dist - %halfRadius) / %halfRadius);
  69.       %targetObject.Damage(%sourceObject, %position,
  70.          %damage * %coverage * %distScale, %damageType);
  71.       if (%impulse) {
  72.          %impulseVec = VectorSub(%targetObject.GetWorldBoxCenter(), %position);
  73.          %impulseVec = VectorNormalize(%impulseVec);
  74.          %impulseVec = VectorScale(%impulseVec, %impulse * %distScale);
  75.          %targetObject.ApplyImpulse(%position, %impulseVec);
  76.       }
  77.    }
  78. }
  79.