Пример #1
0
  //
  // Trigger a Location Message
  //
  void CDECL TriggerLocationMessage(U32 messageCrc, const Vector &location, U32 params, ...)
  {
    // Lookup the game message
    Location *message = locationMessages.Find(messageCrc);

    // Is there are game message for this trigger ?
    if (message)
    {
      // Save the location of this message
      lastLocationValid = TRUE;
      lastLocation = location;

      va_list args;
      va_start(args, params);
      message->Trigger(location, params, args);
      va_end(args);
    }
  }
Пример #2
0
  //
  // Trigger a Obj Message
  //
  void CDECL TriggerObjMessage(U32 messageCrc, GameObj *obj, const Vector *position, U32 params, ...)
  {
    ASSERT(obj)

    // Lookup the obj message
    Obj *message = objMessages.Find(messageCrc);

    if (message)
    {
      Location *location = NULL;

      // Go through the tags (if any) and see if this object is in any of the tags
      for (BinTree<Location>::Iterator t(&message->tags); *t; t++)
      {
        TagObj *tag = TagObj::FindTag(t.GetKey());

        if (tag && tag->list.Find(obj->Id()))
        {
          location = *t;
          break;
        }
      }

      if (!location)
      {
        // Check to see if we have a message for this type
        location = message->types.Find(obj->GameType()->GetNameCrc());

        if (!location)
        {
          // Check the properties we have to see if this unit has all the properties
          for (List<PropertyLocation>::Iterator p(&message->properties); *p; p++)
          {
            if ((*p)->properties.TestAll(obj->GameType()))
            {
              location = *p;
              break;
            }
          }

          if (!location)
          {
            // Finally, do we have a default
            if ((location = message->defaultLocation) == NULL)
            {
              // We got nought
              return;
            }
          }
        }
      }

      if (position)
      {
        // Save the location of this message
        lastLocationValid = TRUE;
        lastLocation = *position;

        // Trigger the message
        va_list args;
        va_start(args, params);
        location->Trigger(lastLocation, params, args, obj);
        va_end(args);
      }
      else

      // Can we get the location of this object ?
      if (MapObj *mapObj = Promote::Object<MapObjType, MapObj>(obj))
      {
        // Is this map object on the map
        if (mapObj->OnMap())
        {
          // Save the location of this message
          lastLocationValid = TRUE;
          lastLocation = mapObj->Origin();
        }
        else
        {
          // Location is invalid
          lastLocationValid = FALSE;
        }

        va_list args;
        va_start(args, params);
        location->Trigger(lastLocation, params, args, obj);
        va_end(args);
      }
      else
      {
        SquadObj *squadObj = Promote::Object<SquadObjType, SquadObj>(obj);

        if (squadObj)
        {
          if (squadObj->GetLocation(lastLocation))
          {
            lastLocationValid = TRUE;

            va_list args;
            va_start(args, params);
            location->Trigger(lastLocation, params, args, obj);
            va_end(args);
          }
        }
      }
    }
  }