/*Add legal Moves for Bishop/Rook/Queen/King at Location to Linked List*/ int getBRQKMoves(Game *game, Location *loc, ListNode *temp){ int killflag, blockedflag, i, j, dist, len; int flag = 0; MoveType type; MoveType *list = getMoveTypeList(game->board, loc); len = getMoveTypeListLength(game->board, loc); for (i = 0; i < len; i++){ killflag = 0; blockedflag = 0; type = list[i]; dist = distFrom(game->board, loc, type); if (isKing(game->board, loc) && dist>0){ dist = 1; } for (j = 1; j <= dist&&!killflag&&!blockedflag; j++){ Location *tLoc = setLocation(loc->column + shiftCol(game->board, loc, type)*j, loc->row + shiftRow(game->board, loc, type)*j); if (legalMoveToKing(game, loc, tLoc)){ Move *move = setMove(loc, tLoc, NONETYPE); if (isValidMove(game, move)){ addMoveToList(temp, move); flag = 1; } else{ freeMove(move); } } else{ free(tLoc); } } } return flag; }
/*! \author Luxor */ void cChar::walk() { pChar pc_att = cSerializable::findCharBySerial( attackerserial ); if ( !pc_att ) pc_att = cSerializable::findCharBySerial( targserial ); if ( !pc_att ) war = 0; if ( war && npcWander != cNPC::WANDER_FLEE && ( pc_att->IsOnline() || pc_att->npc ) ) { //We are following a combat target follow( pc_att ); return; } switch( npcWander ) { case cNPC::WANDER_NOMOVE: //No movement break; case cNPC::WANDER_FOLLOW: //Follow the follow target { pChar pc = cSerializable::findCharBySerial( ftargserial ); if ( !pc ) break; if ( pc->isDead() ) break; if ( pc->questDestRegion == region ) ((pNPC)this)->clearedEscordQuest( (pPC) pc ); follow( pc ); } break; case cNPC::WANDER_FREELY_CIRCLE: // Wander freely, in a defined circle npcwalk( this, (chance( 20 ) ? rand()%8 : dir), 2 ); break; case cNPC::WANDER_FREELY_BOX: // Wander freely, within a defined box npcwalk( this, (chance( 20 ) ? rand()%8 : dir), 1 ); break; case cNPC::WANDER_FREELY: // Wander freely, avoiding obstacles npcwalk( this, (chance( 20 ) ? rand()%8 : dir), 0 ); break; case cNPC::WANDER_FLEE: //FLEE!!!!!! { pChar target = cSerializable::findCharBySerial( targserial ); if ( target ) { if ( distFrom( target ) < VISRANGE ) getDirFromXY( target->getBody()->getPosition() ); npcwalk( this, npcSelectDir( this, getDirFromXY(target->getBody()->getPosition()) +4 ), 0); } } break; case cNPC::WANDER_AMX: // Sparhawk: script controlled movement { uint32_t l = dir; pFunctionHandle evt = getEvent(cChar::evtChrOnWalk); if( evt ) { cVariantVector params = cVariantVector(3); params[0] = pc->getSerial(); params[1] = dir; params[2] = dir; evt->setParams(params); evt->execute(); if( evt->isBypassed() ) return; } int k = dir; dir = l; l = npcmovetime; npcwalk( this, k, 0); if ( l != npcmovetime ) // it's been changed through small return; } break; default: LogError("Unknown npcwander [serial %u]\n", getSerial()); break; } setNpcMoveTime(); }