//
 // Initial state
 //
 void SquadAttack::StateInit()
 {
   // Attack that target already
   for (SquadObj::UnitList::Iterator i(&subject->GetList()); *i; ++i)
   {
     if (UnitObj *u = (*i)->GetPointer())
     {
       // If the unit can damage the target then make it attack
       if 
       (
         !u->ForceAttacking(target) && u->CanDamageNow(target) && 
         u->FlushTasks(Tasks::UnitAttack::GetConfigBlockingPriority())
       )
       {
         Task *task = new UnitAttack(u, target);
         u->PrependTask(task, GetFlags());
         (*i)->task = task->GetTaskId();
         (*i)->completed = FALSE;
       }
       else 
       {
         (*i)->task = 0;
         (*i)->completed = TRUE;
       }
     }
   }
   NextState(0xA8FEF90A); // "Attack"
 }
Exemple #2
0
  //
  // Save
  //
  // Save a task
  //
  void SaveTask(FScope *fScope, const char *name, Task &task)
  {
    // Write the name given
    fScope = fScope->AddFunction(name);

    // Add the task configuration (type)
    fScope->AddArgString(task.GetName());

    // Add the task id
    fScope->AddArgInteger(task.GetTaskId());

    // Let the task do the rest
    task.Save(fScope);
  }
  //
  // StateInit
  //
  void SquadBoard::StateInit()
  {
    // Get each of the units in the squad to board transports
    SquadObj::UnitList::Iterator u(&subject->GetList());

    // We could enhance this to use units which are closest to transports etc.

    // Clear the squad's completed flags
    for (!u; *u; u++)
    {
      (*u)->completed = FALSE;
      (*u)->task = 0;
    }

    // Reset squad iterator
    !u;

    for (TransportObjList::Iterator t(&transports); *t; t++)
    {
      if ((*t)->Alive())
      {
        TransportObj *transport = **t;
        U32 slots = transport->TransportType()->GetSpaces();
        U32 added = 0;

        while (slots--)
        {
          UnitObjPtr *unitPtr = *u;

          if (unitPtr)
          {
            ASSERT(unitPtr->Alive())
            UnitObj *unit = *unitPtr;

            if (unit->CanEverMove())
            {
              // Tell the unit to board
              unit->FlushTasks(Tasks::UnitBoard::GetConfigBlockingPriority());

              Task *task;

              // Is this a telepad
              if (TaskCtrl::PromoteIdle<Tasks::TransportPad>(transport))
              {
                unit->PrependTask(task = new Tasks::UnitMove(unit, transport), GetFlags());
              }
              else
              {
                unit->PrependTask(task = new Tasks::UnitBoard(unit, transport), GetFlags());
              }

              (*u)->task = task->GetTaskId();

              added++;
            }
            else
            {
              // This unit can't move so complete it
              (*u)->completed = TRUE;
            }
          }
          else
          {
            break;
          }

          // Increment iterator
          u++;
        }

        if (!added)
        {
          // No units were added
          break;
        }
      }
    }

    // Complete those units which missed out
    for (; *u; u++)
    {
      (*u)->completed = TRUE;
    }

    NextState(0x09E5F977); // "Boarding"
  }