Ejemplo n.º 1
0
//-------- Begin of function Game::main_loop_all --------//
//
// [int] isLoadedGame - whether the game is a loaded game.
//							   (default: 0)
//
void Game::main_loop_all(int isLoadedGame)
{
	// ##### begin Gilbert 10/4 #######//
	// press alt-f4 during game
	if( sys.signal_exit_flag && !vga_front.is_inited() )
		return;
	// ##### end Gilbert 10/4 #######//

	sys.signal_exit_flag = 0;

	while(1)
	{
		if( is_campaign_mode() )
			campaign()->main_loop(isLoadedGame);
		else
			sys.run(isLoadedGame);

		if( sys.signal_exit_flag == 4 )		// 4-this is set after loading a game for exiting the current main_loop() so that it can enter the correct main_loop() (campaign & game) later.
		{
			isLoadedGame = 1;
			sys.signal_exit_flag = 0;
		}
		else
			break;
	}
}
Ejemplo n.º 2
0
void
tamo_campaign( int yy, int mm, int dd, long g, int htmlMode )
{
    /* キャンペーン出力 */
    if ( htmlMode == OFF )
        campaign( g, dd, mm, yy );
}
Ejemplo n.º 3
0
TEST(CampaignTest, testLoad2) {
	SCOPED_TRACE("gamestate2.sqlite");
	SQLitePersister persister(System.getDatabaseDirectory() + "gamestate2.sqlite");
	ASSERT_TRUE(persister.init()) << "Failed to initialize the persister";
	Campaign campaign("tutorial", &persister);
	ASSERT_TRUE(campaign.loadProgress()) << "failed to load the campaign progress";
}
Ejemplo n.º 4
0
TEST(CampaignTest, testSave) {
	SCOPED_TRACE("new.sqlite");
	SQLitePersister persister(System.getDatabaseDirectory() + "new.temp");
	ASSERT_TRUE(persister.init()) << "Failed to initialize the persister";
	Campaign campaign("testsave", &persister);
	campaign.addMap("test1", "test1");
	campaign.addMap("test2", "test2");
	campaign.addMap("test3", "test3");
	campaign.unlock();
	ASSERT_TRUE(campaign.unlockNextMap(false)) << "failed to unlock the next map";
	const int expectedLives = 1;
	campaign.setLives(expectedLives);
	ASSERT_TRUE(campaign.saveProgress()) << "failed to save the campaign";
	campaign.setLives(100);
	ASSERT_TRUE(campaign.unlockNextMap(false)) << "failed to unlock the next map";
	ASSERT_EQ(std::string("test3"), campaign.getNextMap()) << "Failed to unlock the next map";
	ASSERT_TRUE(campaign.loadProgress()) << "failed to load the campaign progress";
	ASSERT_EQ(std::string("test2"), campaign.getNextMap()) << "Failed to load the campaign map progress";
	ASSERT_EQ(expectedLives, (int )campaign.getLives()) << "Failed to save/load lives";
}
Ejemplo n.º 5
0
TEST(CampaignTest, testReset) {
	SCOPED_TRACE("reset.temp");
	SQLitePersister persister(System.getDatabaseDirectory() + "reset.temp");
	ASSERT_TRUE(persister.init()) << "Failed to initialize the persister";
	Campaign campaign("testsave", &persister);
	campaign.addMap("test1", "test1");
	campaign.addMap("test2", "test2");
	campaign.addMap("test3", "test3");
	campaign.unlock();
	ASSERT_TRUE(campaign.unlockNextMap(true)) << "failed to unlock the next map";
	ASSERT_EQ(std::string("test2"), campaign.getNextMap()) << "Failed to load the campaign map progress";
	const int expectedLives = 3;
	ASSERT_TRUE(campaign.reset(true)) << "failed to reset the campaign";
	ASSERT_TRUE(campaign.isUnlocked()) << "failed to reset the locked state of the campaign";
	ASSERT_TRUE(campaign.saveProgress()) << "failed to save the campaign";
	ASSERT_TRUE(campaign.loadProgress()) << "failed to load the campaign progress";
	ASSERT_EQ(std::string("test1"), campaign.getNextMap()) << "Failed to load the campaign map progress";
	ASSERT_EQ(expectedLives, (int )campaign.getLives()) << "Failed to reset lives";
	ASSERT_TRUE(campaign.reset(false)) << "failed to reset the campaign";
	ASSERT_TRUE(!campaign.isUnlocked()) << "failed to reset the locked state of the campaign";
	ASSERT_TRUE(campaign.loadProgress()) << "failed to load the campaign progress";
	ASSERT_EQ(std::string(""), campaign.getNextMap()) << "Failed to load the campaign map progress";
	ASSERT_EQ(expectedLives, (int )campaign.getLives()) << "Failed to reset lives";
}
Ejemplo n.º 6
0
optional<CampaignSetup> CampaignBuilder::prepareCampaign(function<optional<RetiredGames>(CampaignType)> genRetired,
    CampaignType type, string worldName) {
  Vec2 size(17, 9);
  int numBlocked = 0.6 * size.x * size.y;
  Table<Campaign::SiteInfo> terrain = getTerrain(random, size, numBlocked);
  auto retired = genRetired(type);
  View::CampaignMenuState menuState { true, false};
  setCountLimits(options);
  const auto playerRole = getPlayerRole();
  while (1) {
    Campaign campaign(terrain, type, playerRole, worldName);
    if (auto pos = considerStaticPlayerPos(campaign)) {
      campaign.clearSite(*pos);
      setPlayerPos(campaign, *pos, avatarInfo.playerCreature->getMaxViewIdUpgrade());
    }
    placeVillains(campaign, getVillainCounts(type, options), retired, avatarInfo.tribeAlignment);
    while (1) {
      bool updateMap = false;
      campaign.influenceSize = options->getIntValue(OptionId::INFLUENCE_SIZE);
      campaign.refreshInfluencePos();
      CampaignAction action = autoConfirm(type) ? CampaignActionId::CONFIRM
          : view->prepareCampaign({
              campaign,
              (retired && type == CampaignType::FREE_PLAY) ? optional<RetiredGames&>(*retired) : none,
              avatarInfo.playerCreature.get(),
              getPrimaryOptions(),
              getSecondaryOptions(type),
              getSiteChoiceTitle(type),
              getIntroText(),
              getAvailableTypes().transform([](CampaignType t) -> View::CampaignOptions::CampaignTypeInfo {
                  return {t, getCampaignTypeDescription(t)};}),
              getMenuWarning(type)
              }, options, menuState);
      switch (action.getId()) {
        case CampaignActionId::REROLL_MAP:
          terrain = getTerrain(random, size, numBlocked);
          updateMap = true;
          break;
        case CampaignActionId::UPDATE_MAP:
          updateMap = true;
          break;
        case CampaignActionId::CHANGE_TYPE:
          type = action.get<CampaignType>();
          retired = genRetired(type);
          updateMap = true;
          break;
        case CampaignActionId::UPDATE_OPTION:
          switch (action.get<OptionId>()) {
            case OptionId::PLAYER_NAME:
            case OptionId::GENERATE_MANA:
            case OptionId::INFLUENCE_SIZE:
              break;
            default:
              updateMap = true;
              break;
          }
          break;
        case CampaignActionId::CANCEL:
          return none;
        case CampaignActionId::CHOOSE_SITE:
          if (!considerStaticPlayerPos(campaign))
            setPlayerPos(campaign, action.get<Vec2>(), avatarInfo.playerCreature->getMaxViewIdUpgrade());
          break;
        case CampaignActionId::CONFIRM:
          if (!retired || retired->getNumActive() > 0 || playerRole != PlayerRole::KEEPER ||
              retired->getAllGames().empty() ||
              view->yesOrNoPrompt("The imps are going to be sad if you don't add any retired dungeons. Continue?")) {
            string name = avatarInfo.playerCreature->getName().firstOrBare();
            string gameIdentifier = name + "_" + campaign.worldName + getNewIdSuffix();
            string gameDisplayName = name + " of " + campaign.worldName;
            return CampaignSetup{campaign, gameIdentifier, gameDisplayName,
                getIntroMessages(type)};
          }
      }
      if (updateMap)
        break;
    }
  }
}
Ejemplo n.º 7
0
optional<Campaign> Campaign::prepareCampaign(View* view, Options* options, RetiredGames&& retired,
    RandomGen& random) {
  Vec2 size(16, 9);
  int numBlocked = 0.6 * size.x * size.y;
  Table<SiteInfo> terrain = getTerrain(random, size, numBlocked);
  string worldName = NameGenerator::get(NameGeneratorId::WORLD)->getNext();
  options->setDefaultString(OptionId::KEEPER_NAME, NameGenerator::get(NameGeneratorId::FIRST)->getNext());
  while (1) {
    //options->setLimits(OptionId::RETIRED_VILLAINS, 0, min<int>(retired.size(), 4)); 
    options->setLimits(OptionId::MAIN_VILLAINS, 0, 9); 
    options->setLimits(OptionId::LESSER_VILLAINS, 0, 8); 
    options->setLimits(OptionId::ALLIES, 0, 6); 
    options->setLimits(OptionId::INFLUENCE_SIZE, 3, 6); 
    int numRetired = min(retired.getNumActive(), options->getIntValue(OptionId::MAIN_VILLAINS));
    int numMain = options->getIntValue(OptionId::MAIN_VILLAINS) - numRetired;
    int numLesser = options->getIntValue(OptionId::LESSER_VILLAINS);
    int numAllies = options->getIntValue(OptionId::ALLIES);
    vector<VillainInfo> mainVillains;
    while (mainVillains.size() < numMain)
      append(mainVillains, random.permutation(getMainVillains()));
    mainVillains.resize(numMain);
    vector<VillainInfo> lesserVillains;
    while (lesserVillains.size() < numLesser)
      append(lesserVillains, random.permutation(getLesserVillains()));
    lesserVillains.resize(numLesser);
    vector<VillainInfo> allies;
    while (allies.size() < numAllies)
      append(allies, random.permutation(getAllies()));
    allies.resize(numAllies);
    Campaign campaign(terrain);
    campaign.worldName = worldName;
    vector<Vec2> freePos;
    for (Vec2 v : Rectangle(size))
      if (campaign.sites[v].canEmbark())
        freePos.push_back(v);
    for (int i : All(mainVillains)) {
      Vec2 pos = random.choose(freePos);
      removeElement(freePos, pos);
      campaign.sites[pos].dweller = mainVillains[i];
    }
    vector<RetiredGames::RetiredGame> activeGames = retired.getActiveGames();
    for (int i : Range(numRetired)) {
      Vec2 pos = random.choose(freePos);
      removeElement(freePos, pos);
      campaign.sites[pos].dweller = RetiredInfo{activeGames[i].gameInfo, activeGames[i].fileInfo};
    }
    for (int i : All(lesserVillains)) {
      Vec2 pos = random.choose(freePos);
      removeElement(freePos, pos);
      campaign.sites[pos].dweller = lesserVillains[i];
    }
    for (int i : All(allies)) {
      Vec2 pos = random.choose(freePos);
      removeElement(freePos, pos);
      campaign.sites[pos].dweller = allies[i];
    }
    while (1) {
      bool updateMap = false;
      campaign.influenceSize = options->getIntValue(OptionId::INFLUENCE_SIZE);
      campaign.refreshInfluencePos();
      CampaignAction action = view->prepareCampaign(campaign, options, retired);
      switch (action.getId()) {
        case CampaignActionId::REROLL_MAP:
            terrain = getTerrain(random, size, numBlocked);
            worldName = NameGenerator::get(NameGeneratorId::WORLD)->getNext();
            options->setDefaultString(OptionId::KEEPER_NAME, NameGenerator::get(NameGeneratorId::FIRST)->getNext());
        case CampaignActionId::UPDATE_MAP:
            updateMap = true; break;
        case CampaignActionId::UPDATE_OPTION:
            switch (action.get<OptionId>()) {
              case OptionId::KEEPER_NAME:
              case OptionId::INFLUENCE_SIZE: break;
              default: updateMap = true; break;
            }
            break;
        case CampaignActionId::CANCEL:
            return none;
        case CampaignActionId::CHOOSE_SITE:
            if (campaign.playerPos)
              campaign.clearSite(*campaign.playerPos);
            campaign.playerPos = action.get<Vec2>();
            campaign.sites[*campaign.playerPos].dweller = PlayerInfo{ViewId::KEEPER};
            break;
        case CampaignActionId::CONFIRM:
            return campaign;
      }
      if (updateMap)
        break;
    }
  }
}