Exemplo n.º 1
0
    //
    // Execute
    //
    U32 Turn::Execute(const U8 *data, Player &player)
    {
      const Data *d = (Data *) data;

      // Send the move order to all of the selected objects
      for (UnitObjList::Iterator i(&player.GetSelectedList()); *i; i++)
      {
        UnitObj *unit = **i;

        // Calculate desired front vector
        Vector v(d->x - unit->Position().x, 0, d->z - unit->Position().z);
        v.Normalize();

        // Can the unit move
        if (unit->CanEverMove())
        {
          if (!unit->GetDriver()->IsBoarded())
          {
            // Convert the given task Id into a move type
            Tasks::UnitMove *task = new Tasks::UnitMove(unit);
            task->SetDir(v);
            IssueTask(d->mod, unit, task, player);
          }
        }
      }

      return (sizeof (Data));
    }
Exemplo n.º 2
0
  //
  // Initial state
  //
  void MapDeath::StateInit()
  {
    // Stop the objects driver
    UnitObj *unitObj = Promote::Object<UnitObjType, UnitObj>(subject);

    if (unitObj)
    {
      if (unitObj->GetWeapon())
      {
        unitObj->GetWeapon()->HaltFire();
      }

      if (unitObj->CanEverMove())
      {
        unitObj->GetDriver()->Stop(Movement::Driver::STOP_DYING);
      }
    }

    // Play the death animation
    subject->SetAnimation(0xF40D135F); // "Death"

    NextState(0x382D3C63); // "Dead"
  }
    //
    // Undo
    //
    // Undo operation
    //
    void Objects::Undo()
    {
      // Process each object
      for (NList<Data>::Iterator i(&dataList); *i; i++)
      {
        Data *d = *i;

        switch (op)
        {
          // Delete objects that were created
          case OP_CREATE:
            if (d->object.Alive())
            {
              GameObjCtrl::MarkForDeletion(d->object);
            }
            break;

          // Create objects that were deleted
          case OP_DELETE:
          {
            MapObj *m = MapObjCtrl::ObjectNewOnMap(d->type, d->matrix, 0, d->zipped);

            // Restore zipping
            if (d->zipped)
            {
              m->ToggleFootPrint(TRUE);
            }
  
            // Is this a unit
            UnitObj *u = Promote::Object<UnitObjType, UnitObj>(m);

            // Restore correct team
            if (u && d->team)
            {
              u->SetTeam(d->team);
            }

            // Save the old id
            U32 oldId = d->object.DirectId();

            // Now replace all references to the old object with the new object
            for (NList<Base>::Iterator items(&GetHistoryList()); *items; items++)
            {
              Objects *item = Promote<Objects>(*items);

              if (item)
              {
                for (NList<Data>::Iterator data(&item->dataList); *data; data++)
                {
                  if ((*data)->object.DirectId() == oldId)
                  {
                    (*data)->object = m;
                  }
                }
              }
            }

            break;
          }

          // Move objects back to original location
          case OP_MOVE:
            if (d->object.Alive())
            {
              d->object->SetSimCurrent(d->matrix);

              // Toggle claiming if necessary
              UnitObj *unitObj = Promote::Object<UnitObjType, UnitObj>(d->object);

              if (unitObj && unitObj->CanEverMove())
              {
                unitObj->GetDriver()->RemoveFromMapHook();
                unitObj->GetDriver()->AddToMapHook();
              }
            }
            break;

          // Restore zipped state
          case OP_ZIP:
            if (d->object.Alive())
            {
              d->object->ToggleFootPrint(d->zipped);
            }
            break;
        }
      }
    }
Exemplo n.º 4
0
  //
  // 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"
  }