/**
 * Get the clusters
 * @return both merged and unique clusters in a single map.
 */
ClusterRegister::MapCluster ClusterRegister::clusters() const {
  MapCluster temp;
  temp.insert(m_Impl->m_unique.begin(), m_Impl->m_unique.end());
  auto mergedClusters = m_Impl->makeCompositeClusters();
  for (const auto &merged : mergedClusters) {
    temp.emplace(merged->getLabel(), merged);
  }
  return temp;
}
/**
 * Get the clusters. Also set the elements to the uniform minimum of each
 * cluster.
 * @param elements
 * @return: Map of merged clusters.
 */
ClusterRegister::MapCluster
ClusterRegister::clusters(std::vector<DisjointElement> &elements) const {
  MapCluster temp;
  temp.insert(m_Impl->m_unique.begin(), m_Impl->m_unique.end());
  auto mergedClusters = m_Impl->makeCompositeClusters();
  for (auto &merged : mergedClusters) {
    merged->toUniformMinimum(elements);
    temp.emplace(merged->getLabel(), merged);
  }
  return temp;
}
Beispiel #3
0
 /**
  * Get the clusters
  * @return both merged and unique clusters in a single map.
  */
 ClusterRegister::MapCluster ClusterRegister::clusters() const
 {
   MapCluster temp;
   temp.insert(m_Impl->m_unique.begin(), m_Impl->m_unique.end());
   auto mergedClusters = m_Impl->makeCompositeClusters();
   for(auto i = mergedClusters.begin(); i != mergedClusters.end(); ++i)
   {
     const auto&  merged = *i;
     temp.insert(std::make_pair( merged->getLabel(), merged));
   }
   return temp;
 }
Beispiel #4
0
 /**
  * Get the clusters. Also set the elements to the uniform minimum of each cluster.
  * @param elements
  * @return: Map of merged clusters.
  */
 ClusterRegister::MapCluster ClusterRegister::clusters(std::vector<DisjointElement>& elements) const
 {
   MapCluster temp;
   temp.insert(m_Impl->m_unique.begin(), m_Impl->m_unique.end());
   auto mergedClusters = m_Impl->makeCompositeClusters();
   for(auto i = mergedClusters.begin(); i != mergedClusters.end(); ++i)
   {
     const auto&  merged = *i;
     merged->toUniformMinimum(elements);
     temp.insert(std::make_pair( merged->getLabel(), merged));
   }
   return temp;
 }
  //
  // Process
  //
  // Process the orderer
  //
  void Base::Process()
  {
    if (newState)
    {
      // Clear new state flag
      newState = FALSE;

      // Enter the new state
      currentState->Enter();
    }
    else
    {
      currentState->Process();
    }

    // Has the list of constructors/units changed ?
    if (processTokens)
    {
      processTokens = FALSE;

      units.PurgeDead();
      constructorsIdle.PurgeDead();
      constructorsWorking.PurgeDead();

      // Process all of the tokens waiting for constructors in the system
      NBinTree<Token>::Iterator w(&tokensWaiting);
      while (Token *token = w++)
      {
        token->CheckConstructor(units, constructorsIdle);
      }
    }

    // Are we auto disrupting ?
    if (autoDisrupt != -1)
    {
      // Has sufficient cycles elapsed since the last time we sorted the disruptors ?
      if (GameTime::SimCycle() - disruptorCycle > 300)
      {
        // Save the cycle we processed
        disruptorCycle = GameTime::SimCycle();

        // Check to see if the index has gone out of range
        if (disruptorIndex > disruptors.GetCount())
        {
          disruptors.PurgeDead();
          disruptorIndex = 0;
        }

        // Get the list node
        UnitObjListNode *node = disruptors[disruptorIndex];

        if (node)
        {
          // Get the unit list
          UnitObj *unit = node->GetPointer();

          // If it was alive then find the most undisrupted spot and send that unit there
          if (unit)
          {
            // Iterate the map, find the cluster with the most defense and the least disruption
            MapCluster *mapCluster = WorldCtrl::GetCluster(0, 0);
            MapCluster *winningCluster = NULL;

            U32 team = GetObject().GetTeam()->GetId();
            Point<U32> cluster;
            U32 minDisruption = U32_MAX;
            U32 maxDefense = 0;

            for (cluster.z = 0; cluster.z < WorldCtrl::ClusterMapZ(); cluster.z++)
            {
              for (cluster.x = 0; cluster.x < WorldCtrl::ClusterMapX(); cluster.x++)
              {
                U32 defense = mapCluster->ai.GetDefense(team, autoDisrupt);

                if (defense)
                {
                  U32 disruption = mapCluster->ai.GetDisruption();

                  if (disruption < minDisruption)
                  {
                    minDisruption = disruption;
                    maxDefense = defense;
                    winningCluster = mapCluster;
                  }
                  else if (disruption == minDisruption && defense > maxDefense)
                  {
                    maxDefense = defense;
                    winningCluster = mapCluster;
                  }
                }

                mapCluster++;
              }
            }

            if (winningCluster)
            {
              Point<F32> point = winningCluster->GetMidPoint();
              Vector location(point.x, Terrain::FindFloor(point.x, point.z), point.z);

              // Move this disruptor to the middle of this cluster
              Orders::Game::ClearSelected::Generate(GetObject());
              Orders::Game::AddSelected::Generate(GetObject(), unit);
              Orders::Game::Move::Generate(GetObject(), location, FALSE, Orders::FLUSH);
            }
          }

          disruptorIndex++;
        }
      }
    }
  }
