Skip to content

Commit

Permalink
Close #1323, port partial blows per round from V320.
Browse files Browse the repository at this point in the history
Note, that due to some (vast) differences in our energy code, the port
is not a 100% match.
  • Loading branch information
flambard-took committed Aug 14, 2019
1 parent a59f11f commit cd2758d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/common/types.h
Expand Up @@ -1504,6 +1504,8 @@ struct player_type
u32b energy; /* Current energy */
u32b energy_buildup; /* MAngband-specific: bonus energy (!) */

byte dealt_blows; /* Temp -- count blows this round */

s16b food; /* Current nutrition */

byte confusing; /* Glowing hands */
Expand Down
52 changes: 43 additions & 9 deletions src/server/cmd1.c
Expand Up @@ -1181,6 +1181,7 @@ void py_attack_player(player_type *p_ptr, int y, int x)
int Depth = p_ptr->dun_depth;

int num = 0, k, bonus, chance;
u32b blow_energy;

cave_type *c_ptr = &cave[Depth][y][x];

Expand All @@ -1192,6 +1193,9 @@ void py_attack_player(player_type *p_ptr, int y, int x)

bool do_quake = FALSE;

/* Hack -- reset counter */
p_ptr->dealt_blows = 0;

/* Disturb both players */
disturb(p_ptr, 0, 0);
disturb(q_ptr, 0, 0);
Expand Down Expand Up @@ -1219,10 +1223,18 @@ void py_attack_player(player_type *p_ptr, int y, int x)
bonus = p_ptr->to_h + o_ptr->to_h;
chance = (p_ptr->skill_thn + (bonus * BTH_PLUS_ADJ));

/* Energy cost for one blow */
blow_energy = level_speed(p_ptr->dun_depth) / p_ptr->num_blow;

/* Attack once for each legal blow */
while (num++ < p_ptr->num_blow)
/* Attack once */
while (p_ptr->energy >= blow_energy)
{
/* Spend energy */
p_ptr->energy -= blow_energy;

/* Hack -- increase counter (for later) */
p_ptr->dealt_blows++;

/* Test for hit */
if (test_hit_norm(chance, q_ptr->ac + q_ptr->to_a, 1))
{
Expand Down Expand Up @@ -1327,6 +1339,7 @@ void py_attack_mon(player_type *p_ptr, int y, int x)
int Depth = p_ptr->dun_depth;

int num = 0, k, bonus, chance;
u32b blow_energy;

cave_type *c_ptr = &cave[Depth][y][x];

Expand All @@ -1344,6 +1357,9 @@ void py_attack_mon(player_type *p_ptr, int y, int x)

bool backstab = FALSE, stab_fleeing = FALSE;

/* Hack -- reset counter */
p_ptr->dealt_blows = 0;

/* Disturb the player */
disturb(p_ptr, 0, 0);

Expand Down Expand Up @@ -1390,10 +1406,17 @@ void py_attack_mon(player_type *p_ptr, int y, int x)
bonus = p_ptr->to_h + o_ptr->to_h;
chance = (p_ptr->skill_thn + (bonus * BTH_PLUS_ADJ));

blow_energy = level_speed(p_ptr->dun_depth) / p_ptr->num_blow;

/* Attack once for each legal blow */
while (num++ < p_ptr->num_blow)
/* Attack while we have energy */
while (p_ptr->energy >= blow_energy)
{
/* Remove energy */
p_ptr->energy -= blow_energy;

/* Hack -- increase counter (for later) */
p_ptr->dealt_blows++;

/* Test for hit */
if (test_hit_norm(chance, r_ptr->ac, p_ptr->mon_vis[c_ptr->m_idx]))
{
Expand Down Expand Up @@ -1573,6 +1596,9 @@ void move_player(player_type *p_ptr, int dir, int do_pickup)
/* Ensure "dir" is in ddx/ddy array bounds */
if (!VALID_DIR(dir)) return;

/* Hack -- reset temp. flag */
p_ptr->dealt_blows = 0;

/* Find the result of moving */
y = p_ptr->py + ddy[dir];
x = p_ptr->px + ddx[dir];
Expand Down Expand Up @@ -2885,15 +2911,23 @@ void run_step(player_type *p_ptr, int dir)
/* Increase counter */
p_ptr->ran_tiles += 1;

/* Take a turn */
p_ptr->energy -= level_speed(p_ptr->dun_depth);

/* Classic MAnghack #5. Reset built-up energy. */
p_ptr->energy_buildup = 0;

/* Make noise */
set_noise(p_ptr, p_ptr->noise + (30 - p_ptr->skill_stl));

/* Move the player, using the "pickup" flag */
move_player(p_ptr, p_ptr->find_current, option_p(p_ptr,ALWAYS_PICKUP));

/* Hack -- don't spend energy if player attacked someone */
/* Because we have already spent an appropriate amount elsewhere */
if (!p_ptr->dealt_blows)
{

/* Take a turn */
p_ptr->energy -= level_speed(p_ptr->dun_depth);

/* Classic MAnghack #5. Reset built-up energy. */
p_ptr->energy_buildup = 0;

}/* End Hack */
}
6 changes: 6 additions & 0 deletions src/server/cmd2.c
Expand Up @@ -3010,9 +3010,15 @@ void do_cmd_walk(player_type *p_ptr, int dir, int pickup)
/* Actually move the character */
move_player(p_ptr, dir, pickup);

/* Hack -- don't spend energy if player attacked someone */
/* Because we have already spent an appropriate amount elsewhere */
if (!p_ptr->dealt_blows) {

/* Take a turn */
p_ptr->energy -= level_speed(p_ptr->dun_depth);

}/* End Hack */

/* Allow more walking */
more = TRUE;
}
Expand Down
11 changes: 8 additions & 3 deletions src/server/dungeon.c
Expand Up @@ -1005,6 +1005,7 @@ static void process_player_end(player_type *p_ptr)
int i, j, new_depth, new_world_x, new_world_y, time, timefactor;
int regen_amount, NumPlayers_old=NumPlayers;
char attackstatus;
u32b blow_energy;
int minus;
int fatal_err;

Expand All @@ -1023,8 +1024,12 @@ static void process_player_end(player_type *p_ptr)
/* Paranoia -- buffered commands shouldn't even cause fatal errors */
if (fatal_err == -1) return;

/* How much energy does it cost do deal 1 blow? */
blow_energy = level_speed(p_ptr->dun_depth) / p_ptr->num_blow;


/* Check for auto-retaliate */
if ((p_ptr->energy >= level_speed(p_ptr->dun_depth))/* - have spare energy */
if ((p_ptr->energy >= blow_energy) /* - have spare energy */
&& !p_ptr->confused && !p_ptr->afraid /* - not confused or afraid */
&& !p_ptr->run_request && !cq_len(&p_ptr->cbuf)) /* - no commands queued */
{
Expand All @@ -1034,8 +1039,8 @@ static void process_player_end(player_type *p_ptr)
*/
if ((attackstatus = auto_retaliate(p_ptr)))
{
/* Use energy */
p_ptr->energy -= level_speed(p_ptr->dun_depth);
/* Use energy */ /* XXX spent in attack code */
/*p_ptr->energy -= blow_energy;*/
}
}

Expand Down

0 comments on commit cd2758d

Please sign in to comment.