void move_character(dungeon_t *d, character *c, pair_t next) { int rs; pair_t p; if (charpair(next) && ((next[dim_y] != character_get_y(c)) || (next[dim_x] != character_get_x(c)))) { d->combat_message = ""; rs = do_combat(d, c, charpair(next)); } /* No character in new position. */ if(rs == 0 || !charpair(next)){ d->charmap[character_get_y(c)][character_get_x(c)] = NULL; character_set_y(c, next[dim_y]); character_set_x(c, next[dim_x]); d->charmap[character_get_y(c)][character_get_x(c)] = c; } if (c == d->pc) { pc_set_speed(d, c); } }
/*! \brief Main combat function * * The big one... I say that because the game is mostly combat :p * First, check to see if a random encounter has occured. The check is skipped * if it's a scripted battle. Then call all the helper and setup functions * and start the combat by calling do_round. * * \param bno Combat identifier (index into battles[]) * \returns 0 if no combat, 1 otherwise */ int combat (int bno) { int hero_level; int encounter; int lc; #ifdef KQ_CHEATS if (cheat && no_monsters) return 0; #endif /* PH: some checking! */ if (bno < 0 || bno >= NUM_BATTLES) { sprintf (strbuf, _("Combat: battle %d does not exist."), bno); return 1; //program_death (strbuf); } /* TT: no battles during scripted/target movements */ if (g_ent[0].movemode != MM_STAND) { return 0; } hero_level = party[pidx[0]].lvl; encounter = select_encounter (battles[bno].etnum, battles[bno].eidx); /* RB: check if we had had a random encounter */ if (battles[bno].enc > 1) { #ifdef KQ_CHEATS /* skip battle if no_random_encouters cheat is set */ if (cheat && no_random_encounters) return 0; #endif /* skip battle if haven't moved enough steps since last battle, * or if it's just not time for one yet */ if ((steps < STEPS_NEEDED) || ((rand () % battles[bno].enc) > 0)) { return 0; } /* Likely (not always) skip random battle if repluse is active */ if (save_spells[P_REPULSE] > 0) { lc = (hero_level - erows[encounter].lvl) * 20; if (lc < 5) lc = 5; /* Although Repulse is active, there's still a chance of battle */ if ((rand () % 100) < lc) { return 0; } } } if (hero_level >= erows[encounter].lvl + 5 && battles[bno].eidx == 99) { lc = (hero_level - erows[encounter].lvl) * 5; /* TT: This will skip battles based on a random number from hero's * level minus enemy's level. */ if ((rand () % 100) < lc) { return 0; } } /* Player is about to do battle. */ steps = 0; init_fighters (); return do_combat (battles[bno].backimg, battles[bno].bmusic, battles[bno].eidx == 99); }