コード例 #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));
    }
コード例 #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"
  }
コード例 #3
0
    //
    // 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;
        }
      }
    }