Пример #1
0
  //
  // LoadConfig
  //
  // Load the configured difficulty settings
  //
  static void LoadConfig()
  {
    PTree pTree;
    GameIdent defaultName;

    // Clear any current settings
    ClearSettings();

    // Open the configuration file
    if (pTree.AddFile(configName))
    {
      FScope *gScope = pTree.GetGlobalScope();
      FScope *sScope;

      // Parse each function
      while ((sScope = gScope->NextFunction()) != NULL)
      {
        switch (sScope->NameCrc())
        {
          case 0x12AFF0D8: // "CreateSetting"
            ProcessCreateSetting(sScope);
            break;

          case 0x733C1EB5: // "DefaultSetting"
            defaultName = StdLoad::TypeString(sScope);
            break;
        }
      }

      // Ensure at least one setting is configured
      if (settings.GetCount())
      {
        // Setup the default setting
        if ((defaultSetting = FindSetting(defaultName)) == NULL)
        {
          defaultSetting = settings.GetHead();
        }

        // Set the current from the default
        currentSetting = defaultSetting;
      }
      else
      {
        ERR_CONFIG(("At least one difficulty setting must be supplied in [%s]", configName));
      }
    }
    else
    {
      ERR_CONFIG(("Unable to load difficulty settings configuration [%s]", configName));
    }
  }
  //
  // ExecuteScript
  //
  Script & Script::Manager::ExecuteScript(const GameIdent &script, const char *configName, U32 weighting, U32 priority)
  {
    // Ask config if there's a script
    Config::Generic *config = Config::FindConfig(0x8810AE3C, GameIdent(configName)); // "Script"

    if (config)
    {
      // Check to see if there's already a script with this name running
      if (scripts.Find(script.crc))
      {
        ERR_CONFIG(("Script '%s' is already being executed", script.str))
      }

      FScope *fScope = config->GetFScope();

      // Create new script
      Script *s = new Script(*this, script.str, configName, fScope, weighting, priority);

      FSCOPE_CHECK(fScope)

      // Add script
      scripts.Add(script.crc, s);

      // Return the script
      return (*s);
    }
    else
    {
Пример #3
0
  //
  // TagProximity::PostLoad
  //
  void TagProximity::PostLoad()
  {
    // Call Parent First
    Condition::PostLoad();

    // Resolve source tag
    sourceTag = TagObj::FindTag(sourceTagName.str);
    if (!sourceTag.Alive())
    {
      ERR_CONFIG(("Could not resolve source tag '%s'", sourceTagName.str))
    }

    switch (style)
    {
      case TAG:
        tag->PostLoad();
        break;

      case REGION:
        region->PostLoad();
        break;

      case TYPE:
        type->PostLoad();
        break;

      case PROPERTY:
        property->PostLoad();
        break;
    }
  }
Пример #4
0
 //
 // Tag::PostLoad
 //
 void Tag::PostLoad()
 {
   // Resolve the Tag identifier into a Tag
   tag = TagObj::FindTag(tagName.str);
   if (!tag.Alive())
   {
     ERR_CONFIG(("Tag '%s' could not be resolved", tagName.str))
   }
 }
Пример #5
0
 //
 // Region::PostLoad
 //
 void Region::PostLoad()
 {
   // Resolve the Region Identifier into a Region
   region = RegionObj::FindRegion(regionName.str);
   if (region.Dead())
   {
     ERR_CONFIG(("Region '%s' could not be resolved", regionName.str))
   }
 }
Пример #6
0
  //
  // TractionIndex
  //
  // Get the index for a traction type, creating if not found
  //
  U8 TractionIndex(const char *key)
  {
    ASSERT(initialized);

    U8 index = 0;

    if (!table->GetYIndex(key, index))
    {
      ERR_CONFIG(("Max TRACTION types has been reached on '%s' (%u)", key, table->KeyCountY()));
    }

    return (index);
  }
Пример #7
0
  //
  // SurfaceIndex
  //
  // Get the index for a surface type, creating if not found
  //
  U8 SurfaceIndex(const char *key)
  {
    ASSERT(initialized);

    U8 index = 0;

    if (!table->GetXIndex(key, index))
    {
      ERR_CONFIG(("Max SURFACE types has been reached on '%s' (%u)", key, table->KeyCountX()));
    }

    return (index);
  }
Пример #8
0
 //
 // PostLoad
 //
 void Type::PostLoad()
 {
   // Are they refering to ALL types ?
   if (!Utils::Strcmp(typeName.str, "*"))
   {
     all = TRUE;  
   }
   else
   {
     // Resolve the type name
     if ((type = GameObjCtrl::FindType<MapObjType>(typeName.str)) == NULL)
     {
       ERR_CONFIG(("Type '%s' could not be resolved", typeName.str))
     }
   }
 }
Пример #9
0
  //
  // GotoState
  //
  // Goto the given state
  //
  void Base::GotoState(const GameIdent &state)
  {
//    LOG_AI(("%5.1f Base '%s' Entering State '%s'", GameTime::SimTotalTime(), GetName(), state.str))

    // If there was a previous state, leave it
    if (currentState)
    {
      currentState->Leave();
    }

    // Change to the new state
    currentState = states.Find(state.crc);
    newState = TRUE;

    if (!currentState)
    {
      ERR_CONFIG(("Could not find State '%s' in Base '%s'", state.str, GetName()))
    }
  }
Пример #10
0
  //
  // Activate
  //
  // Activate this control
  //
  Bool TeamList::Activate()
  {
    if (ICWindow::Activate())
    {
      // Find all the important controls
      teamList = IFace::Find<ICListBox>("TeamList", this);
      if (!teamList.Alive())
      {
        ERR_CONFIG(("Could not find 'TeamList' in the TeamList"))
      }

      // Build the list of teams
      BuildList();

      // Activate vars
      ActivateVar(currentTeam);
      ActivateVar(createTeam);
 
      return (TRUE);
    }

    return (FALSE);
  }
Пример #11
0
//
// TBuf::DefaultError
//
// Fatal error handler
//
void FASTCALL TBuf::DefaultError(const char *bufName, U32 x, U32 y, const char *errStr)
{
  // Trigger the error
  ERR_CONFIG(("%s(%d): Error! (col %d) %s", bufName, y, x, errStr));
}
//
// Execute
//
void Spawn::Execute()
{
    Object &object = script.GetObject();

    // Find a named formation
    ::Formation::Slots *formation = ::Formation::Find(formationName.GetCrc());
    if (!formation)
    {
        ERR_CONFIG(("Could not find formation '%s'", formationName.GetStr()))
    }

    Config::RecruitType *config = Config::FindRecruitType(configName.GetCrc());
    if (!config)
    {
        ERR_CONFIG(("Could not find RecruitType '%s'", configName.GetStr()))
    }

    List<::Formation::Slot>::Iterator slot(&formation->slots);

    F32 angle = (90.0f - direction) * DEG2RAD;

    for (Config::RecruitType::TypeList::Iterator t(&config->GetTypes()); *t; t++)
    {
        if ((*t)->Alive())
        {
            UnitObjType *type = **t;

            for (U32 i = 0; i < (*t)->amount; i++)
            {
                // Is there a slot for this unit ?
                if (*slot)
                {
                    // Calculate the absolute direction to the slot
                    F32 dir = angle + (*slot)->direction;
                    VectorDir::FixU(dir);

                    // Calculate the orientation
                    F32 orient = angle + (*slot)->orientation;
                    VectorDir::FixU(orient);

                    // Determine the slot offset
                    Vector offset;
                    offset.x = (F32) cos(dir);
                    offset.y = 0.0f;
                    offset.z = (F32) sin(dir);
                    offset *= (*slot)->distance;
                    offset += location->GetVector();
                    offset.y = TerrainData::FindFloor(offset.x, offset.z);

                    // Order the creation of the unit
                    Orders::Squad::Spawn::Generate(object, script.GetSquad()->Id(), type->GetNameCrc(), offset, orient);

                    // Increment the slot
                    slot++;
                }
                else
                {
                    // Ran out of slots
                    LOG_WARN(("Ran out of slots in formation '%s' whilst spawning in units", formationName.GetStr()))
                }
            }
        }
    }
Пример #13
0
//
// ProjectileObjType::ProjectileObjType
//
// Constructor
//
ProjectileObjType::ProjectileObjType(const char *name, FScope *fScope) 
  : MapObjType(name, fScope)
{
  fScope = fScope->GetFunction(SCOPE_CONFIG);

  // Does the projectile explode on impact ?
  impact = StdLoad::TypeU32(fScope, "Impact", TRUE);

  // Does the projectile have a fuse ?
  fuse = StdLoad::TypeF32(fScope, "Fuse", 0.0f);

  // Set the proximity type
  switch (StdLoad::TypeStringCrc(fScope, "ProximityType", 0x5EB76DCD)) // "Normal"
  {
    case 0x5EB76DCD: // "Normal"
      proximityType = PROXIMITY_NORMAL;
      break;

    case 0xCB8AD298: // "XZ"
      proximityType = PROXIMITY_XZ;
      break;

    case 0x738AADA3: // "Y"
      proximityType = PROXIMITY_Y;
      break;

    default:
      ERR_CONFIG(("%s has an unknown proximity type", GetName()));
  }
  
  // Does the projectile have a proximity fuse ?
  proximity = StdLoad::TypeF32(fScope, "Proximity", 0.0f);
  proximity2 = proximity * proximity;

  // If the projectile has a fuse then it does not explode on contact
  if (fuse != 0.0)
  {
    impact = FALSE;
  }
  else
  // Make sure the projectile either explodes on impact or it has a fuse
  if (!impact)
  {
    fScope->ScopeError("Projectile does not have a fuse and does not explode on impact");
  }

  // Get the missile thrust
  GameIdent modelName = StdLoad::TypeString(fScope, "ProjectileModel", "StraightTrajectory");
  model = modelName.crc;

  switch (model)
  {
    case ProjectileModel::StraightTrajectory:
    {
      // Set physics proc
      projectilePhysicsProc = BulletPhysics;

      // Load specific settings

      break;
    }

    case ProjectileModel::ArcTrajectory:
    {
      // Set physics proc
      projectilePhysicsProc = GrenadePhysics;

      // Load specific settings

      break;
    }

    case ProjectileModel::GuidedTrajectory:
    {
      // Set physics proc
      projectilePhysicsProc = MissilePhysics;

      // Load specific settings
      missile.topSpeed = StdLoad::TypeF32(fScope, "TopSpeed", 160.0F) * PhysicsConst::KMH2MPS;

      // Acceleration time (in seconds)
      F32 accelTime = StdLoad::TypeF32(fScope, "AccelerationTime", 1.0F, Range<F32>::positive);

      // Calculate acceleration rate
      if (accelTime < 1e-4F)
      {
        // Accelerate to top speed in 1 game cycle
        missile.acceleration = missile.topSpeed / GameTime::INTERVAL;
      }
      else
      {
        missile.acceleration = missile.topSpeed / accelTime;
      }

      // Turn rate
      missile.homingRate = StdLoad::TypeF32(fScope, "HomingRate", 0.0F, Range<F32>::positive) * DEG2RAD;

      // Cos of turn rate
      missile.cosHomingRate = F32(cos(missile.homingRate * GameTime::INTERVAL));

      // Waver turn
      missile.waverTurn = StdLoad::TypeF32(fScope, "WaverTurn", 0.0F) * DEG2RAD;

      // Waver rate
      missile.waverRate = StdLoad::TypeF32(fScope, "WaverRate", 180.0F, Range<F32>::positive) * DEG2RAD;

      break;
    }

    default:
      fScope->ScopeError("Unknown projectile model '%s'", modelName.str);
  }

  // Get optional explosion
  StdLoad::TypeReaperObjType(fScope, "Explosion", explosionType);

  // Projectile flag
  isProjectile = TRUE;
}