void create_engine::prepare_for_new_level()
{
	DBG_MP << "preparing mp_game_settings for new level\n";

	state_.set_scenario(current_level().data());
	state_.mp_settings().hash = current_level().data().hash();
}
Exemple #2
0
void create_engine::prepare_for_scenario()
{
	DBG_MP << "preparing data for scenario by reloading game config\n";

	state_.classification().scenario_define =
		current_level().data()["define"].str();

	state_.set_carryover_sides_start(
		config_of("next_scenario", current_level().data()["id"])
	);
}
Exemple #3
0
/**
 * select_campaign_difficulty
 *
 * Launches difficulty selection gui and returns selected difficulty name.
 *
 * The gui can be bypassed by supplying a number
 * from 1 to the number of difficulties available,
 * corresponding to a choice of difficulty.
 * This is useful for specifying difficulty via command line.
 *
 * @param	set_value Preselected difficulty number. The default -1 launches the gui.
 * @return	Selected difficulty. Returns "FAIL" if set_value is invalid,
 *	and "CANCEL" if the gui is cancelled.
 */
std::string create_engine::select_campaign_difficulty(int set_value)
{
	const std::string difficulty_descriptions =
		current_level().data()["difficulty_descriptions"];
	std::vector<std::string> difficulty_options =
		utils::split(difficulty_descriptions, ';');
	const std::vector<std::string> difficulties =
		utils::split(current_level().data()["difficulties"]);

	if(difficulties.empty()) return "";

	int difficulty = 0;
	if (set_value != -1)
	{
		// user-specified campaign to jump to. con
		if (set_value
				> static_cast<int>(difficulties.size()))
		{
			std::cerr << "incorrect difficulty number: [" <<
				set_value << "]. maximum is [" <<
				difficulties.size() << "].\n";
			return "FAIL";
		}
		else if (set_value < 1)
		{
			std::cerr << "incorrect difficulty number: [" <<
				set_value << "]. minimum is [1].\n";
			return "FAIL";
		}
		else
		{
			difficulty = set_value - 1;
		}
	}
	else
	{
		if(difficulty_options.size() != difficulties.size())
		{
			difficulty_options = difficulties;
		}

		// show gui
		gui2::tcampaign_difficulty dlg(difficulty_options);
		dlg.show(disp_.video());

		if(dlg.selected_index() == -1)
		{
			return "CANCEL";
		}
		difficulty = dlg.selected_index();
	}
	return difficulties[difficulty];
}
void create_engine::prepare_for_campaign(const std::string& difficulty)
{
	DBG_MP << "preparing data for campaign by reloading game config\n";

	if (difficulty != "") {
		state_.classification().difficulty = difficulty;
	}

	state_.classification().campaign = current_level().data()["id"].str();
	state_.classification().abbrev = current_level().data()["abbrev"].str();

	state_.classification().end_text = current_level().data()["end_text"].str();
	state_.classification().end_text_duration =
		current_level().data()["end_text_duration"];

	state_.classification().campaign_define =
		current_level().data()["define"].str();
	state_.classification().campaign_xtra_defines =
		utils::split(current_level().data()["extra_defines"]);

	resources::config_manager->
		load_game_config_for_game(state_.classification());

	current_level().set_data(
		resources::config_manager->game_config().find_child(
		lexical_cast<std::string> (game_classification::MULTIPLAYER),
		"id", current_level().data()["first_scenario"]));
}
void create_engine::prepare_for_scenario()
{
	DBG_MP << "preparing data for scenario by reloading game config\n";

	state_.classification().scenario_define =
		current_level().data()["define"].str();
	
	resources::config_manager->
		load_game_config_for_game(state_.classification());

	current_level().set_data(
		resources::config_manager->game_config().find_child(
		lexical_cast<std::string> (game_classification::MULTIPLAYER),
		"id", current_level().data()["id"]));
}
void create_engine::init_generated_level_data()
{
	DBG_MP << "initializing generated level data\n";

	config data = generator_->create_scenario(std::vector<std::string>());

	// Set the scenario to have placing of sides
	// based on the terrain they prefer
	data["modify_placing"] = "true";

	const std::string& description = current_level().data()["description"];
	data["description"] = description;

	current_level().set_data(data);
}
Exemple #7
0
static void
game_leave (void)
{
  --lives;
  level = current_level ();
  extinguish_laser ();
  remove_meteors ();
}
Exemple #8
0
/**
 * select_campaign_difficulty
 *
 * Launches difficulty selection gui and returns selected difficulty name.
 *
 * The gui can be bypassed by supplying a number from 1 to the number of
 * difficulties available, corresponding to a choice of difficulty.
 * This is useful for specifying difficulty via command line.
 *
 * @param	set_value Preselected difficulty number. The default -1 launches the gui.
 * @return	Selected difficulty. Returns "FAIL" if set_value is invalid,
 *	        and "CANCEL" if the gui is canceled.
 */
