Example #1
0
bool Game_Interpreter::CommandChangeHP(RPG::EventCommand const& com) { // Code 10460
	std::vector<Game_Actor*> actors = GetActors(com.parameters[0],
												com.parameters[1]);
	bool remove = com.parameters[2] != 0;
	int amount = ValueOrVariable(com.parameters[3],
								 com.parameters[4]);
	bool lethal = com.parameters[5] != 0;

	if (remove)
		amount = -amount;

	for (std::vector<Game_Actor*>::iterator i = actors.begin();
		 i != actors.end();
		 ++i) {
		Game_Actor* actor = *i;
		int hp = actor->GetHp() + amount;
		if (!lethal && hp <= 0) {
			amount += hp * (-1) + 1;
		}
		actor->ChangeHp(amount);
	}

	if (lethal) {
		CheckGameOver();
	}

	return true;
}
Example #2
0
void Game_Party::ApplyDamage(int damage) {
	if (damage <= 0) {
		return;
	}

	std::vector<Game_Actor*> actors = GetActors();

	for (std::vector<Game_Actor*>::iterator i = actors.begin(); i != actors.end(); ++i) {
		Game_Actor* actor = *i;
		actor->SetHp(actor->GetHp() - damage);
	}
}
Example #3
0
void Game_Party::ApplyDamage(int damage, bool lethal) {
	if (damage <= 0) {
		return;
	}

	std::vector<Game_Actor*> actors = GetActors();

	for (std::vector<Game_Actor*>::iterator i = actors.begin(); i != actors.end(); ++i) {
		Game_Actor* actor = *i;
		actor->ChangeHp(lethal? -damage : - std::max<int>(0, std::min<int>(damage, actor->GetHp() - 1)));
	}
}
Example #4
0
void Scene_Save::Action(int index) {
	std::stringstream ss;
	ss << "Save" << (index <= 8 ? "0" : "") << (index + 1) << ".lsd";

	// TODO: Maybe find a better place to setup the save file?
	RPG::SaveTitle title;

	int size = (int)Main_Data::game_party->GetActors().size();
	Game_Actor* actor;

	switch (size) {
		case 4:
			actor = Main_Data::game_party->GetActors()[3];
			title.face4_id = actor->GetFaceIndex();
			title.face4_name = actor->GetFaceName();
		case 3:
			actor = Main_Data::game_party->GetActors()[2];
			title.face3_id = actor->GetFaceIndex();
			title.face3_name = actor->GetFaceName();
		case 2:
			actor = Main_Data::game_party->GetActors()[1];
			title.face2_id = actor->GetFaceIndex();
			title.face2_name = actor->GetFaceName();
		case 1:
			actor = Main_Data::game_party->GetActors()[0];
			title.face1_id = actor->GetFaceIndex();
			title.face1_name = actor->GetFaceName();
			title.hero_hp = actor->GetHp();
			title.hero_level = actor->GetLevel();
			title.hero_name = actor->GetName();
			break;
		default:;
	}

	Main_Data::game_data.title = title;

	Main_Data::game_data.system.save_slot = index + 1;
	Main_Data::game_data.system.save_count += 1;

	Game_Map::PrepareSave();

	std::string filename = FileFinder::FindDefault(*tree, ss.str());

	if (filename.empty()) {
		filename = FileFinder::MakePath(Main_Data::project_path, ss.str());
	}

	LSD_Reader::Save(filename, Main_Data::game_data,
		ReaderUtil::GetEncoding(FileFinder::FindDefault(INI_NAME)));

	Scene::Pop();
}
bool Game_Interpreter::CommandChangeHP(RPG::EventCommand const& com) { // Code 10460
	std::vector<Game_Actor*> actors = GetActors(com.parameters[0],
												com.parameters[1]);
	bool remove = com.parameters[2] != 0;
	int amount = ValueOrVariable(com.parameters[3],
								 com.parameters[4]);
	bool lethal = com.parameters[5] != 0;

	if (remove)
		amount = -amount;

	for (std::vector<Game_Actor*>::iterator i = actors.begin();
		 i != actors.end();
		 i++) {
		Game_Actor* actor = *i;
		int hp = actor->GetHp() + amount;
		if (hp < 0)
			hp = lethal ? 0 : 1;
		actor->SetHp(hp);
	}

	return true;
}
// Command control vars
bool Game_Interpreter::CommandControlVariables(RPG::EventCommand const& com) { // Code ControlVars
	int i, value = 0;
	Game_Actor* actor;
	Game_Character* character;

	switch (com.parameters[4]) {
		case 0:
			// Constant
			value = com.parameters[5];
			break;
		case 1:
			// Var A ops B
			value = Game_Variables[com.parameters[5]];
			break;
		case 2:
			// Number of var A ops B
			value = Game_Variables[Game_Variables[com.parameters[5]]];
			break;
		case 3:
			// Random between range
			int a, b;
			a = max(com.parameters[5], com.parameters[6]);
			b = min(com.parameters[5], com.parameters[6]);
			value = rand() % (a-b+1)+b;
			break;
		case 4:
			// Items
			switch (com.parameters[6]) {
				case 0:
					// Number of items posessed
					value = Game_Party::ItemNumber(com.parameters[5]);
					break;
				case 1:
					// How often the item is equipped
					value = Game_Party::ItemNumber(com.parameters[5], true);
					break;
			}
			break;
		case 5:
			// Hero
			actor = Game_Actors::GetActor(com.parameters[5]);
			if (actor != NULL) {
				switch (com.parameters[6]) {
					case 0:
						// Level
						value = actor->GetLevel();
						break;
					case 1:
						// Experience
						value = actor->GetExp();
						break;
					case 2:
						// Current HP
						value = actor->GetHp();
						break;
					case 3:
						// Current MP
						value = actor->GetSp();
						break;
					case 4:
						// Max HP
						value = actor->GetMaxHp();
						break;
					case 5:
						// Max MP
						value = actor->GetMaxSp();
						break;
					case 6:
						// Attack
						value = actor->GetAtk();
						break;
					case 7:
						// Defense
						value = actor->GetDef();
						break;
					case 8:
						// Intelligence
						value = actor->GetSpi();
						break;
					case 9:
						// Agility
						value = actor->GetAgi();
						break;
					case 10:
						// Weapon ID
						value = actor->GetWeaponId();
						break;
					case 11:
						// Shield ID
						value = actor->GetShieldId();
						break;
					case 12:
						// Armor ID
						value = actor->GetArmorId();
						break;
					case 13:
						// Helmet ID
						value = actor->GetHelmetId();
						break;
					case 14:
						// Accesory ID
						value = actor->GetAccessoryId();
						break;
				}
			}
			break;
		case 6:
			// Characters
			if (com.parameters[6] != 0){
				character = GetCharacter(com.parameters[5]);
			} else {
				// Special case for Player Map ID
				character = NULL;
				value = Game_Map::GetMapId();
			}
			// Other cases
			if (character != NULL) {
				switch (com.parameters[6]) {
					case 1:
						// X Coordinate
						value = character->GetX();
						break;
					case 2:
						// Y Coordinate
						value = character->GetY();
						break;
					case 3:
						// TODO Orientation
						// Needs testing
						value = character->GetDirection();
						break;
					case 4:
						// Screen X
						value = character->GetScreenX();
						break;
					case 5:
						// Screen Y
						value = character->GetScreenY();
				}
			}
			break;
		case 7:
			// More
			switch (com.parameters[5]) {
				case 0:
					// Gold
					value = Game_Party::GetGold();
					break;
				case 1:
					value = Game_Party::ReadTimer(Game_Party::Timer1);
					break;
				case 2:
					// Number of heroes in party
					value = Game_Party::GetActors().size();
					break;
				case 3:
					// Number of saves
					value = Game_System::GetSaveCount();
					break;
				case 4:
					// Number of battles
					value = Game_Party::GetBattleCount();
					break;
				case 5:
					// Number of wins
					value = Game_Party::GetWinCount();
					break;
				case 6:
					// Number of defeats
					value = Game_Party::GetDefeatCount();
					break;
				case 7:
					// Number of escapes (aka run away)
					value = Game_Party::GetRunCount();
					break;
				case 8:
					// TODO: MIDI play position
					break;
				case 9:
					value = Game_Party::ReadTimer(Game_Party::Timer2);
					break;
			}
			break;
		default:
			;
	}

	switch (com.parameters[0]) {
		case 0:
		case 1:
			// Single and Var range
			for (i = com.parameters[1]; i <= com.parameters[2]; i++) {
				switch (com.parameters[3]) {
					case 0:
						// Assignement
						Game_Variables[i] = value;
						break;
					case 1:
						// Addition
						Game_Variables[i] += value;
						break;
					case 2:
						// Subtraction
						Game_Variables[i] -= value;
						break;
					case 3:
						// Multiplication
						Game_Variables[i] *= value;
						break;
					case 4:
						// Division
						if (value != 0) {
							Game_Variables[i] /= value;
						}
						break;
					case 5:
						// Module
						if (value != 0) {
							Game_Variables[i] %= value;
						} else {
							Game_Variables[i] = 0;
						}
				}
				if (Game_Variables[i] > MaxSize) {
					Game_Variables[i] = MaxSize;
				}
				if (Game_Variables[i] < MinSize) {
					Game_Variables[i] = MinSize;
				}
			}
			break;

		case 2:
			switch (com.parameters[3]) {
				case 0:
					// Assignement
					Game_Variables[com.parameters[1]] = value;
					break;
				case 1:
					// Addition
					Game_Variables[com.parameters[1]] += value;
					break;
				case 2:
					// Subtraction
					Game_Variables[com.parameters[1]] -= value;
					break;
				case 3:
					// Multiplication
					Game_Variables[com.parameters[1]] *= value;
					break;
				case 4:
					// Division
					if (value != 0) {
						Game_Variables[com.parameters[1]] /= value;
					}
					break;
				case 5:
					// Module
					if (value != 0) {
						Game_Variables[com.parameters[1]] %= value;
					}
			}
			if (Game_Variables[com.parameters[1]] > MaxSize) {
				Game_Variables[com.parameters[1]] = MaxSize;
			}
			if (Game_Variables[com.parameters[1]] < MinSize) {
				Game_Variables[com.parameters[1]] = MinSize;
			}
	}

	Game_Map::SetNeedRefresh(true);
	return true;
}
Example #7
0
bool Game_Battle::AreConditionsMet(const RPG::TroopPageCondition& condition) {
	if (condition.flags.switch_a && !Game_Switches[condition.switch_a_id])
		return false;

	if (condition.flags.switch_b && !Game_Switches[condition.switch_b_id])
		return false;

	if (condition.flags.variable && !(Game_Variables[condition.variable_id] >= condition.variable_value))
		return false;

	if (condition.flags.turn && !CheckTurns(GetTurn(), condition.turn_b, condition.turn_a))
		return false;

	/*
	TODO RPG 2k3
	if (condition.flags.turn_enemy && !CheckTurns(GetEnemy(condition.turn_enemy_id).GetTurns(),
	condition.turn_enemy_b, condition.turn_enemy_a))
	return false;

	if (condition.flags.turn_actor) {
	Battle::Ally* ally = FindAlly(condition.turn_actor_id);
	if (!ally)
	return false;
	if (!CheckTurns(ally->GetTurns(), condition.turn_actor_b, condition.turn_actor_a))
	return false;
	}*/

	if (condition.flags.fatigue) {
		int fatigue = Main_Data::game_party->GetFatigue();
		if (fatigue < condition.fatigue_min || fatigue > condition.fatigue_max)
			return false;
	}

	if (condition.flags.enemy_hp) {
		Game_Battler& enemy = (*Main_Data::game_enemyparty)[condition.enemy_id - 1];
		int hp = enemy.GetHp();
		int hpmin = enemy.GetMaxHp() * condition.enemy_hp_min / 100;
		int hpmax = enemy.GetMaxHp() * condition.enemy_hp_max / 100;
		if (hp < hpmin || hp > hpmax)
			return false;
	}

	if (condition.flags.actor_hp) {
		Game_Actor* actor = Game_Actors::GetActor(condition.actor_id);
		int hp = actor->GetHp();
		int hpmin = actor->GetMaxHp() * condition.actor_hp_min / 100;
		int hpmax = actor->GetMaxHp() * condition.actor_hp_max / 100;
		if (hp < hpmin || hp > hpmax)
			return false;
	}

	if (condition.flags.turn_actor) {
		if (!CheckTurns(Game_Actors::GetActor(condition.actor_id)->GetBattleTurn(),
			condition.turn_actor_b, condition.turn_actor_a)) {
			return false;
		}
	}
	/*
	TODO RPG2k3

	if (condition.flags.command_actor) {
	Battle::Ally* ally = FindAlly(condition.actor_id);
	if (!ally)
	return false;
	if (ally->last_command != condition.command_id)
	return false;
	}*/
	return true;
}
Example #8
0
void Scene_Save::Action(int index) {
	std::stringstream ss;
	ss << "Save" << (index <= 8 ? "0" : "") << (index + 1) << ".lsd";

	Output::Debug("Saving to %s", ss.str().c_str());

	// TODO: Maybe find a better place to setup the save file?
	RPG::SaveTitle title;

	int size = (int)Main_Data::game_party->GetActors().size();
	Game_Actor* actor;

	if (size > 3) {
		actor = Main_Data::game_party->GetActors()[3];
		title.face4_id = actor->GetFaceIndex();
		title.face4_name = actor->GetFaceName();
	}
	if (size > 2) {
		actor = Main_Data::game_party->GetActors()[2];
		title.face3_id = actor->GetFaceIndex();
		title.face3_name = actor->GetFaceName();
	}
	if (size > 1) {
		actor = Main_Data::game_party->GetActors()[1];
		title.face2_id = actor->GetFaceIndex();
		title.face2_name = actor->GetFaceName();
	}
	if (size > 0) {
		actor = Main_Data::game_party->GetActors()[0];
		title.face1_id = actor->GetFaceIndex();
		title.face1_name = actor->GetFaceName();
		title.hero_hp = actor->GetHp();
		title.hero_level = actor->GetLevel();
		title.hero_name = actor->GetName();
	}

	Main_Data::game_data.title = title;

	Main_Data::game_data.system.save_slot = index + 1;

	Game_Map::PrepareSave();

	std::string save_file = ss.str();
	std::string filename = FileFinder::FindDefault(*tree, ss.str());

	if (filename.empty()) {
		filename = FileFinder::MakePath((*tree).directory_path, save_file);
	}

	LSD_Reader::PrepareSave(Main_Data::game_data, PLAYER_SAVEGAME_VERSION);
	auto data_copy = LSD_Reader::ClearDefaults(Main_Data::game_data, Game_Map::GetMapInfo(), Game_Map::GetMap());
	// RPG_RT saves always have the scene set to this.
	data_copy.system.scene = RPG::SaveSystem::Scene_file;
	// RPG_RT always stores SaveMapEvent with map_id == 0.
	for (auto& sme: data_copy.map_info.events) {
		sme.map_id = 0;
	}
	LSD_Reader::Save(filename, data_copy, Player::encoding);

#ifdef EMSCRIPTEN
	// Save changed file system
	EM_ASM({
		FS.syncfs(function(err) {
		});
	});