Skip to content

Commit

Permalink
Fix improper attack display for npcs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kestrel Gregorich-Trevor committed Jan 18, 2024
1 parent a91d40d commit 56ba369
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions include/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#define GRAB 0x08

/* Stances */
#define STANCE_CROUCH LOW | MID
#define STANCE_STAND MID | HIGH
#define STANCE_CROUCH (LOW | MID)
#define STANCE_STAND (MID | HIGH)
#define STANCE_TECH GRAB
#define STANCE_STUN 0x0
#define MAX_HITDESC 4
Expand Down
2 changes: 1 addition & 1 deletion include/combat.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int do_attack(struct actor *, struct actor *, int);
int weak_res(short, short);
int calculate_evasion(struct actor *);
int calculate_accuracy(struct actor *, struct attack *);
struct attack *get_active_attack(int);
struct attack *get_active_attack(struct actor *, int);
int change_stance(struct actor *, short, int);

#define DAMAGE_SCALING 0.9
Expand Down
2 changes: 1 addition & 1 deletion src/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ struct action *get_action(void) {
int keycode = handle_keys();
if (keycode >= 49 && keycode < 57) {
g.active_attack_index = keycode - 49;
while (!get_active_attack(g.active_attack_index)->dam)
while (!get_active_attack(g.player, g.active_attack_index)->dam)
g.active_attack_index++;
}
for (i = 0; i < ACTION_COUNT; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/ai.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ struct attack choose_attack(struct actor *aggressor, struct actor *target) {
int i, j;
(void) target; /* TODO: Implement attack favoring. */
if (aggressor == g.player) {
return *(get_active_attack(g.active_attack_index));
return *(get_active_attack(g.player, g.active_attack_index));
}
for (i = 0; i < MAX_ATTK; i++) {
if (is_noatk(aggressor->attacks[i]))
Expand Down
12 changes: 7 additions & 5 deletions src/combat.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ void apply_knockback(struct actor* target, int velocity, int x, int y) {
* tech = 2
*/
int weak_res(short hitdesc, short stance) {
logm("%d, %d", hitdesc, stance);
if ((stance & STANCE_STUN)) { /* If stunned, all attacks hit. */
logm("STUN");
return BHIT;
}
if ((hitdesc & GRAB) && (stance & GRAB))
Expand Down Expand Up @@ -251,11 +253,11 @@ int calculate_accuracy(struct actor *actor, struct attack *attack) {
* @param index the index of the attack to get
* @return struct attack* The pointer to the active attack.
*/
struct attack *get_active_attack(int index) {
if (EWEP(g.player) && !EOFF(g.player)) return &EWEP(g.player)->attacks[index % MAX_ATTK];
else if (EWEP(g.player) && EOFF(g.player)) return index < MAX_ATTK ? &EWEP(g.player)->attacks[index] : &EOFF(g.player)->attacks[index % MAX_ATTK];
else if (EOFF(g.player)) return &EOFF(g.player)->attacks[index % MAX_ATTK];
else return &g.player->attacks[index % MAX_ATTK];
struct attack *get_active_attack(struct actor *actor, int index) {
if (EWEP(actor) && !EOFF(actor)) return &EWEP(actor)->attacks[index % MAX_ATTK];
else if (EWEP(actor) && EOFF(actor)) return index < MAX_ATTK ? &EWEP(actor)->attacks[index] : &EOFF(actor)->attacks[index % MAX_ATTK];
else if (EOFF(actor)) return &EOFF(actor)->attacks[index % MAX_ATTK];
else return &actor->attacks[index % MAX_ATTK];
return NULL;
}

Expand Down
4 changes: 2 additions & 2 deletions windows/curses/windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ void display_sb_nearby(WINDOW *sb_win, int *j) {
/* TODO: Remove unecessary buffer usage. */
void display_sb_stats(WINDOW *win, int *i, struct actor *actor) {
char buf[128];
struct attack *cur_attack = get_active_attack(g.active_attack_index);
struct attack *cur_attack = get_active_attack(actor, g.active_attack_index);
int k = 0;

memset(buf, 0, 128);
Expand All @@ -526,7 +526,7 @@ void display_sb_stats(WINDOW *win, int *i, struct actor *actor) {

/* TODO: Clean up this epic kludge */
for (int index = 0; index < MAX_ATTK * 2; index++) {
cur_attack = get_active_attack(index);
cur_attack = get_active_attack(actor, index);
if ((EWEP(actor) && (index > MAX_ATTK || is_noatk(EWEP(actor)->attacks[index]))) ||
(EOFF(actor) && !EWEP(actor) && (index >= MAX_ATTK || is_noatk(EOFF(actor)->attacks[index]))) ||
(!(EWEP(actor) || EOFF(actor)) && (index >= MAX_ATTK || is_noatk(actor->attacks[index])))) {
Expand Down

0 comments on commit 56ba369

Please sign in to comment.