std::string create_engine::select_campaign_difficulty(int set_value)
{
	// Verify the existence of difficulties
	std::vector<std::string> difficulties;

	BOOST_FOREACH(const config &d, current_level().data().child_range("difficulty"))
	{
		difficulties.push_back(d["define"]);
	}

	if(difficulties.empty()) {
		difficulties = utils::split(current_level().data()["difficulties"]);
	}

	// No difficulties found. Exit
	if(difficulties.empty()) {
		return "";
	}

	// A specific difficulty value was passed
	// Use a minimilistic interface to get the specified define
	if(set_value != -1) {
		if (set_value > static_cast<int>(difficulties.size())) {
			std::cerr << "incorrect difficulty number: [" <<
				set_value << "]. maximum is [" << difficulties.size() << "].\n";
			return "FAIL";
		} else if (set_value < 1) {
			std::cerr << "incorrect difficulty number: [" <<
				set_value << "]. minimum is [1].\n";
			return "FAIL";
		} else {
			return difficulties[set_value - 1];
		}
	}

	// If not, let the user pick one from the prompt
	// We don't pass the difficulties vector here because additional data is required
	// to constrict the dialog
	gui2::tcampaign_difficulty dlg(current_level().data());
	dlg.show(disp_.video());

	return dlg.selected_difficulty();
}
Exemple #9
0
void create_engine::init_generated_level_data()
{
	DBG_MP << "initializing generated level data\n";

	//DBG_MP << "current data:\n";
	//DBG_MP << current_level().data().debug();

	random_map * cur_lev = dynamic_cast<random_map *> (&current_level());

	if (!cur_lev) {
		WRN_MP << "Tried to initialized generated level data on a level that wasn't a random map\n";
		return;
	}

	try {
		if (!cur_lev->generate_whole_scenario())
		{
			DBG_MP << "** replacing map ** \n";

			config data = cur_lev->data();

			data["map_data"] = generator_->create_map();

			cur_lev->set_data(data);

		} else { //scenario generation

			DBG_MP << "** replacing scenario ** \n";

			config data = generator_->create_scenario();

			// Set the scenario to have placing of sides
			// based on the terrain they prefer
			if (!data.has_attribute("modify_placing")) {
				data["modify_placing"] = "true";
			}

			const std::string& description = cur_lev->data()["description"];
			data["description"] = description;

			cur_lev->set_data(data);
		}
	} catch (mapgen_exception & e) {
		config data = cur_lev->data();

		data["error_message"] = e.what();

		cur_lev->set_data(data);
	}

	//DBG_MP << "final data:\n";
	//DBG_MP << current_level().data().debug();

}
Exemple #10
0
void create_engine::prepare_for_campaign(const std::string& difficulty)
{
	DBG_MP << "preparing data for campaign by reloading game config\n";

	if (difficulty != "") {
		state_.classification().difficulty = difficulty;
	}

	state_.classification().campaign = current_level().data()["id"].str();
	state_.classification().abbrev = current_level().data()["abbrev"].str();

	state_.classification().end_text = current_level().data()["end_text"].str();
	state_.classification().end_text_duration =
		current_level().data()["end_text_duration"];

	state_.classification().campaign_define =
		current_level().data()["define"].str();
	state_.classification().campaign_xtra_defines =
		utils::split(current_level().data()["extra_defines"]);

	state_.set_carryover_sides_start(
		config_of("next_scenario", current_level().data()["first_scenario"])
	);
}
Exemple #11
0
	void Player::score_exp(int x)
	{
		byte i;

		/* Overall adjustment. */
		Dungeon::d.pc.experience += x;

		/* Divided adjustment. */
		for (i = 0; i < MAX_T_SKILL; i++)
		{
			Dungeon::d.pc.tskill_exp[i] += (x * Dungeon::d.pc.tskill_training[i]);

			/* Check advancement. */
			while (Dungeon::d.pc.tskill_exp[i] >= required_exp(i))
			{
				Dungeon::d.pc.tskill_exp[i] -= required_exp(i);
				increase_training_skill(i);
				Misc::Message(Misc::Format("Your %s increases to %d.", gcnew String(tskill_s[i]), current_level(i)));
			}
		}

		/* Update the changes. */
		update_necessary = true;
	}
Exemple #12
0
	void Player::adjust_training(void)
	{
		char c;
		byte i, length, exp_length, unit_length, training_length;
		short remaining_units;
		bool do_redraw;
		static byte pos = 0;  /* Initial menu position. */

		/*
		 * Determine the maximum training skill length.  This could be a hard-coded
		 * constants but by doing this dynamically it's a lot simpler and less
		 * error-prone to change the specific training skills.
		 *
		 * In the same run we count the number of training units spent.
		 */
		length = exp_length = unit_length = 0;
		remaining_units = TUNITS;
		for (i = 0; i < MAX_T_SKILL; i++)
		{
			length = Misc::imax(length, strlen(tskill_s[i]));
			exp_length = Misc::imax(exp_length
				, strlen(Misc::string("%d"
					, (int) Dungeon::d.pc.tskill_exp[i] / TUNITS)));
			unit_length = Misc::imax(unit_length
				, strlen(Misc::string("%ld"
					, (long) required_exp(i) / TUNITS)));
			remaining_units -= Dungeon::d.pc.tskill_training[i];
		}

		/* Main loop.  Draw the menu and react on commands. */
		do_redraw = true;

		do
		{
			/* Draw the menu. */
			if (do_redraw)
			{
				SysDep::set_color(ConsoleColor::Gray);

				training_length = 0;
				for (i = 0; i < MAX_T_SKILL; i++)
					training_length = Misc::imax(training_length
						, strlen(Misc::string("%d"
							, (int)
							Dungeon::d.pc.tskill_training[i])));
				for (i = 0; i < MAX_T_SKILL; i++)
				{
					SysDep::cursor(3, i);
					SysDep::prtstr("    %*s: %*ld of %*ld [%*d]: %d   "
						, length
						, tskill_s[i]
						, exp_length
						, (long) Dungeon::d.pc.tskill_exp[i] / TUNITS
						, unit_length
						, (long) required_exp(i) / TUNITS
						, training_length
						, (int) Dungeon::d.pc.tskill_training[i]
						, (int) current_level(i));
				}
				SysDep::cursor(0, 24);
				SysDep::prtstr(" [iI] Up -- [kK] Down -- [jJ] Decrease -- [lL] Increase");
				SysDep::prtstr(" -- Units: %d", (int) remaining_units);
				SysDep::clear_to_eol();
				do_redraw = false;
			}

			SysDep::cursor(4, pos);
			SysDep::prtstr("->");
			SysDep::update();
			c = SysDep::getkey();
			SysDep::cursor(4, pos);
			SysDep::prtstr("  ");
			SysDep::update();

			switch (c)
			{
			case 'L':
				if (remaining_units)
				{
					Dungeon::d.pc.tskill_training[pos] += remaining_units;
					remaining_units = 0;
					do_redraw = true;
				}
				break;

			case 'l':
				if (remaining_units)
				{
					remaining_units--;
					Dungeon::d.pc.tskill_training[pos]++;
					do_redraw = true;
				}
				break;

			case 'J':
				if (Dungeon::d.pc.tskill_training[pos])
				{
					remaining_units += Dungeon::d.pc.tskill_training[pos];
					Dungeon::d.pc.tskill_training[pos] = 0;
					do_redraw = true;
				}
				break;

			case 'j':
				if (Dungeon::d.pc.tskill_training[pos])
				{
					Dungeon::d.pc.tskill_training[pos]--;
					remaining_units++;
					do_redraw = true;
				}
				break;

			case 'I':
				pos = 0;
				break;

			case 'i':
				if (pos)
					pos--;
				else
					pos = MAX_T_SKILL - 1;
				break;

			case 'K':
				pos = MAX_T_SKILL - 1;
				break;

			case 'k':
				if (pos < MAX_T_SKILL - 1)
					pos++;
				else
					pos = 0;
				break;

			default:
				break;
			}
		} while (c != 27 && c != 'Q' && c != 32);

		/* Clean up. */
		Game::redraw();
	}
Exemple #13
0
void create_engine::prepare_for_other()
{
	DBG_MP << "prepare_for_other\n";
	state_.set_scenario(current_level().data());
	state_.mp_settings().hash = current_level().data().hash();
}