📄 directive.cpp
字号:
throw("DirectiveSetManager::createDirectiveSet() : Out of bounds!"); } // 捞傈狼 DirectiveSet阑 昏力窍绊, 货 巴阑 父电促. if (m_ppSet[index]==NULL) // by sigi. 2002.9.26 { //SAFE_DELETE(m_ppSet[index]); m_ppSet[index] = new DirectiveSet; } else { // 扁粮俊 乐带霸 乐促搁.. 瘤款促. m_ppSet[index]->clear(); } m_ppSet[index]->setName(name); string beginToken = "DIRECTIVE BEGIN"; string endToken = "DIRECTIVE END"; uint start = 0; uint end = 0; while (end < text.size() - 1) { //////////////////////////////////////////////////////////// // ex) // DIRECTIVE BEGIN // (CONDITION:ImDying) // (ACTION:Flee) // DIRECTIVE END // DIRECTIVE BEGIN // (CONDITION:EnemyRangeMelee) // (CONDITION:EnemyDying) // (CONDITION:EnemyNotBloodDrained) // (ACTION:UseSkill,BloodDrain,30) // DIRECTIVE END //////////////////////////////////////////////////////////// start = text.find(beginToken, end); end = text.find(endToken, start+1); if (start > end) break; Directive* pDirective = new Directive; string directive = trim(text.substr(start+beginToken.size()+1, end-start-beginToken.size()-1)); Assert(pDirective != NULL); uint i = 0, j = 0, k = 0; while (k < directive.size()) { // Directive甫 备己窍绰 咀记捞唱 牧叼记 吝狼 // 窍唱甫 佬绢甸牢促. i = directive.find_first_of('(', k); j = directive.find_first_of(':', i+1); k = directive.find_first_of(')', j+1); // 巩磊凯狼 场阑 檬苞沁促搁, 颇教阑 吝窜茄促. if (i > j || j > k) break; // identifier绰 咀记捞衬, 牧叼记捞衬狼 咯何. // parameter绰 弊 第俊 蝶扼坷绰 牢荐捞促. string identifier = directive.substr(i+1, j-i-1); string parameter = directive.substr(j+1, k-j-1); if (identifier == "CONDITION") { parseDirectiveParameter(pDirective, parameter, MODE_CONDITION); } else if (identifier == "ACTION") { parseDirectiveParameter(pDirective, parameter, MODE_ACTION); } else { cerr << "DirectiveSetManager::createDirectiveSet() : 舅 荐 绝绰 IDENTIFIER" << endl; throw ("DirectiveSetManager::createDirectiveSet() : 舅 荐 绝绰 IDENTIFIER"); } } m_ppSet[index]->addDirective(pDirective); } // 磷菌阑 锭 窍绰 青悼阑 佬绢甸牢促. 5鄂 箭磊俊 奴 狼固绰 绝促. // 酒公 青悼档 窍瘤 臼阑 锭绰 焊烹 0捞瘤父, 公攫啊 咀记捞 甸绢啊搁 // 辨捞啊 措碍 50篮 登府扼绊 积阿篮 窍绰单... 窍扛瓢 咀记捞 绝绰 // 版快俊绰 佬绢甸捞瘤 臼扁 困秦辑, 窍绰 八荤促. -- 辫己刮 if (deadtext.size() > 5) { start = 0; end = 0; while (end < deadtext.size() - 1) { //////////////////////////////////////////////////////////// // ex) // DIRECTIVE BEGIN // (CONDITION:ImDying) // (ACTION:Flee) // DIRECTIVE END // DIRECTIVE BEGIN // (CONDITION:EnemyRangeMelee) // (CONDITION:EnemyDying) // (CONDITION:EnemyNotBloodDrained) // (ACTION:UseSkill,BloodDrain,30) // DIRECTIVE END //////////////////////////////////////////////////////////// start = deadtext.find(beginToken, end); end = deadtext.find(endToken, start+1); if (start > end) break; Directive* pDirective = new Directive; string directive = trim(deadtext.substr(start+beginToken.size()+1, end-start-beginToken.size()-1)); Assert(pDirective != NULL); uint i = 0, j = 0, k = 0; while (k < directive.size()) { // Directive甫 备己窍绰 咀记捞唱 牧叼记 吝狼 // 窍唱甫 佬绢甸牢促. i = directive.find_first_of('(', k); j = directive.find_first_of(':', i+1); k = directive.find_first_of(')', j+1); // 巩磊凯狼 场阑 檬苞沁促搁, 颇教阑 吝窜茄促. if (i > j || j > k) break; // identifier绰 咀记捞衬, 牧叼记捞衬狼 咯何. // parameter绰 弊 第俊 蝶扼坷绰 牢荐捞促. string identifier = directive.substr(i+1, j-i-1); string parameter = directive.substr(j+1, k-j-1); if (identifier == "CONDITION") { parseDirectiveParameter(pDirective, parameter, MODE_CONDITION); } else if (identifier == "ACTION") { parseDirectiveParameter(pDirective, parameter, MODE_ACTION); } else { cerr << "DirectiveSetManager::createDirectiveSet() : 舅 荐 绝绰 IDENTIFIER" << endl; throw ("DirectiveSetManager::createDirectiveSet() : 舅 荐 绝绰 IDENTIFIER"); } } m_ppSet[index]->addDeadDirective(pDirective); } } m_ppSet[index]->setAttackAir( m_ppSet[index]->hasCondition( DIRECTIVE_COND_ENEMY_ON_AIR ) ); m_ppSet[index]->setSeeSafeZone( m_ppSet[index]->hasCondition( DIRECTIVE_COND_ENEMY_ON_SAFE_ZONE ) ); if ( m_ppSet[index]->canSeeSafeZone() ) cout << index << " : can see safe zone" << endl; __END_CATCH}////////////////////////////////////////////////////////////////////////// parseDirectiveParameter()// 巩磊凯阑 颇教秦辑, 牧叼记捞唱 咀记阑 父甸绢 Directive俊 技泼茄促.////////////////////////////////////////////////////////////////////////void DirectiveSetManager::parseDirectiveParameter(Directive* pDirective, const string& text, int mode) throw(){ __BEGIN_TRY uint oldpos = 0; uint pos = 0; uint paramCount = 0; while (oldpos < text.size() && pos < text.size()) { // 楷加等 颇扼固磐绰 ","肺 备盒等促. oldpos = pos; pos = text.find_first_of(',', oldpos); // 牧叼记 鞍篮 版快俊绰 颇扼固磐啊 窍唱捞扁 锭巩俊 // ","甫 茫栏搁 钙胶 蔼捞 公炼扒 唱柯促. // 捞吧肺绰 辑宏胶飘傅 窃荐甫 力措肺 何甫 荐啊 // 绝扁 锭巩俊 巩磊凯狼 辨捞肺 pos 蔼阑 技泼秦霖促. if (pos == string::npos) pos = text.size(); pos++; string token = text.substr(oldpos, (pos-1)-oldpos); switch (mode) { case MODE_CONDITION: if (paramCount != 0) { cerr << "DirectiveSetManager::parseParameter() : There's two or more parameters in condition" << endl; cerr << "ParsingText: " << text.c_str() << endl; throw("DirectiveSetManager::parseParameter() : There's two or more parameters in condition"); } pDirective->addCondition(getCondition(token)); break; case MODE_ACTION: if (paramCount == 0) pDirective->setAction(getAction(token)); else if (paramCount == 1) { switch (pDirective->getAction()) { case DIRECTIVE_ACTION_USE_SKILL : pDirective->setParameter(getParameter(token)); break; case DIRECTIVE_ACTION_CHANGE_ENEMY : case DIRECTIVE_ACTION_MOVE_RANDOM : pDirective->setParameter(atoi(token.c_str())); break; default : cerr << "DirectiveSetManager::parseParameter() : There's two or more parameters in condition" << endl; cerr << "ParsingText: " << text.c_str() << endl; throw Error("No Need Parameter!"); } //////////////// //if (pDirective->getAction() == DIRECTIVE_ACTION_USE_SKILL) //{ // filelog("Directive.txt", "%s", token.c_str()); //} //////////////// } else if (paramCount == 2) pDirective->setRatio(getRatio(token)); break; default: break; } paramCount++; } __END_CATCH}////////////////////////////////////////////////////////////////////////// getCondition()// 巩磊凯阑 罐酒 弊俊 秦寸窍绰 牧叼记 惑荐甫 府畔茄促.////////////////////////////////////////////////////////////////////////int DirectiveSetManager::getCondition(const string& token) throw(){ __BEGIN_TRY for (int i=0; i<DIRECTIVE_COND_MAX; i++) if (DirectiveCondition2String[i] == token) return i; StringStream msg; msg << "DirectiveSetManager::getCondition() : Invalid condition string[" << token << "]"; cerr << msg.toString() << endl; throw(msg.toString()); return DIRECTIVE_COND_MAX; __END_CATCH}////////////////////////////////////////////////////////////////////////// getAction()// 巩磊凯阑 罐酒 弊俊 秦寸窍绰 咀记 惑荐甫 府畔茄促.////////////////////////////////////////////////////////////////////////int DirectiveSetManager::getAction(const string& token) throw(){ __BEGIN_TRY for (int i=0; i<DIRECTIVE_ACTION_MAX; i++) if (DirectiveAction2String[i] == token) return i; cerr << "DirectiveSetManager::getAction() : Invalid action[" << token << "]" << endl; throw("DirectiveSetManager::getAction() : Invalid action"); return DIRECTIVE_COND_MAX; __END_CATCH}////////////////////////////////////////////////////////////////////////// getParameter()// 巩磊凯阑 罐酒 弊俊 秦寸窍绰 颇扼固磐甫 府畔茄促.// 泅犁肺辑绰 阁胶磐啊 荤侩窍绰 胶懦 鸥涝 挥捞促.////////////////////////////////////////////////////////////////////////int DirectiveSetManager::getParameter(const string& token) throw(){ __BEGIN_TRY for (int i=0; i<SKILL_MAX; i++) { if (strcasecmp(token.c_str(), SkillTypes2String[i].c_str()) == 0) return i; } cerr << "DirectiveSetManager::getParameter() : Invalid parameter[" << token << "]" << endl; throw("DirectiveSetManager::getParameter() : Invalid parameter"); return 0; __END_CATCH}////////////////////////////////////////////////////////////////////////// getRatio()// 巩磊凯阑 罐酒 弊俊 秦寸窍绰 犬伏蔼阑 府畔茄促. 归盒啦捞促.////////////////////////////////////////////////////////////////////////int DirectiveSetManager::getRatio(const string& token) throw(){ __BEGIN_TRY int rValue = atoi(token.c_str()); if (rValue < 0 || rValue > 100) { cerr << "DirectiveSetManager::getRatio() : Invalid ratio value" << endl; throw ("DirectiveSetManager::getRatio() : Invalid ratio value"); } return rValue; __END_CATCH}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -