actionwander.cpp
来自「dk1游戏的原代码文件,完整.编译系统redhat7.3,mysql 3.23 」· C++ 代码 · 共 159 行
CPP
159 行
////////////////////////////////////////////////////////////////////////////////// Filename : ActionWander.cpp// Written By : // Description :////////////////////////////////////////////////////////////////////////////////#include "ActionWander.h"#include "Creature.h"#include "NPC.h"#include "Utility.h"static const POINT d [] = { POINT(-1, 0), // 0 == LEFT POINT(-1, 1), // 1 == LEFTDOWN POINT(0, 1), // 2 == DOWN POINT(1, 1), // 3 == RIGHTDOWN POINT(1, 0), // 4 == RIGHT POINT(1,-1), // 5 == RIGHTUP POINT(0,-1), // 6 == UP POINT(-1,-1), // 7 == LEFTUP};////////////////////////////////////////////////////////////////////////////////// read from PropertyBuffer////////////////////////////////////////////////////////////////////////////////void ActionWander::read (PropertyBuffer & propertyBuffer) throw (Error){ __BEGIN_TRY try { m_X = propertyBuffer.getPropertyInt("X"); m_Y = propertyBuffer.getPropertyInt("Y"); m_Radius = propertyBuffer.getPropertyInt("Radius"); m_MovePercentage = propertyBuffer.getPropertyInt("MovePercentage"); Assert(m_MovePercentage <= 100); } catch (NoSuchElementException & nsee) { throw Error(nsee.toString()); } __END_CATCH}////////////////////////////////////////////////////////////////////////////////// 咀记阑 角青茄促.////////////////////////////////////////////////////////////////////////////////void ActionWander::execute (Creature * pCreature1 , Creature * pCreature2) throw (Error){ __BEGIN_TRY Assert(pCreature1 != NULL); Assert(pCreature2 == NULL); Assert(pCreature1->isNPC() || pCreature1->isMonster()); // 捞锅 畔俊 框流老 巴牢瘤 眉农茄促. uint diceResult = Dice(1,100); if (diceResult < m_MovePercentage) { bool movableDir[8]; uint movableDirCount = 0; ZoneCoord_t cx = pCreature1->getX(); ZoneCoord_t cy = pCreature1->getY(); ZoneCoord_t nx = 0; ZoneCoord_t ny = 0; // 框流捞扁肺 沁促搁, 绢蠢 规氢栏肺 框流老 巴牢瘤 眉农茄促. // 老窜 哎 荐 乐绰 规氢狼 格废何磐 累己茄促. for (uint i = 0 ; i < 8 ; i ++) { nx = cx + d[i].x; ny = cy + d[i].y; // 促澜 档馒 瘤痢篮 (x,y,r) 康开 救俊 粮犁窍搁辑, // NPC啊 框流老 荐 乐绰 - 喉遏登瘤 臼篮 - 鸥老捞绢具 茄促. if (max(abs(m_X-nx),abs(m_Y-ny)) <= m_Radius && pCreature1->canMove(nx,ny)) { movableDir[i] = true; movableDirCount++; } else { movableDir[i] = false; } } // 父距 泅犁 困摹俊辑 框流老 荐 绝促搁, 沥瘤茄促. // 框流老 荐 乐促搁.. 框流牢促. if (movableDirCount > 0) { Dir_t nextDir = pCreature1->getDir(); bool changeDir = false; if ( movableDir[nextDir] ) { if ( rand() % 10 == 0 ) changeDir = true; } else { changeDir = true; } if ( changeDir ) { uint j = rand() % movableDirCount + 1; uint k = 0; // movableDir[l] == true 牢 规氢狼 牢郸胶 for (uint l = 0 ; l < 8 ; l ++) { if (movableDir[l] && ++k == j) { nextDir = l; break; } } } nx = cx + d[nextDir].x; ny = cy + d[nextDir].y; // move creature Zone * pZone = pCreature1->getZone(); pZone->moveCreature(pCreature1 , nx , ny , nextDir); } } __END_CATCH}////////////////////////////////////////////////////////////////////////////////// get debug string////////////////////////////////////////////////////////////////////////////////string ActionWander::toString () const throw (){ __BEGIN_TRY StringStream msg; msg << "ActionWander(" << " X:" << (int)m_X << " ,Y:" << (int)m_Y << " ,Radius:" << (int)m_Radius << " ,MovePercentage:" << (int)m_MovePercentage << ")"; return msg.toString(); __END_CATCH}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?