From fa19cb0f6d9233f681287d7d9e1294d50741d798 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 18 Dec 2015 18:07:11 +0100 Subject: [PATCH] Merge with develop --- code/ryzom/server/src/ai_service/ai_bot.cpp | 13 +++++ code/ryzom/server/src/ai_service/ai_bot.h | 14 +++++ .../src/ai_service/ai_generic_fight.cpp | 25 ++++++++- .../ai_service/ai_generic_fight_helpers.cpp | 6 +- .../server/src/ai_service/ai_instance.cpp | 37 +++++++++++- code/ryzom/server/src/ai_service/commands.cpp | 29 ++++++++++ code/ryzom/server/src/ai_service/messages.cpp | 56 ++++++++++++++++++- .../server/src/ai_service/nf_grp_npc.cpp | 12 ++-- 8 files changed, 181 insertions(+), 11 deletions(-) diff --git a/code/ryzom/server/src/ai_service/ai_bot.cpp b/code/ryzom/server/src/ai_service/ai_bot.cpp index 4950ebd29..2fb47023a 100644 --- a/code/ryzom/server/src/ai_service/ai_bot.cpp +++ b/code/ryzom/server/src/ai_service/ai_bot.cpp @@ -370,6 +370,7 @@ CBot::CBot(CGroup* owner, CAIAliasDescriptionNode* alias) : CAliasChild(owner, alias) , _VerticalPos(AITYPES::vp_auto) , _Sheet(NULL) +, _ClientCSheet(NULL) , _Stuck(false) , _IgnoreOffensiveActions(false) , _Healer(false) @@ -384,6 +385,7 @@ CBot::CBot(CGroup* owner, uint32 alias, std::string const& name) : CAliasChild(owner,alias, name) , _VerticalPos(AITYPES::vp_auto) , _Sheet(NULL) +, _ClientCSheet(NULL) , _Stuck(false) , _IgnoreOffensiveActions(false) , _Healer(false) @@ -695,6 +697,17 @@ void CBot::setClientSheet(const std::string & clientSheetName) nlwarning("Invalid CLIENT_SHEET %s", clientSheetName.c_str()); return; } + + AISHEETS::ICreatureCPtr sheet = AISHEETS::CSheets::getInstance()->lookup(NLMISC::CSheetId(clientSheetName)); + + if (!sheet || sheet->SheetId() == NLMISC::CSheetId::Unknown) + { + nlwarning("Unknown sheet %s", clientSheetName.c_str()); + return; + } + + _ClientCSheet = sheet; + sheetChanged(); } } diff --git a/code/ryzom/server/src/ai_service/ai_bot.h b/code/ryzom/server/src/ai_service/ai_bot.h index f016d943c..9810dcd41 100644 --- a/code/ryzom/server/src/ai_service/ai_bot.h +++ b/code/ryzom/server/src/ai_service/ai_bot.h @@ -181,6 +181,19 @@ public: /// @name AI objects hierarchy access //@{ CAIInstance* getAIInstance() const; + + AISHEETS::ICreatureCPtr getClientCSheet() const + { + if (_ClientSheet != NLMISC::CSheetId::Unknown && _ClientCSheet) + return _ClientCSheet; + return _Sheet; + } + + NLMISC::CSheetId getClientSheet() const + { + return _ClientSheet; + } + CGroup& getGroup() { return *getOwner(); } CAliasTreeOwner const* getAliasTreeOwner() const { return this; } CSpawnBot* getSpawnObj() const; @@ -270,6 +283,7 @@ protected: private: AISHEETS::ICreatureCPtr _Sheet; + AISHEETS::ICreatureCPtr _ClientCSheet; NLMISC::CSheetId _ClientSheet; bool _Stuck; bool _IgnoreOffensiveActions; diff --git a/code/ryzom/server/src/ai_service/ai_generic_fight.cpp b/code/ryzom/server/src/ai_service/ai_generic_fight.cpp index f4c9a5cb0..fb8235063 100644 --- a/code/ryzom/server/src/ai_service/ai_generic_fight.cpp +++ b/code/ryzom/server/src/ai_service/ai_generic_fight.cpp @@ -514,6 +514,8 @@ bool CFightOrganizer::reorganizeIteration(CBot* bot) CAIVector movingVector; double fear=1.0f; + CAIEntityPhysical* target = (CAIEntityPhysical*)spawnBot->getTarget(); + FOREACH(it, std::vector, botList) { CAIEntityPhysical *const entity=(*it); @@ -565,6 +567,27 @@ bool CFightOrganizer::reorganizeIteration(CBot* bot) float score = (float)(entity->_AggroScore*slotCoef); + if (target && target->getRyzomType() == RYZOMID::player) + { + if (entity != target) + { + CBotPlayer const* const ptarget = NLMISC::safe_cast(target); + if (entity->getRyzomType() == RYZOMID::player) + { + CBotPlayer const* const player = NLMISC::safe_cast(entity); + if ( ptarget && player && spawnBot->getAggroFor(entity->dataSetRow()) <= spawnBot->getAggroFor(ptarget->dataSetRow()) && ( + ptarget->getCurrentTeamId() == CTEAM::InvalidTeamId || + player->getCurrentTeamId() == CTEAM::InvalidTeamId || + player->getCurrentTeamId() != ptarget->getCurrentTeamId() + ) + ) + { + score = 0; + } + } + } + } + if (score>=BestChooseScore) // add distance and bot profile compatibility. { BestChooseScore=score; @@ -583,7 +606,7 @@ bool CFightOrganizer::reorganizeIteration(CBot* bot) { _HaveEnnemy=true; nlassert(ennemy->getRyzomType()!=debugCheckedType); - if (((CAIEntityPhysical*)spawnBot->getTarget())==ennemy) + if (target == ennemy) { return true; } diff --git a/code/ryzom/server/src/ai_service/ai_generic_fight_helpers.cpp b/code/ryzom/server/src/ai_service/ai_generic_fight_helpers.cpp index 18e779d1d..4b655422c 100644 --- a/code/ryzom/server/src/ai_service/ai_generic_fight_helpers.cpp +++ b/code/ryzom/server/src/ai_service/ai_generic_fight_helpers.cpp @@ -277,7 +277,11 @@ static void s_calcRanges( _RangeMax = CBotProfileFightHeal::fightRangeMaxRange; } } - _RangeMax += _Bot->getPersistent().getSheet()->Radius() * _Bot->getPersistent().getSheet()->Scale(); + if (_Bot->getPersistent().getClientSheet() != NLMISC::CSheetId::Unknown && _Bot->getPersistent().getClientCSheet()) + _RangeMax += _Bot->getPersistent().getClientCSheet()->Radius() * _Bot->getPersistent().getClientCSheet()->Scale(); + else + _RangeMax += _Bot->getPersistent().getSheet()->Radius() * _Bot->getPersistent().getSheet()->Scale(); + _RangeCalculated = true; } diff --git a/code/ryzom/server/src/ai_service/ai_instance.cpp b/code/ryzom/server/src/ai_service/ai_instance.cpp index 2b46e20ca..ef7c4aea9 100644 --- a/code/ryzom/server/src/ai_service/ai_instance.cpp +++ b/code/ryzom/server/src/ai_service/ai_instance.cpp @@ -31,6 +31,7 @@ using namespace std; using namespace NLMISC; +using namespace NLNET; using namespace MULTI_LINE_FORMATER; CAIInstance::CAIInstance(CAIS* owner) @@ -694,6 +695,11 @@ CGroupNpc* CAIInstance::eventCreateNpcGroup(uint nbBots, NLMISC::CSheetId const& bot->equipmentInit(); bot->initEnergy(/*groupEnergyCoef()*/0); CAIVector rpos(pos); + if (dispersionRadius == 0) + { + nlinfo("Stucked !"); + bot->setStuck(true); + } // Spawn all randomly except if only 1 bot if (nbBots > 1) { @@ -853,6 +859,7 @@ void cbEventCreateNpcGroup( NLNET::CMessage& msgin, const std::string &serviceNa uint32 instanceNumber; sint32 x; sint32 y; + sint32 z; sint32 orientation; uint32 nbBots; NLMISC::CSheetId sheetId; @@ -861,12 +868,14 @@ void cbEventCreateNpcGroup( NLNET::CMessage& msgin, const std::string &serviceNa bool spawnBots; std::string botsName; std::string look; + sint32 cell; msgin.serial(messageVersion); nlassert(messageVersion==1); msgin.serial(instanceNumber); msgin.serial(playerId); msgin.serial(x); msgin.serial(y); + msgin.serial(z); msgin.serial(orientation); msgin.serial(nbBots); msgin.serial(sheetId); @@ -874,13 +883,39 @@ void cbEventCreateNpcGroup( NLNET::CMessage& msgin, const std::string &serviceNa msgin.serial(spawnBots); msgin.serial(botsName); msgin.serial(look); + msgin.serial(cell); CAIInstance* instance = CAIS::instance().getAIInstance(instanceNumber); if (instance) { - CGroupNpc* npcGroup = instance->eventCreateNpcGroup(nbBots, sheetId, CAIVector((double)x/1000., (double)y/1000.), dispersionRadius, spawnBots, (double)orientation/1000., botsName, look); + CGroupNpc* npcGroup = instance->eventCreateNpcGroup(nbBots, sheetId, CAIVector(((double)x)/1000.0, ((double)y)/1000.0), dispersionRadius, spawnBots, ((double)orientation)/1000.0, botsName, look); if (npcGroup != NULL) { _PlayersLastCreatedNpcGroup[playerId] = npcGroup->getName(); + + FOREACH(botIt, CCont, npcGroup->bots()) + { + CSpawnBot* pbot = botIt->getSpawnObj(); + if (pbot!=NULL) + { + CEntityId id = pbot->getEntityId(); + float t = 0; + uint8 cont = 0; + uint8 one = 1; + NLMISC::TGameCycle tick = CTickEventHandler::getGameCycle() + 1; + CMessage msgout2("ENTITY_TELEPORTATION"); + msgout2.serial( id ); + msgout2.serial( x ); + msgout2.serial( y ); + msgout2.serial( z ); + msgout2.serial( t ); + msgout2.serial( tick ); + msgout2.serial( cont ); + msgout2.serial( cell ); + msgout2.serial( one ); + + sendMessageViaMirror("GPMS", msgout2); + } + } } } } diff --git a/code/ryzom/server/src/ai_service/commands.cpp b/code/ryzom/server/src/ai_service/commands.cpp index 52315372a..f44380cc3 100644 --- a/code/ryzom/server/src/ai_service/commands.cpp +++ b/code/ryzom/server/src/ai_service/commands.cpp @@ -1665,6 +1665,35 @@ bool execScriptGroupByName(CStringWriter& stringWriter, TCommand const& args) return true; } +NLMISC_COMMAND(getDatasetId,"get datasetid of bots with name matchiong the given filter", "") +{ + if (args.size()!=1) + return false; + + string const& botName = args[0]; + string DatasetIds; + + vector bots; + /// try to find the bot name + buildFilteredBotList(bots, botName); + if (bots.empty()) + { + log.displayNL("ERR: No bot correspond to name %s", botName.c_str()); + return false; + } + else + { + FOREACH(itBot, vector, bots) + { + CBot* bot = *itBot; + DatasetIds += bot->getSpawnObj()->dataSetRow().toString()+"|"; + + } + } + log.displayNL("%s", DatasetIds.c_str()); + return true; +} + NLMISC_COMMAND(script,"execute a script for groups matching the given filter [buffered]"," ") { clearBufferedRetStrings(); diff --git a/code/ryzom/server/src/ai_service/messages.cpp b/code/ryzom/server/src/ai_service/messages.cpp index 3f05236b3..809320de4 100644 --- a/code/ryzom/server/src/ai_service/messages.cpp +++ b/code/ryzom/server/src/ai_service/messages.cpp @@ -984,12 +984,64 @@ void CBSAIDeathReport::callback(const std::string &name, NLNET::TServiceId id) CBotNpc* bot = NLMISC::safe_cast(&(sb->getPersistent())); spawnGrp.botHaveDied (bot); bot->notifyBotDeath(); - + + std::string eventBotKilled; + if (spawnGrp.getProfileParameter("event_bot_killed", eventBotKilled) && !eventBotKilled.empty()) + { + nlinfo("NPC: TRIGGER EVENT BOT KILLED"); + } spawnGrp.getPersistent().processStateEvent(mgr.EventBotKilled); - if (!spawnGrp.isGroupAlive(0*1)) + std::string eventGroupKilled; + if (!spawnGrp.isGroupAlive(0*1)) + { + if (spawnGrp.getProfileParameter("event_group_killed", eventGroupKilled) && !eventGroupKilled.empty()) + { + nlinfo("NPC: TRIGGER EVENT GROUP KILLED"); + } spawnGrp.getPersistent().processStateEvent(mgr.EventGrpEliminated); + } + + if (!eventBotKilled.empty() || !eventGroupKilled.empty()) + { + CSpawnBot *const spBot = static_cast(phys); + // make a vector of aggroable player + CBotAggroOwner::TBotAggroList const& aggroList = spBot->getBotAggroList(); + //typedef std::map TBotAggroList; + CBotAggroOwner::TBotAggroList::const_iterator aggroIt(aggroList.begin()), aggroEnd(aggroList.end()); + TDataSetRow foundRow = TDataSetRow(); + + std::vector playerAggroable; + for (; aggroIt != aggroEnd; ++aggroIt) + { + if (CMirrors::getEntityId(aggroIt->first).getType() != RYZOMID::player) + continue; + CAIEntityPhysical* ep = CAIS::instance().getEntityPhysical(aggroIt->first); + if (!ep) + continue; + CBotPlayer const* const player = NLMISC::safe_cast(ep); + if (!player) + continue; + if (!player->isAggroable()) + continue; + playerAggroable.push_back(aggroIt->first); + } + + NLNET::CMessage msgout("TRIGGER_WEBIG"); + if (!eventBotKilled.empty()) + msgout.serial(eventBotKilled); + else + msgout.serial(eventGroupKilled); + + uint32 nbPlayers = (uint32)playerAggroable.size(); + msgout.serial(nbPlayers); + for (uint32 i = 0; i < nbPlayers; i++) + { + msgout.serial(playerAggroable[i]); + } + sendMessageViaMirror("EGS", msgout); + } } break; case RYZOMID::creature: diff --git a/code/ryzom/server/src/ai_service/nf_grp_npc.cpp b/code/ryzom/server/src/ai_service/nf_grp_npc.cpp index 88dc8f5b6..dbe005544 100644 --- a/code/ryzom/server/src/ai_service/nf_grp_npc.cpp +++ b/code/ryzom/server/src/ai_service/nf_grp_npc.cpp @@ -1482,14 +1482,14 @@ void setPlayerController_ss_(CStateInstance* entity, CScriptStack& stack) CAIEntityPhysical *botEntity = inst->getEntity(botId); if (botEntity) { - if ((bot = dynamic_cast(botEntity)) - && (&bot->getPersistent().getGroup())==entity->getGroup()) + if ((bot = dynamic_cast(botEntity)) && (&bot->getPersistent().getGroup())==entity->getGroup()) { - CBotPlayer* player = NULL; - if (playerId!=NLMISC::CEntityId::Unknown - && (player = dynamic_cast(CAIEntityPhysicalLocator::getInstance()->getEntity(playerId)))) + if (playerId != NLMISC::CEntityId::Unknown) { - bot->setPlayerController(player); + CAIEntityPhysical *playerEntity = inst->getEntity(playerId); + CBotPlayer* player = NULL; + if (playerEntity && (player = dynamic_cast(playerEntity))) + bot->setPlayerController(player); } else bot->setPlayerController(NULL);