Exemple #1
0
int fight_check_dead()
{
	/* TODO: figure out the order of checking deaths: attacks are simultaneous. Iniative? */
	// TODO enemy and player codes are almost identical, refactor into a function
	// bool check_chr_dead(Character *chr); or something

	bool enemy_dead;
	bool enemy_dead_elements;
	// loop through all enemies in combat

	for (int i = 0; i <= 2; i++)
		{
		enemy_dead = false;
		enemy_dead_elements = false;

			if (enemy_party.characters[i]->incombat)
				{
					/* check if enemy dies */
					for (size_t j = 0; j < ELEM_COUNT; j++)
						{
							if (enemy_party.characters[i]->elements[j] <= 0) 
							{
								enemy_dead = true;
								enemy_dead_elements = true;
							}
						}
					if (enemy_party.characters[i]->health <= 0)
						enemy_dead = true;
			
				// the current enemy is dead (characters[i])
				if (enemy_dead)	
					{
						enemy_party.characters[i]->incombat = false;
						// TODO: would it look better to display "DEAD" instead of erasing the box?
						werase(fight_stat_win[3+i]);
						wrefresh(fight_stat_win[3+i]);

						int money = 7;
						player.money += money;
				
						if (enemy_dead_elements)
							ncurs_log_sysmsg(_("%s has caused an elemental imbalance in %s"), player.name, enemy_party.characters[i]->name);
					
						ncurs_log_sysmsg(_("%s has killed %s!"), player.name, enemy_party.characters[i]->name);
						// TODO: share money from a kill someway
						ncurs_log_sysmsg(_("%s found %d coins from the body"), player.name, money);

					// if there's no more enemies left, return to dungeons. 
					int alldead = 1;
 					for (int i = 0; i <= 2; i++)
						if (enemy_party.characters[i]->incombat)
 							alldead = 0;

					// if all enemies are dead, the battle is over
					if (alldead)
						{
						player.incombat = false; // don't return to combat any more
						ncurs_log_sysmsg(_("All enemies are slain! The battle is over"));
						return 1;					
						}
					// If there's enemies left, the battle continues (i.e. do nothing)
					}
				}
			}

	/* check if player dies as well */
	// TODO: loop through all players, not just yourself
	bool player_dead = false;
	bool player_dead_elements = false;
	for (size_t i = 0; i < 5; i++)
	{
		if (player.elements[i] <= 0) {
			player_dead = true;
			player_dead_elements = true;
		}
	}
	if (player.health <= 0)
		player_dead = true;

	if (player_dead)
	{
		wclear (game_win);
		if (player_dead_elements) // elements below 0, don't die but faint only
		{
			db_player_location(LOC_FAINTED);
			// TODO: which enemy..
			ncurs_log_sysmsg(_("%s has caused an elemental imbalance in %s"), enemy_party.characters[0]->name, player.name);
			mvwprintw(game_win, 6, 0, _("The world around you starts to spin.\nYou sense a great imbalance inside you."));

			wattron(game_win, A_BOLD);
			wattron(game_win, A_UNDERLINE);
			mvwprintw(game_win, 8, 0, _("You faint. TODO: \"come back in 8 hours??\""));
			wattroff(game_win, A_BOLD);
			wattroff(game_win, A_UNDERLINE);
		}
		else // PERMADEATH
		{
			/* first, set the player location to "DEAD" */
			db_player_location(LOC_DEAD);
			// TODO: which enemy
			ncurs_log_sysmsg(_("%s has killed %s!"), enemy_party.characters[0]->name, player.name);
			mvwprintw(game_win, 6, 0, _("The world fades around you as you fall to the ground, \nbleeding."));
			wattron(game_win, A_BOLD);
			wattron(game_win, A_UNDERLINE);
			mvwprintw(game_win, 8, 0, _("You are dead."));
			wattroff(game_win, A_BOLD);
			wattroff(game_win, A_UNDERLINE);
		}

		// common stuff to death // elemental imbalance
		wrefresh(game_win);
		todd_getchar(NULL);
		playing = false;
	}

	if (enemy_dead || player_dead)
		return 1; /* if enemy / player is dead, don't redraw combat stuff anymore */
	else
		return 0; // redraw combat stuff
}
Exemple #2
0
int fight_check_dead()
{
	/* TODO: figure out the order of checking deaths: attacks are simultaneous. Iniative? */
	// TODO enemy and player codes are almost identical, refactor into a function
	// bool check_chr_dead(Character *chr); or something

	/* check if enemy dies */
	bool enemy_dead = false;
	bool enemy_dead_elements = false;
	for (size_t i = 0; i < ELEM_COUNT; i++)
	{
		if (enemy.elements[i] <= 0) {
			enemy_dead = true;
			enemy_dead_elements = true;
		}
	}
	if (enemy.health <= 0)
		enemy_dead = true;
	if (enemy_dead)
	{
		int money = 7;
		int exp = 10;
		player.money += money;
		player.experience += exp;
		werase(game_win);
		if (enemy_dead_elements)
			ncurs_log_sysmsg(_("%s has caused an elemental imbalance in %s"), player.name, enemy.name);
		ncurs_log_sysmsg(_("%s has killed %s!"), player.name, enemy.name);
		ncurs_log_sysmsg(_("%s received %d coins and %d XP"), player.name, money, exp);
		ncurs_modal_msg(
				_("%s is slain!\n\nYou find %d coins on the corpse, and gain %d experience\n"),
				enemy.name, money, exp);
		ac_dungeons();
	}

	/* check if player dies as well */
	bool player_dead = false;
	bool player_dead_elements = false;
	for (size_t i = 0; i < 5; i++)
	{
		if (player.elements[i] <= 0) {
			player_dead = true;
			player_dead_elements = true;
		}
	}
	if (player.health <= 0)
		player_dead = true;

	if (player_dead)
	{
	
		wclear (game_win);

		if (player_dead_elements) // elements below 0, don't die but faint only
		{
			db_player_location(LOC_FAINTED);
			ncurs_log_sysmsg(_("%s has caused an elemental imbalance in %s"), enemy.name, player.name);
			mvwprintw(game_win, 6, 0, _("The world around you starts to spin.\nYou sense a great imbalance inside you."));

			wattron(game_win, A_BOLD);
			wattron(game_win, A_UNDERLINE);
			mvwprintw(game_win, 8, 0, _("You faint. TODO: \"come back in 8 hours??\""));
			wattroff(game_win, A_BOLD);
			wattroff(game_win, A_UNDERLINE);
		}
		else // PERMADEATH
		{
			/* first, set the player location to "DEAD" */
			db_player_location(LOC_DEAD);
		
			ncurs_log_sysmsg(_("%s has killed %s!"), enemy.name, player.name);
			mvwprintw(game_win, 6, 0, _("The world fades around you as you fall to the ground, \nbleeding."));
			wattron(game_win, A_BOLD);
			wattron(game_win, A_UNDERLINE);
			mvwprintw(game_win, 8, 0, _("You are dead."));
			wattroff(game_win, A_BOLD);
			wattroff(game_win, A_UNDERLINE);
		}

		// common stuff to death // elemental imbalance
		wrefresh(game_win);
		todd_getchar(NULL);
		playing = false;
	}

	if (enemy_dead || player_dead)
		return 1; /* if enemy / player is dead, don't redraw combat stuff anymore */
	else
		return 0; // redraw combat stuff
}