Beispiel #6
0
int GameInfo::Unserialize(LArchive &a)
{
  int i, n;
  // treat all enums as ints
  a << demoversion;
  a << n; mode = gamemode_t(n);
  a << n; state = gamestate_t(n);
  a << n; skill = skill_t(n);

  // flags
  a << netgame << multiplayer << modified << paused << inventory;

  a << maxteams;
  a << maxplayers;

  if (!a.Marker(MARK_GROUP))
    return -1;

  // mapinfo (and maps)
  a << n;
  for (i = 0; i < n; i++)
    {
      MapInfo *m = new MapInfo;
      if (m->Unserialize(a))
	return -2;
      mapinfo[m->mapnumber] = m;
    }

  if (!a.Marker(MARK_GROUP))
    return -1;

  // clustermap
  a << n;
  for (i = 0; i < n; i++)
    {
      MapCluster *c = new MapCluster;
      if (c->Unserialize(a))
	return -3;
      clustermap[c->number] = c;
    }

  a << n;
  currentcluster = clustermap[n];

  if (!a.Marker(MARK_GROUP))
    return -1;

  // episodes
  a << n;
  episodes.resize(n);
  for (i = 0; i < n; i++)
    {
      episodes[i] = new Episode;
      if (episodes[i]->Unserialize(a))
	return -666;
    }

  if (!a.Marker(MARK_GROUP))
    return -1;

  // teams
  a << n;
  teams.resize(n);
  for (i = 0; i < n; i++)
    {
      teams[i] = new TeamInfo;
      if (teams[i]->Unserialize(a))
	return -4;
    }

  if (!a.Marker(MARK_GROUP))
    return -1;

  // players 
  a << n;
  for (i = 0; i < n; i++)
    {
      PlayerInfo *p = new PlayerInfo;
      if (p->Unserialize(a))
	return -5;
      Players[p->number] = p;
    }

  if (!a.Marker(MARK_GROUP))
    return -1;

  // global script data
  a.Read((byte *)ACS_world_vars, sizeof(ACS_world_vars));

  if (!a.Marker(MARK_GROUP))
    return -1;

  // client stuff
  a << n;
  for (i = 0; i < n; i++)
    {
      int num;
      a << num;
      if (num == -1)
	LocalPlayers[i].info = NULL;
      else
	LocalPlayers[i].info = FindPlayer(num);
    }

  if (!a.Marker(MARK_GROUP))
    return -1;
  // misc shit

  a << n;
  P_SetRandIndex(n);

  string mus;
  a << mus;
  S.StartMusic(mus.c_str(), true);

  return 0;
}