1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
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"
26 //////////////////////////////////////////////////////////////////////////////
27 // CPlayerControlNpc //
28 //////////////////////////////////////////////////////////////////////////////
30 CPlayerControlNpc::CPlayerControlNpc(CBotPlayer
* player
, CSpawnBotNpc
* bot
)
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
56 void CPlayerControlNpc::updateControl(uint ticks
)
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)
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
85 // moveToProfile = new CBotProfileMoveTo(vertPos, wantedWPos, _Bot);
86 // _ControlProfileManager.setAIProfile(moveToProfile);
87 // _LastPathUpdate = currentTime;
92 // if (!moveToProfile->destinationReach())
94 // const double dist = _Bot->pos().quickDistTo( wantedWPos.toAIVector() );
95 // if (dist > wantedDist)
97 // _ControlProfileManager.updateProfile(ticks);
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();
112 CSpawnBotNpc
* CPlayerControlNpc::getSpawnBot() const