void test_invalid_if_on_same_position(void) { position_t white_queen; position_t black_queen; white_queen.column = 2; white_queen.row = 5; black_queen.column = white_queen.column; black_queen.row = white_queen.row; TEST_ASSERT_EQUAL(INVALID_POSITION, can_attack(white_queen, black_queen)); }
void test_can_attack_on_same_row(void) { TEST_IGNORE(); position_t white_queen; position_t black_queen; white_queen.column = 4; white_queen.row = 2; black_queen.column = 6; black_queen.row = 2; TEST_ASSERT_EQUAL(CAN_ATTACK, can_attack(white_queen, black_queen)); }
void test_black_queen_must_have_column_on_board(void) { TEST_IGNORE(); position_t white_queen; position_t black_queen; white_queen.column = 0; white_queen.row = 0; black_queen.column = 9; black_queen.row = 4; TEST_ASSERT_EQUAL(INVALID_POSITION, can_attack(white_queen, black_queen)); }
void test_can_attack_on_fourth_diagonal(void) { TEST_IGNORE(); position_t white_queen; position_t black_queen; white_queen.column = 2; white_queen.row = 2; black_queen.column = 5; black_queen.row = 5; TEST_ASSERT_EQUAL(CAN_ATTACK, can_attack(white_queen, black_queen)); }
void Monster::take_turn() { // TODO: Move make_plans() outside of this function? make_plans(); while (action_points > 0 && !dead) { if (wander_duration > 0) { wander_duration--; } if (target) { if (can_attack(target)) { attack(target); } else { move_towards(target); } } else { wander(); } } }
int do_attack(int cn,int dir,int co) { int m,x,y; if (cn<1 || cn>=MAXCHARS) { error=ERR_ILLEGAL_CHARNO; return 0; } if (ch[cn].flags&(CF_DEAD)) { error=ERR_DEAD; return 0; } if (!dx2offset(dir,&x,&y,NULL)) { error=ERR_ILLEGAL_DIR; return 0; } x+=ch[cn].x; y+=ch[cn].y; if (x<1 || x>MAXMAP-2 || y<1 || y>MAXMAP-2) { error=ERR_ILLEGAL_COORDS; return 0; } m=x+y*MAXMAP; if (co!=map[m].ch && co!=map[m+1].ch && co!=map[m-1].ch && co!=map[m+MAXMAP].ch && co!=map[m-MAXMAP].ch && co!=map[m+MAXMAP+1].ch && co!=map[m+MAXMAP-1].ch && co!=map[m-MAXMAP+1].ch && co!=map[m-MAXMAP-1].ch) { error=ERR_NO_CHAR; return 0; } // the intended victim isnt reachable if (ch[co].flags&(CF_DEAD)) { error=ERR_DEAD; return 0; } if (!can_attack(cn,co)) { error=ERR_ILLEGAL_ATTACK; return 0; } ch[cn].action=AC_ATTACK1+RANDOM(3); ch[cn].act1=co; ch[cn].duration=speed(ch[cn].value[0][V_SPEED],ch[cn].speed_mode,DUR_COMBAT_ACTION); if (ch[cn].speed_mode==SM_FAST) ch[cn].endurance-=end_cost(cn)*2; ch[cn].dir=dir; return 1; }
void cmd_steal(int cn) { int co,x,y,n,cnt,in=0,chance,dice,diff,m; if (!ch[cn].prof[P_THIEF]) { log_char(cn,LOG_SYSTEM,0,"You are not a thief, you cannot steal."); return; } if (ch[cn].action!=AC_IDLE) { log_char(cn,LOG_SYSTEM,0,"You can only steal when standing still."); return; } if (ch[cn].citem) { log_char(cn,LOG_SYSTEM,0,"Please free your hand (mouse cursor) first."); return; } dx2offset(ch[cn].dir,&x,&y,NULL); x+=ch[cn].x; y+=ch[cn].y; if (x<1 || x>=MAXMAP-1 || y<1 || y>=MAXMAP-1) { log_char(cn,LOG_SYSTEM,0,"Out of map."); return; } m=x+y*MAXMAP; co=map[m].ch; if (!co) { log_char(cn,LOG_SYSTEM,0,"There's no one to steal from."); return; } if (!can_attack(cn,co)) { log_char(cn,LOG_SYSTEM,0,"You cannot steal from someone you are not allowed to attack."); return; } if (map[m].flags&(MF_ARENA|MF_CLAN)) { log_char(cn,LOG_SYSTEM,0,"You cannot steal inside an arena."); return; } if (!(ch[co].flags&CF_PLAYER)) { log_char(cn,LOG_SYSTEM,0,"You can only steal from players."); return; } if (ch[co].driver==CDR_LOSTCON) { log_char(cn,LOG_SYSTEM,0,"You cannot steal from lagging players."); return; } if (areaID==20) { log_char(cn,LOG_SYSTEM,0,"You cannot steal in Live Quests."); return; } if (ch[co].action!=AC_IDLE || ticker-ch[co].regen_ticker<TICKS) { log_char(cn,LOG_SYSTEM,0,"You cannot steal from someone if your victim is not standing still."); return; } for (n=cnt=0; n<INVENTORYSIZE; n++) { if (n>=12 && n<30) continue; if ((in=ch[co].item[n]) && !(it[in].flags&IF_QUEST) && can_carry(cn,in,1)) cnt++; } if (!cnt) { log_char(cn,LOG_SYSTEM,0,"You could not find anything to steal."); return; } cnt=RANDOM(cnt); for (n=cnt=0; n<INVENTORYSIZE; n++) { if (n>=12 && n<30) continue; if ((in=ch[co].item[n]) && !(it[in].flags&IF_QUEST) && can_carry(cn,in,1)) { if (cnt<1) break; cnt--; } } if (n==INVENTORYSIZE) { log_char(cn,LOG_SYSTEM,0,"You could not find anything to steal (2)."); return; } diff=(ch[cn].value[0][V_STEALTH]-ch[co].value[0][V_PERCEPT])/2; chance=40+diff; if (chance<10) { log_char(cn,LOG_SYSTEM,0,"You'd get caught for sure. You decide not to try."); return; } chance=min(chance,ch[cn].prof[P_THIEF]*3); dice=RANDOM(100); diff=chance-dice; if (diff<-20) { log_char(cn,LOG_SYSTEM,0,"%s noticed your attempt and stopped you from stealing.",ch[co].name); ch[cn].endurance=1; if (ch[co].flags&CF_PLAYER) { log_char(co,LOG_SYSTEM,0,"°c3%s tried to steal from you!",ch[cn].name); } else notify_char(co,NT_GOTHIT,cn,0,0); return; } dlog(co,in,"dropped because %s stole it",ch[cn].name); remove_item_char(in); if (!give_char_item(cn,in)) { destroy_item(in); elog("had to destroy item in cmd_steal()!"); return; } add_pk_steal(cn); if (diff<0) { log_char(cn,LOG_SYSTEM,0,"%s noticed your theft, but you managed to steal a %s anyway.",ch[co].name,it[in].name); ch[cn].endurance=1; if (ch[co].flags&CF_PLAYER) { log_char(co,LOG_SYSTEM,0,"°c3%s stole your %s!",ch[cn].name,it[in].name); } else notify_char(co,NT_GOTHIT,cn,0,0); } else log_char(cn,LOG_SYSTEM,0,"You stole a %s without %s noticing.",it[in].name,ch[co].name); }