コード例 #1
0
ファイル: ActorFactory.cpp プロジェクト: ronw23/ia-osx
Actor* ActorFactory::spawnRandomActor(const coord& pos, const int SPAWN_LVL_OFFSET) {
  const int DLVL = eng->map->getDungeonLevel();
  vector<ActorId_t> monsterCandidates;
  const unsigned int ACTORS_DEFINED = static_cast<unsigned int>(endOfActorIds);
  for(unsigned int i = 1; i < ACTORS_DEFINED; i++) {
    const ActorDefinition& def = eng->actorData->actorDefinitions[i];

    const bool IS_LVL_OK = DLVL + SPAWN_LVL_OFFSET >= def.spawnMinLevel && DLVL <= def.spawnMaxLevel;

    const bool IS_ALLOWED_TO_SPAWN = def.isAutoSpawnAllowed && def.nrLeftAllowedToSpawn != 0;

    const bool IS_FEATURE_PASSABLE = eng->map->featuresStatic[pos.x][pos.y]->isMoveTypePassable(def.moveType);

    bool IS_NO_ACTOR_AT_POS = eng->mapTests->getActorAtPos(pos) == NULL;

    if(IS_LVL_OK && IS_ALLOWED_TO_SPAWN && IS_FEATURE_PASSABLE && IS_NO_ACTOR_AT_POS) {
      monsterCandidates.push_back(static_cast<ActorId_t>(i));
    }
  }

  if(monsterCandidates.empty() == false) {
    const int ELEMENT = eng->dice.getInRange(0, monsterCandidates.size() - 1);
    const ActorId_t monsterType = monsterCandidates.at(ELEMENT);
    return spawnActor(monsterType, pos);
  }

  return NULL;
}
コード例 #2
0
ファイル: wall_target.cpp プロジェクト: abannerth/Reaping2
void WallTarget::PutTarget( glm::vec2 position )
{
    std::auto_ptr<MapElement> mapElement( MapElementFactory::Get()( AutoId( "spawn_actor" ) ) );
    Opt<SpawnActorMapElement> spawnActor( static_cast<SpawnActorMapElement*>( mapElement.get() ) );
    spawnActor->GetInputNodeId( SpawnActorMapElement::SpawnNodeId() )( 1 );

    AddPositionLoader( position, spawnActor );

    spawnActor->SetActorID( EditorTargetSystem::Get()->GetTarget().GetActorId() );
    mapElement->SetUID( AutoId( "spawn_at_start" ) );
    MapSystem::Get()->GetMapElementList().insert( Opt<MapElement>( mapElement.release() ) );
}