Exemplo n.º 1
0
  //
  // Assign constructors to this base
  //
  void Base::AssignConstructors(const char *tagName)
  {
    processTokens = TRUE;

    // Was a tag specified ?
    if (tagName)
    {
      // Resolve the tag
      TagObj *tag = TagObj::FindTag(tagName);

      if (tag)
      {
        // Iterate the units in the tag
        for (MapObjList::Iterator i(&tag->list); *i; i++)
        {
          // Is it alive
          if (!(*i)->Alive())
          {
            continue;
          }

          // Is this a unit ?
          UnitObj *unit = Promote::Object<UnitObjType, UnitObj>(**i);
          if (!unit)
          {
            continue;
          }

          // Is it on our team ?
          if (unit->GetTeam() != GetObject().GetTeam())
          {
            continue;
          }

          // Is it a constructor ?
          if (!unit->HasProperty(0xDCDE71CD)) // "Ability::Construction"
          {
            continue;
          }

//          LOG_AI(("Assigning constructor [%d] '%s' to base '%s'", unit->Id(), unit->UnitType()->GetName(), GetName()))

          // Add this constructor to the list of idle constructors
          constructorsIdle.Append(unit);
        }
      }
      else
      {
        ERR_CONFIG(("Could not find tag '%s' when assign constructors to base '%s'", tagName, GetName()))
      }
    }
    else
    {
      // Iterate all of the units on this team
      for (NList<UnitObj>::Iterator u(&GetObject().GetTeam()->GetUnitObjects()); *u; u++)
    //
    // Data constructor
    //
    Objects::Data::Data(MapObj *o) : object(o)
    {
      type = object->MapType();
      matrix = object->WorldMatrix();
      zipped = object->GetFootInstance() ? TRUE : FALSE;

      UnitObj *unit = Promote::Object<UnitObjType, UnitObj>(object);

      if (unit)
      {
        team = unit->GetTeam();
      }
    }
    //
    // Execute
    //
    U32 SelfDestruct::Execute(const U8 *, Player &player)
    {
      // Tell each object to SelfDestruct
      for (UnitObjList::Iterator i(&player.GetSelectedList()); *i; i++)
      {
        // Get the unit
        UnitObj *unit = **i;

        // Ensure it can self destruct
        if (unit->HasProperty(0x54D4152A) && !unit->UnderConstruction()) // "Ability::SelfDestruct"
        {
          unit->SelfDestruct(TRUE, unit->GetTeam());
        }
      }

      return (sizeof (Data));
    }
Exemplo n.º 4
0
  //
  // Recycle
  //
  // Check timer and refund resources once recycled
  //
  void UnitRecycle::StateRecycle()
  {
    // Apply progress
    progressTotal -= progressMax;

    // Has recycling finished
    if (progressTotal <= 0.0F)
    {
      // Refund the resources
      if (subject->GetTeam() && refund > 0)
      {
        // Calculate the total refund
        U32 totalRefund = U32(subject->UnitType()->GetRecyclePercentage() * refund);

        // Add to the team
        subject->GetTeam()->AddResourceStore(totalRefund);

        // Report the resource type
        subject->GetTeam()->ReportResource(totalRefund, "resource.recycled");

        // Generate a message
        if (Team::GetDisplayTeam() == subject->GetTeam())
        {
          CON_MSG((TRANSLATE(("#game.messages.recyclerefund", 2, subject->GetUpgradedUnit().GetDesc(), totalRefund))));
        }
      }

      // Trigger finish FX
      subject->StartGenericFX(0x2062BAAD, NULL, TRUE); // "Recycle::Finish"

      // Did this building consume its constructor
      if 
      (
        subject->UnitType()->GetConstructorType() && 
        !subject->UnitType()->GetConstructorType()->GetIsFacility() &&
        subject->UnitType()->GetConstructorConsume()
      )
      {
        // Ensure the constructors resources are initialized
        subject->UnitType()->GetConstructorType()->InitializeResources();

        // Create a fresh new constructor
        UnitObj *unit = subject->UnitType()->GetConstructorType()->SpawnClosest
        (
          subject->Position(), subject->GetTeam()
        );

        // If this team is controlled by AI then assign the 
        // constructor to the primary base (if there is one)
        if (unit && unit->GetTeam() && unit->GetTeam()->IsAI())
        {
          Strategic::Object *object = unit->GetTeam()->GetStrategicObject();
          if (object)
          {
            Strategic::Base *base = object->GetBaseManager().GetPrimaryBase();

            if (base)
            {
              base->AddUnit(unit);
              base->AddConstructor(unit);
            }
          }
        }
      }

      // Remove the object
      subject->MarkForDeletion();

      // Remove boarded object
      if (subject->UnitType()->CanBoard() && subject->GetBoardManager()->InUse())
      {
        subject->GetBoardManager()->GetUnitObj()->SelfDestruct();
      }

      // Recycle completed
      Quit();
    }
  }
Exemplo n.º 5
0
//
// Poll
//
// Attempt to trigger this trap
//
Bool TrapObj::Poll()
{
  // Did we find a valid target
  Bool valid = FALSE;

  // Has recharging finished
  if (recharge.Test())
  {
    UnitObj *target;

    // Find an enemy within the configured range
    UnitObjIter::Tactical i
    (
      NULL, UnitObjIter::FilterData(GetTeam(), Relation::ENEMY, Position(), TrapType()->GetDistance())
    );
    
    // Step through each possible target
    while ((target = i.Next()) != NULL)
    {
      // Can this trap trigger on this target
      if (TrapType()->Test(target))
      {
        // Does this trap self destruct
        if (TrapType()->GetSelfDestruct())
        {
          SelfDestruct(TRUE, GetTeam());
          valid = TRUE;
        }

        // Does this trap attach a parasite
        if (TrapType()->GetParasite() && TrapType()->GetParasite()->Infect(target, GetTeam()))
        {
          valid = TRUE;
        }

        // Should we fire a weapon
        if (TrapType()->GetWeaponSpeed() > 0.0F)
        {
          if (GetWeapon())
          {
            Vector pos = Origin();
            pos.y += 20.0f;
            GetWeapon()->SetTarget(Target(pos));
            valid = TRUE;
          }
          else
          {
            LOG_WARN(("Trap %s configured to fire a weapon, but has none!", TypeName()));
          }
        }

        if (valid)
        {
          // Signal team radio that we were triggered
          if (GetTeam())
          {
            // "Trap::Triggered"
            GetTeam()->GetRadio().Trigger(0xA0FF29A5, Radio::Event(this));
          }

          // Signal the target that it has been trapped
          if (target->GetTeam())
          {
            // "Trap::Triggered::Target"
            target->GetTeam()->GetRadio().Trigger(0x3070E869, Radio::Event(target));
          }

          // Start charge time
          recharge.Start(TrapType()->GetChargeTime());
        }

        // Only affect one target for now
        break;
      }
    }
  }

  return (valid);
}