Added ai command setEquipment
[ryzomcore.git] / ryzom / server / src / ai_service / ai_control_npc.cpp
blobe46349f82bda5f9800b94221e281b312efec761e
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdpch.h"
18 #include "game_share/mode_and_behaviour.h"
19 #include "ai_control_npc.h"
20 #include "ai_bot_npc.h"
21 #include "ai_player.h"
22 #include "ai_profile_npc.h"
23 #include "ais_control.h"
24 using namespace std;
26 //////////////////////////////////////////////////////////////////////////////
27 // CPlayerControlNpc //
28 //////////////////////////////////////////////////////////////////////////////
30 CPlayerControlNpc::CPlayerControlNpc(CBotPlayer* player, CSpawnBotNpc* bot)
32 _Player = player;
33 _Bot = bot;
34 _LastPathUpdate = 0;
35 _CPlayerEntityId = player->getEntityId();
36 _CNpcEntityId = bot->getEntityId();
37 IAisControl::getInstance()->reportNpcControl(_CPlayerEntityId, _CNpcEntityId);
40 CPlayerControlNpc::~CPlayerControlNpc()
42 IAisControl::getInstance()->reportStopNpcControl(_CPlayerEntityId, _CNpcEntityId);
45 bool CPlayerControlNpc::isValid() const
47 if (_Player == NULL)
48 return false;
50 if (_Bot == NULL)
51 return false;
53 return true;
56 void CPlayerControlNpc::updateControl(uint ticks)
58 nlassert(isValid());
60 // static double baseDist = 1.0;
61 // const double wantedDist = baseDist + _Bot->radius() + _Player->radius();
62 const AITYPES::TVerticalPos vertPos = AITYPES::vp_auto;
64 RYAI_MAP_CRUNCH::CMapPosition mapPos(CAIVector(_Player->pos()));
65 RYAI_MAP_CRUNCH::CWorldPosition wantedWPos( mapPos.x(), mapPos.y());
67 //const RYAI_MAP_CRUNCH::CWorldPosition wantedWPos = _Player->wpos();
69 // :BUG: _Player->wpos().x() == 0 && _Player->wpos().x() == 0 where colision are wrong (like prime roots)
70 if (wantedWPos.x() == 0 && wantedWPos.y()==0)
72 _Player = NULL;
73 _Bot = NULL;
74 return;
77 // CBotProfileMoveTo* moveToProfile = dynamic_cast<CBotProfileMoveTo*>(_ControlProfileManager.getAIProfile());
79 // // do not path finding more than once per second
80 // const uint32 currentTime = CTimeInterface::gameCycle();
81 // const uint32 dt = currentTime - _LastPathUpdate;
82 // if ( moveToProfile == NULL
83 // || dt >= 10)
84 // {
85 // moveToProfile = new CBotProfileMoveTo(vertPos, wantedWPos, _Bot);
86 // _ControlProfileManager.setAIProfile(moveToProfile);
87 // _LastPathUpdate = currentTime;
88 // }
90 // breakable
91 // {
92 // if (!moveToProfile->destinationReach())
93 // {
94 // const double dist = _Bot->pos().quickDistTo( wantedWPos.toAIVector() );
95 // if (dist > wantedDist)
96 // {
97 // _ControlProfileManager.updateProfile(ticks);
98 // break;
99 // }
100 // }
102 _Bot->setPos(_Player->pos());
103 _Bot->setTheta(_Player->theta());
104 _Bot->setMode(_Player->getMode());
105 CMirrorPropValueRO<MBEHAV::CBehaviour> playerBehaviour( TheDataset, _Player->dataSetRow(), DSPropertyBEHAVIOUR );
106 CMirrorPropValue<MBEHAV::CBehaviour> npcBehaviour( TheDataset, _Bot->dataSetRow(), DSPropertyBEHAVIOUR );
107 npcBehaviour = playerBehaviour.getValue();
108 // }
112 CSpawnBotNpc* CPlayerControlNpc::getSpawnBot() const
114 return _Bot;