void MonsterGenerator::load_monster_attack( JsonObject &jo, const std::string &src ) { add_attack( create_actor( jo, src ) ); }
void MonsterGenerator::add_hardcoded_attack( const std::string &type, const mon_action_attack f ) { add_attack( mtype_special_attack( type, f ) ); }
void MonsterGenerator::add_attack( mattack_actor *ptr ) { add_attack( mtype_special_attack( ptr ) ); }
void attack_init() { int delta, inc; int piece; int dir, dist; int size; int king; int from, to; int pos; // clear for (delta = 0; delta < DeltaNb; delta++) { DeltaIncLine[delta] = IncNone; DeltaIncAll[delta] = IncNone; DeltaMask[delta] = 0; } for (inc = 0; inc < IncNb; inc++) { IncMask[inc] = 0; } // pawn attacks DeltaMask[DeltaOffset-17] |= BlackPawnFlag; DeltaMask[DeltaOffset-15] |= BlackPawnFlag; DeltaMask[DeltaOffset+15] |= WhitePawnFlag; DeltaMask[DeltaOffset+17] |= WhitePawnFlag; // knight attacks for (dir = 0; dir < 8; dir++) { delta = KnightInc[dir]; ASSERT(delta_is_ok(delta)); ASSERT(DeltaIncAll[DeltaOffset+delta]==IncNone); DeltaIncAll[DeltaOffset+delta] = delta; DeltaMask[DeltaOffset+delta] |= KnightFlag; } // bishop/queen attacks for (dir = 0; dir < 4; dir++) { inc = BishopInc[dir]; ASSERT(inc!=IncNone); IncMask[IncOffset+inc] |= BishopFlag; for (dist = 1; dist < 8; dist++) { delta = inc*dist; ASSERT(delta_is_ok(delta)); ASSERT(DeltaIncLine[DeltaOffset+delta]==IncNone); DeltaIncLine[DeltaOffset+delta] = inc; ASSERT(DeltaIncAll[DeltaOffset+delta]==IncNone); DeltaIncAll[DeltaOffset+delta] = inc; DeltaMask[DeltaOffset+delta] |= BishopFlag; } } // rook/queen attacks for (dir = 0; dir < 4; dir++) { inc = RookInc[dir]; ASSERT(inc!=IncNone); IncMask[IncOffset+inc] |= RookFlag; for (dist = 1; dist < 8; dist++) { delta = inc*dist; ASSERT(delta_is_ok(delta)); ASSERT(DeltaIncLine[DeltaOffset+delta]==IncNone); DeltaIncLine[DeltaOffset+delta] = inc; ASSERT(DeltaIncAll[DeltaOffset+delta]==IncNone); DeltaIncAll[DeltaOffset+delta] = inc; DeltaMask[DeltaOffset+delta] |= RookFlag; } } // king attacks for (dir = 0; dir < 8; dir++) { delta = KingInc[dir]; ASSERT(delta_is_ok(delta)); DeltaMask[DeltaOffset+delta] |= KingFlag; } // PieceCode[] for (piece = 0; piece < PieceNb; piece++) { PieceCode[piece] = -1; } PieceCode[WN] = 0; PieceCode[WB] = 1; PieceCode[WR] = 2; PieceCode[WQ] = 3; PieceCode[BN] = 0; PieceCode[BB] = 1; PieceCode[BR] = 2; PieceCode[BQ] = 3; // PieceDeltaSize[][] & PieceDeltaDelta[][][] for (piece = 0; piece < 4; piece++) { for (delta = 0; delta < 256; delta++) { PieceDeltaSize[piece][delta] = 0; } } for (king = 0; king < SquareNb; king++) { if (SQUARE_IS_OK(king)) { for (from = 0; from < SquareNb; from++) { if (SQUARE_IS_OK(from)) { // knight for (pos = 0; (inc=KnightInc[pos]) != IncNone; pos++) { to = from + inc; if (SQUARE_IS_OK(to) && DISTANCE(to,king) == 1) { add_attack(0,king-from,to-from); } } // bishop for (pos = 0; (inc=BishopInc[pos]) != IncNone; pos++) { for (to = from+inc; SQUARE_IS_OK(to); to += inc) { if (DISTANCE(to,king) == 1) { add_attack(1,king-from,to-from); break; } } } // rook for (pos = 0; (inc=RookInc[pos]) != IncNone; pos++) { for (to = from+inc; SQUARE_IS_OK(to); to += inc) { if (DISTANCE(to,king) == 1) { add_attack(2,king-from,to-from); break; } } } // queen for (pos = 0; (inc=QueenInc[pos]) != IncNone; pos++) { for (to = from+inc; SQUARE_IS_OK(to); to += inc) { if (DISTANCE(to,king) == 1) { add_attack(3,king-from,to-from); break; } } } } } } } for (piece = 0; piece < 4; piece++) { for (delta = 0; delta < 256; delta++) { size = PieceDeltaSize[piece][delta]; ASSERT(size>=0&&size<3); PieceDeltaDelta[piece][delta][size] = DeltaNone; } } }