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/>.
21 #include "nel/misc/types_nl.h"
23 #include "client_messages.h"
25 //#include "game_share/tick_event_handler.h"
26 //#include "game_share/msg_client_server.h"
27 //#include "game_share/mode_and_behaviour.h" //TEMP!!!
28 //#include "game_share/news_types.h"
29 //#include "game_share/bot_chat_types.h"
30 //#include "game_share/brick_types.h"
31 //#include "game_share/loot_harvest_state.h"
32 //#include "game_share/ryzom_mirror_properties.h"
34 #include "server_share/r2_variables.h"
36 #include "world_position_manager.h"
37 #include "gpm_service.h"
40 using namespace NLMISC
;
41 using namespace NLNET
;
44 /****************************************************************\
45 cbUpdateEntityPosition()
46 \****************************************************************/
47 void cbClientPosition( CMessage
& msgin
, const string
&serviceName
, NLNET::TServiceId serviceId
)
49 H_AUTO(cbClientPosition
);
52 NLMISC::TGameCycle tick
;
53 msgin
.serial(id
, tick
);
55 TDataSetRow entityIndex
= TheDataset
.getDataSetRow( id
);
56 if ( !entityIndex
.isValid() )
58 // client may send position even before it is added in system
59 //nldebug( "%u: Receiving a position from client %s which is not in mirror yet", CTickEventHandler::getGameCycle(), id.toString().c_str() );
63 // entity pos (x, y, z, theta)
66 msgin
.serial(x
, y
, z
, heading
);
70 // make sure the move that the player is trying to make is legal
71 // if the move wasn't legal then the values of 'x' and 'y' will be changed to make them legal
72 bool moveWasLegal
= pCGPMS
->MoveChecker
->checkMove(entityIndex
, x
, y
, tick
);
74 // if the move wasn't legal then dispatch a message to the player
78 // // Teleport the player back to a previous valid location
79 // CMessage msgout( "IMPULSION_ID" );
80 // msgout.serial( master->Id );
82 // GenericXmlMsgManager.pushNameToStream( "TP:CORRECT", bms );
86 // msgout.serialMemStream( bms );
87 // CUnifiedNetwork::getInstance()->send( master->Id.getDynamicId(), msgout );
91 // set the player coordinates in the ring vision universe
92 pCGPMS
->RingVisionUniverse
->setEntityPosition(entityIndex
,x
,y
);
94 // todo: determine whether player is in water etc for real;
99 // update the player coordinates in the mirror
100 CMirrorPropValue1DS
<sint32
>( TheDataset
, entityIndex
, DSPropertyPOSX
)= x
;
101 CMirrorPropValue1DS
<sint32
>( TheDataset
, entityIndex
, DSPropertyPOSY
)= y
;
102 CMirrorPropValue1DS
<sint32
>( TheDataset
, entityIndex
, DSPropertyPOSZ
)= (z
&~7) + (local
? 1 : 0) + (interior
? 2 : 0) + (water
? 4 : 0);
103 CMirrorPropValue1DS
<float>( TheDataset
, entityIndex
, DSPropertyORIENTATION
)= heading
;
104 CMirrorPropValue1DS
<NLMISC::TGameCycle
>( TheDataset
, entityIndex
, DSPropertyTICK_POS
)= tick
;
106 CMirrorPropValue1DS
<TYPE_CELL
> cell ( TheDataset
, entityIndex
, DSPropertyCELL
);
107 uint32 cx
= (uint16
) ( + x
/CWorldPositionManager::getCellSize() );
108 uint32 cy
= (uint16
) ( - y
/CWorldPositionManager::getCellSize() );
109 cell
= (cx
<<16) + cy
;
111 // update the player position in the ring vision grid
112 pCGPMS
->RingVisionUniverse
->setEntityPosition(entityIndex
,x
,y
);
117 // check player mode and behaviour
118 CMirrorPropValueRO<MBEHAV::TMode> propMode( TheDataset, entityIndex, DSPropertyMODE );
119 MBEHAV::EMode mode = (MBEHAV::EMode)(propMode().Mode);
120 CMirrorPropValueRO<MBEHAV::CBehaviour> propBehaviour( TheDataset, entityIndex, DSPropertyBEHAVIOUR );
121 MBEHAV::EBehaviour behaviour = (MBEHAV::EBehaviour)(propBehaviour().Behaviour);
122 if ( (mode == MBEHAV::COMBAT)
123 || (mode == MBEHAV::COMBAT_FLOAT)
124 || (mode == MBEHAV::DEATH) )
126 H_AFTER(cbClientPosition);
130 CWorldEntity
*player
= CWorldPositionManager::getEntityPtr(entityIndex
);
137 if (player
->X() == 0 && player
->Y() == 0 && player
->Z() == 0)
142 //CWorldPositionManager::setEntityPosition(id, x, y, z, heading, tick);
143 if (player
->getType() == CWorldEntity::Player
&& player
->CheckMotion
&& player
->PosInitialised
)
145 CWorldPositionManager::movePlayer(player
, x
, y
, z
, heading
, tick
);
148 } // cbClientPosition //
150 //----------------------------
152 //----------------------------
153 TUnifiedCallbackItem CbClientArray
[]=
155 { "CLIENT:POSITION", cbClientPosition
},
161 //-------------------------------------------------------------------------
162 // singleton initialisation and release
164 void CClientMessages::init()
166 // setup the callback array
167 CUnifiedNetwork::getInstance()->addCallbackArray( CbClientArray
, sizeof(CbClientArray
)/sizeof(CbClientArray
[0]) );
170 void CClientMessages::release()