Compare commits

...

5 Commits

28 changed files with 103 additions and 13612 deletions

2
.gitignore vendored
View File

@ -26,3 +26,5 @@ locale/
src/lua/build/
src/lua/CMakeFiles/
*bak*
build/
build/*

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -1087,6 +1087,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
std::string datastring((char*)&data[2], datasize-2);
// Throw them in an istringstream
std::istringstream is(datastring, std::ios_base::binary);
//std::istringstream iscopy(datastring, std::ios_base::binary);
// Read stuff
@ -1114,6 +1115,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
is.read(buf, 1);
u8 type = readU8((u8*)buf);
std::string data = deSerializeLongString(is);
//std::string data = deSerializeLongString(iscopy);
// Add it
{
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out

File diff suppressed because it is too large Load Diff

View File

@ -27,6 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common_irrlicht.h"
#include "jmutex.h"
#include <ostream>
#include <exception>
#include <string>
#include "clientobject.h"
#include "utility.h" // For IntervalLimiter
#include "gamedef.h"
@ -48,6 +50,23 @@ public:
{}
};
class ClientError : public std::exception
{
public:
ClientError(const std::string &s)
{
m_s = "ClientError: ";
m_s += s;
}
virtual ~ClientError() throw() {}
virtual const char *what() const throw()
{
return m_s.c_str();
}
private:
std::string m_s;
};
struct QueuedMeshUpdate
{
v3s16 p;

View File

@ -2061,6 +2061,7 @@ private:
scene::IMeshSceneNode *m_body, *m_head, *m_leg_l, *m_leg_r, *m_arm_l, *m_arm_r;
scene::ITextSceneNode* m_text;
std::string m_name;
std::string playerimage;
v3f m_position;
v3f m_old_position;
float m_leg_rot;
@ -2068,6 +2069,7 @@ private:
float m_speed;
float m_pitch;
float m_yaw;
u8 clan;
SmoothTranslator pos_translator;
SmoothTranslator old_pos_translator;
SmoothTranslator head_translator;
@ -2101,6 +2103,7 @@ public:
infostream<<"PlayerCAO: Got init data"<<std::endl;
std::istringstream is(data, std::ios::binary);
//std::istringstream iscopy(data, std::ios::binary);
// version
u8 version = readU8(is);
// check version
@ -2116,6 +2119,10 @@ public:
m_pitch = updateHeadPitch(m_pitch);
// yaw
m_yaw = readF1000(is);
// clan
clan = readF1000(is);
// player image
playerimage = "mt_" + itos(clan) + ".png";
pos_translator.init(m_position);
old_pos_translator.init(m_old_position);
@ -2850,7 +2857,7 @@ public:
scene::IMesh *mesh = m_body->getMesh();
if(mesh){
{
std::string tname = "mt_player.png";
std::string tname = playerimage;
tname += mod;
scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
buf->getMaterial().setTexture(0,
@ -2863,7 +2870,7 @@ public:
scene::IMesh *mesh = m_head->getMesh();
if(mesh){
{
std::string tname = "mt_player.png";
std::string tname = playerimage;
tname += mod;
scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
buf->getMaterial().setTexture(0,
@ -2876,7 +2883,7 @@ public:
scene::IMesh *mesh = m_leg_l->getMesh();
if(mesh){
{
std::string tname = "mt_player.png";
std::string tname = playerimage;
tname += mod;
scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
buf->getMaterial().setTexture(0,
@ -2889,7 +2896,7 @@ public:
scene::IMesh *mesh = m_leg_r->getMesh();
if(mesh){
{
std::string tname = "mt_player.png";
std::string tname = playerimage;
tname += mod;
scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
buf->getMaterial().setTexture(0,
@ -2902,7 +2909,7 @@ public:
scene::IMesh *mesh = m_arm_l->getMesh();
if(mesh){
{
std::string tname = "mt_player.png";
std::string tname = playerimage;
tname += mod;
scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
buf->getMaterial().setTexture(0,
@ -2915,7 +2922,7 @@ public:
scene::IMesh *mesh = m_arm_r->getMesh();
if(mesh){
{
std::string tname = "mt_player.png";
std::string tname = playerimage;
tname += mod;
scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
buf->getMaterial().setTexture(0,

File diff suppressed because it is too large Load Diff

View File

@ -1,134 +0,0 @@
/*
Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "settings.h"
void set_default_settings(Settings *settings)
{
// Client and server
settings->setDefault("port", "");
settings->setDefault("name", "");
settings->setDefault("footprints", "false");
// Client stuff
settings->setDefault("keymap_forward", "KEY_KEY_W");
settings->setDefault("keymap_backward", "KEY_KEY_S");
settings->setDefault("keymap_left", "KEY_KEY_A");
settings->setDefault("keymap_right", "KEY_KEY_D");
settings->setDefault("keymap_jump", "KEY_SPACE");
settings->setDefault("keymap_sneak", "KEY_LSHIFT");
settings->setDefault("keymap_crawl", "KEY_LCONTROL");
settings->setDefault("keymap_drop", "KEY_KEY_Q");
settings->setDefault("keymap_inventory", "KEY_KEY_I");
settings->setDefault("keymap_special1", "KEY_KEY_E");
settings->setDefault("keymap_chat", "KEY_KEY_T");
settings->setDefault("keymap_cmd", "/");
settings->setDefault("keymap_rangeselect", "KEY_KEY_R");
settings->setDefault("keymap_freemove", "KEY_KEY_K");
settings->setDefault("keymap_fastmove", "KEY_KEY_J");
settings->setDefault("keymap_screenshot", "KEY_F12");
settings->setDefault("keymap_toggle_hud", "KEY_F1");
settings->setDefault("keymap_toggle_chat", "KEY_F2");
settings->setDefault("keymap_toggle_force_fog_off", "KEY_F3");
settings->setDefault("keymap_toggle_update_camera", "KEY_F4");
settings->setDefault("keymap_toggle_debug", "KEY_F5");
settings->setDefault("keymap_toggle_profiler", "KEY_F6");
settings->setDefault("keymap_increase_viewing_range_min", "KEY_PRIOR");
settings->setDefault("keymap_decrease_viewing_range_min", "KEY_NEXT");
// Some (temporary) keys for debugging
settings->setDefault("keymap_print_debug_stacks", "KEY_KEY_P");
settings->setDefault("anaglyph", "false");
settings->setDefault("anaglyph_strength", "0.05");
// Show debug info by default?
#ifdef NDEBUG
settings->setDefault("show_debug", "false");
#else
settings->setDefault("show_debug", "true");
#endif
settings->setDefault("wanted_fps", "30");
settings->setDefault("fps_max", "60");
// A bit more than the server will send around the player, to make fog blend well
settings->setDefault("viewing_range_nodes_min", "35");
settings->setDefault("viewing_range_nodes_max", "128");
settings->setDefault("screenW", "800");
settings->setDefault("screenH", "600");
settings->setDefault("address", "");
settings->setDefault("random_input", "false");
settings->setDefault("client_unload_unused_data_timeout", "600");
settings->setDefault("enable_fog", "true");
settings->setDefault("fov", "72");
settings->setDefault("view_bobbing", "true");
settings->setDefault("new_style_water", "false");
settings->setDefault("new_style_leaves", "false");
settings->setDefault("smooth_lighting", "true");
settings->setDefault("enable_texture_atlas", "true");
settings->setDefault("texture_path", "");
settings->setDefault("video_driver", "opengl");
settings->setDefault("free_move", "false");
settings->setDefault("continuous_forward", "false");
settings->setDefault("fast_move", "false");
settings->setDefault("invert_mouse", "false");
settings->setDefault("enable_farmesh", "false");
settings->setDefault("enable_clouds", "true");
settings->setDefault("screenshot_path", ".");
settings->setDefault("view_bobbing_amount", "1.0");
settings->setDefault("enable_3d_clouds", "false");
settings->setDefault("opaque_water", "false");
// Server stuff
// "map-dir" doesn't exist by default.
settings->setDefault("motd", "");
settings->setDefault("max_users", "100");
settings->setDefault("strict_protocol_version_checking", "true");
settings->setDefault("creative_mode", "false");
settings->setDefault("enable_damage", "true");
settings->setDefault("only_peaceful_mobs", "false");
settings->setDefault("fixed_map_seed", "");
settings->setDefault("give_initial_stuff", "false");
settings->setDefault("default_password", "");
settings->setDefault("default_privs", "build, shout");
settings->setDefault("unlimited_player_transfer_distance", "true");
settings->setDefault("enable_pvp", "true");
settings->setDefault("profiler_print_interval", "0");
settings->setDefault("enable_mapgen_debug_info", "false");
settings->setDefault("active_object_send_range_blocks", "3");
settings->setDefault("active_block_range", "2");
//settings->setDefault("max_simultaneous_block_sends_per_client", "1");
// This causes frametime jitter on client side, or does it?
settings->setDefault("max_simultaneous_block_sends_per_client", "2");
settings->setDefault("max_simultaneous_block_sends_server_total", "8");
settings->setDefault("max_block_send_distance", "7");
settings->setDefault("max_block_generate_distance", "5");
settings->setDefault("time_send_interval", "20");
settings->setDefault("time_speed", "96");
settings->setDefault("server_unload_unused_data_timeout", "29");
settings->setDefault("server_map_save_interval", "5.3");
settings->setDefault("full_block_send_enable_min_time_from_building", "2.0");
settings->setDefault("enable_experimental", "false");
settings->setDefault("dedicated_server_step", "0.05");
settings->setDefault("antialiasing", "false");
settings->setDefault("fullscreen", "false");
settings->setDefault("vsync", "false");
}

View File

@ -342,6 +342,7 @@ PointedThing getPointedThing(Client *client, v3f player_position,
f32 mindistance = BS * 1001; //used for regular blocks
f32 maxdistance = -BS * 1001; //used for free blocks
v3s16 pos_i = floatToInt(player_position, BS);
v3s16 cam_i = floatToInt(camera_position, BS);
v3s16 camdir_i(camera_direction.X>=0?1:-1,
camera_direction.Y>=0?1:-1,

File diff suppressed because it is too large Load Diff

View File

@ -1800,10 +1800,10 @@ int main(int argc, char *argv[])
error_message = L"Socket error (port already in use?)";
}
catch(ClientError &e)
+ {
+ errorstream<<e.what()<<std::endl;
+ error_message = narrow_to_wide(e.what());
+ }
{
errorstream<<e.what()<<std::endl;
error_message = narrow_to_wide(e.what());
}
catch(ModError &e)
{
errorstream<<e.what()<<std::endl;

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,8 @@ Player::Player(IGameDef *gamedef):
inventory(gamedef->idef()),
inventory_backup(NULL),
hp(20),
clan(0),
playerimage("mt_0.png"),
peer_id(PEER_ID_INEXISTENT),
// protected
m_gamedef(gamedef),
@ -124,6 +126,8 @@ void Player::serialize(std::ostream &os)
args.setFloat("yaw", m_yaw);
args.setV3F("position", m_position);
args.setS32("hp", hp);
args.setS32("clan", clan);
args.set("playerimage", playerimage);
args.writeLines(os);
@ -165,6 +169,16 @@ void Player::deSerialize(std::istream &is)
}catch(SettingNotFoundException &e){
hp = 20;
}
try{
clan = args.getS32("clan");
}catch(SettingNotFoundException &e){
clan = 0;
}
try{
playerimage = args.get("playerimage");
}catch(SettingNotFoundException &e){
playerimage = "mt_0.png";
}
inventory.deSerialize(is);

View File

@ -1,823 +0,0 @@
/*
Minetest-c55
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "player.h"
#include "map.h"
#include "connection.h"
#include "constants.h"
#include "utility.h"
#ifndef SERVER
#include <ITextSceneNode.h>
#endif
#include "main.h" // For g_settings
#include "settings.h"
#include "nodedef.h"
#include "collision.h"
#include "environment.h"
#include "gamedef.h"
f32 Player::m_eyeOffsetMax = BS+(5*BS)/8;
f32 Player::m_eyeOffsetMin = BS * 0.9f;
Player::Player(IGameDef *gamedef):
touching_ground(false),
in_water(false),
in_water_stable(false),
is_climbing(false),
swimming_up(false),
inventory(gamedef->idef()),
inventory_backup(NULL),
hp(20),
peer_id(PEER_ID_INEXISTENT),
// protected
m_gamedef(gamedef),
m_pitch(0),
m_yaw(0),
m_speed(0,0,0),
m_position(0,0,0),
m_eyeOffset(0,m_eyeOffsetMax,0)
{
updateName("<not set>");
resetInventory();
}
Player::~Player()
{
delete inventory_backup;
}
void Player::resetInventory()
{
inventory.clear();
inventory.addList("main", PLAYER_INVENTORY_SIZE);
inventory.addList("craft", 9);
inventory.addList("craftpreview", 1);
inventory.addList("craftresult", 1);
}
// Y direction is ignored
void Player::accelerate(v3f target_speed, f32 max_increase)
{
v3f d_wanted = target_speed - m_speed;
d_wanted.Y = 0;
f32 dl_wanted = d_wanted.getLength();
f32 dl = dl_wanted;
if(dl > max_increase)
dl = max_increase;
v3f d = d_wanted.normalize() * dl;
m_speed.X += d.X;
m_speed.Z += d.Z;
//m_speed += d;
#if 0 // old code
if(m_speed.X < target_speed.X - max_increase)
m_speed.X += max_increase;
else if(m_speed.X > target_speed.X + max_increase)
m_speed.X -= max_increase;
else if(m_speed.X < target_speed.X)
m_speed.X = target_speed.X;
else if(m_speed.X > target_speed.X)
m_speed.X = target_speed.X;
if(m_speed.Z < target_speed.Z - max_increase)
m_speed.Z += max_increase;
else if(m_speed.Z > target_speed.Z + max_increase)
m_speed.Z -= max_increase;
else if(m_speed.Z < target_speed.Z)
m_speed.Z = target_speed.Z;
else if(m_speed.Z > target_speed.Z)
m_speed.Z = target_speed.Z;
#endif
}
v3s16 Player::getLightPosition() const
{
return floatToInt(m_position + v3f(0,BS+BS/2,0), BS);
}
void Player::serialize(std::ostream &os)
{
// Utilize a Settings object for storing values
Settings args;
args.setS32("version", 1);
args.set("name", m_name);
//args.set("password", m_password);
args.setFloat("pitch", m_pitch);
args.setFloat("yaw", m_yaw);
args.setV3F("position", m_position);
args.setS32("hp", hp);
args.writeLines(os);
os<<"PlayerArgsEnd\n";
// If actual inventory is backed up due to creative mode, save it
// instead of the dummy creative mode inventory
if(inventory_backup)
inventory_backup->serialize(os);
else
inventory.serialize(os);
}
void Player::deSerialize(std::istream &is)
{
Settings args;
for(;;)
{
if(is.eof())
throw SerializationError
("Player::deSerialize(): PlayerArgsEnd not found");
std::string line;
std::getline(is, line);
std::string trimmedline = trim(line);
if(trimmedline == "PlayerArgsEnd")
break;
args.parseConfigLine(line);
}
//args.getS32("version"); // Version field value not used
std::string name = args.get("name");
updateName(name.c_str());
setPitch(args.getFloat("pitch"));
setYaw(args.getFloat("yaw"));
setPosition(args.getV3F("position"));
try{
hp = args.getS32("hp");
}catch(SettingNotFoundException &e){
hp = 20;
}
inventory.deSerialize(is);
if(inventory.getList("craftpreview") == NULL)
{
// Convert players without craftpreview
inventory.addList("craftpreview", 1);
bool craftresult_is_preview = true;
if(args.exists("craftresult_is_preview"))
craftresult_is_preview = args.getBool("craftresult_is_preview");
if(craftresult_is_preview)
{
// Clear craftresult
inventory.getList("craftresult")->changeItem(0, ItemStack());
}
}
}
#ifndef SERVER
/*
LocalPlayer
*/
LocalPlayer::LocalPlayer(IGameDef *gamedef):
Player(gamedef),
m_sneak_node(32767,32767,32767),
m_sneak_node_exists(false),
m_must_crawl(false)
{
// Initialize hp to 0, so that no hearts will be shown if server
// doesn't support health points
hp = 0;
}
LocalPlayer::~LocalPlayer()
{
}
void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
core::list<CollisionInfo> *collision_info)
{
INodeDefManager *nodemgr = m_gamedef->ndef();
v3f position = getPosition();
v3f oldpos = position;
v3s16 oldpos_i = floatToInt(oldpos, BS);
v3f old_speed = m_speed;
/*std::cout<<"oldpos_i=("<<oldpos_i.X<<","<<oldpos_i.Y<<","
<<oldpos_i.Z<<")"<<std::endl;*/
/*
Calculate new position
*/
position += m_speed * dtime;
// Skip collision detection if a special movement mode is used
bool free_move = g_settings->getBool("free_move");
if(free_move)
{
setPosition(position);
return;
}
/*
Collision detection
*/
// Player position in nodes
v3s16 pos_i = floatToInt(position, BS);
/*
Check if player is in water (the oscillating value)
*/
try{
// If in water, the threshold of coming out is at higher y
if(in_water)
{
v3s16 pp = floatToInt(position + v3f(0,BS*0.1,0), BS);
in_water = nodemgr->get(map.getNode(pp).getContent()).isLiquid();
}
// If not in water, the threshold of going in is at lower y
else
{
v3s16 pp = floatToInt(position + v3f(0,BS*0.5,0), BS);
in_water = nodemgr->get(map.getNode(pp).getContent()).isLiquid();
}
}
catch(InvalidPositionException &e)
{
in_water = false;
}
/*
Check if player is in water (the stable value)
*/
try{
v3s16 pp = floatToInt(position + v3f(0,0,0), BS);
in_water_stable = nodemgr->get(map.getNode(pp).getContent()).isLiquid();
}
catch(InvalidPositionException &e)
{
in_water_stable = false;
}
/*
Check if player is climbing
*/
try {
v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS);
v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS);
is_climbing = ((nodemgr->get(map.getNode(pp).getContent()).climbable ||
nodemgr->get(map.getNode(pp2).getContent()).climbable) && !free_move);
}
catch(InvalidPositionException &e)
{
is_climbing = false;
}
/*
Collision uncertainty radius
Make it a bit larger than the maximum distance of movement
*/
//f32 d = pos_max_d * 1.1;
// A fairly large value in here makes moving smoother
f32 d = 0.15*BS;
// This should always apply, otherwise there are glitches
assert(d > pos_max_d);
float player_radius = BS*0.35;
float player_height = m_eyeOffset.Y + BS*0.05f;
float player_maxheight = m_eyeOffsetMax + BS*0.05f;
// Maximum distance over border for sneaking
f32 sneak_max = BS*0.4;
/*
If sneaking, player has larger collision radius to keep from
falling
*/
/*if(control.sneak)
player_radius = sneak_max + d*1.1;*/
/*
If sneaking, keep in range from the last walked node and don't
fall off from it
*/
if(control.sneak && m_sneak_node_exists)
{
f32 maxd = 0.5*BS + sneak_max;
v3f lwn_f = intToFloat(m_sneak_node, BS);
position.X = rangelim(position.X, lwn_f.X-maxd, lwn_f.X+maxd);
position.Z = rangelim(position.Z, lwn_f.Z-maxd, lwn_f.Z+maxd);
f32 min_y = lwn_f.Y + 0.5*BS;
if(position.Y < min_y)
{
position.Y = min_y;
//v3f old_speed = m_speed;
if(m_speed.Y < 0)
m_speed.Y = 0;
/*if(collision_info)
{
// Report fall collision
if(old_speed.Y < m_speed.Y - 0.1)
{
CollisionInfo info;
info.t = COLLISION_FALL;
info.speed = m_speed.Y - old_speed.Y;
collision_info->push_back(info);
}
}*/
}
}
/*
Calculate player collision box (new and old)
*/
core::aabbox3d<f32> playerbox(
position.X - player_radius,
position.Y - 0.0,
position.Z - player_radius,
position.X + player_radius,
position.Y + player_height,
position.Z + player_radius
);
core::aabbox3d<f32> playerbox_standing(
position.X - player_radius,
position.Y - 0.0,
position.Z - player_radius,
position.X + player_radius,
position.Y + player_maxheight,
position.Z + player_radius
);
core::aabbox3d<f32> playerbox_old(
oldpos.X - player_radius,
oldpos.Y - 0.0,
oldpos.Z - player_radius,
oldpos.X + player_radius,
oldpos.Y + player_height,
oldpos.Z + player_radius
);
/*
If the player's feet touch the topside of any node, this is
set to true.
Player is allowed to jump when this is true.
*/
touching_ground = false;
/*std::cout<<"Checking collisions for ("
<<oldpos_i.X<<","<<oldpos_i.Y<<","<<oldpos_i.Z
<<") -> ("
<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z
<<"):"<<std::endl;*/
bool standing_on_unloaded = false;
const s16 player_height_i = player_height/BS + 1;
/*
Go through every node around the player
*/
for(s16 y = oldpos_i.Y - 1; y <= oldpos_i.Y + player_height_i; y++)
for(s16 z = oldpos_i.Z - 1; z <= oldpos_i.Z + 1; z++)
for(s16 x = oldpos_i.X - 1; x <= oldpos_i.X + 1; x++)
{
bool is_unloaded = false;
try{
// Player collides into walkable nodes
if(nodemgr->get(map.getNode(v3s16(x,y,z))).walkable == false)
continue;
}
catch(InvalidPositionException &e)
{
is_unloaded = true;
// Doing nothing here will block the player from
// walking over map borders
}
core::aabbox3d<f32> nodebox = getNodeBox(v3s16(x,y,z), BS);
/*
See if the player is touching ground.
Player touches ground if player's minimum Y is near node's
maximum Y and player's X-Z-area overlaps with the node's
X-Z-area.
Use 0.15*BS so that it is easier to get on a node.
*/
if(
//fabs(nodebox.MaxEdge.Y-playerbox.MinEdge.Y) < d
fabs(nodebox.MaxEdge.Y-playerbox.MinEdge.Y) < 0.15*BS
&& nodebox.MaxEdge.X-d > playerbox.MinEdge.X
&& nodebox.MinEdge.X+d < playerbox.MaxEdge.X
&& nodebox.MaxEdge.Z-d > playerbox.MinEdge.Z
&& nodebox.MinEdge.Z+d < playerbox.MaxEdge.Z
){
touching_ground = true;
if(is_unloaded)
standing_on_unloaded = true;
}
// If player doesn't intersect with node, ignore node.
if(playerbox.intersectsWithBox(nodebox) == false)
continue;
/*
Go through every axis
*/
v3f dirs[3] = {
v3f(0,0,1), // back-front
v3f(0,1,0), // top-bottom
v3f(1,0,0), // right-left
};
for(u16 i=0; i<3; i++)
{
/*
Calculate values along the axis
*/
f32 nodemax = nodebox.MaxEdge.dotProduct(dirs[i]);
f32 nodemin = nodebox.MinEdge.dotProduct(dirs[i]);
f32 playermax = playerbox.MaxEdge.dotProduct(dirs[i]);
f32 playermin = playerbox.MinEdge.dotProduct(dirs[i]);
f32 playermax_old = playerbox_old.MaxEdge.dotProduct(dirs[i]);
f32 playermin_old = playerbox_old.MinEdge.dotProduct(dirs[i]);
/*
Check collision for the axis.
Collision happens when player is going through a surface.
*/
/*f32 neg_d = d;
f32 pos_d = d;
// Make it easier to get on top of a node
if(i == 1)
neg_d = 0.15*BS;
bool negative_axis_collides =
(nodemax > playermin && nodemax <= playermin_old + neg_d
&& m_speed.dotProduct(dirs[i]) < 0);
bool positive_axis_collides =
(nodemin < playermax && nodemin >= playermax_old - pos_d
&& m_speed.dotProduct(dirs[i]) > 0);*/
bool negative_axis_collides =
(nodemax > playermin && nodemax <= playermin_old + d
&& m_speed.dotProduct(dirs[i]) < 0);
bool positive_axis_collides =
(nodemin < playermax && nodemin >= playermax_old - d
&& m_speed.dotProduct(dirs[i]) > 0);
bool main_axis_collides =
negative_axis_collides || positive_axis_collides;
/*
Check overlap of player and node in other axes
*/
bool other_axes_overlap = true;
for(u16 j=0; j<3; j++)
{
if(j == i)
continue;
f32 nodemax = nodebox.MaxEdge.dotProduct(dirs[j]);
f32 nodemin = nodebox.MinEdge.dotProduct(dirs[j]);
f32 playermax = playerbox.MaxEdge.dotProduct(dirs[j]);
f32 playermin = playerbox.MinEdge.dotProduct(dirs[j]);
if(!(nodemax - d > playermin && nodemin + d < playermax))
{
other_axes_overlap = false;
break;
}
}
/*
If this is a collision, revert the position in the main
direction.
*/
if(other_axes_overlap && main_axis_collides)
{
//v3f old_speed = m_speed;
m_speed -= m_speed.dotProduct(dirs[i]) * dirs[i];
position -= position.dotProduct(dirs[i]) * dirs[i];
position += oldpos.dotProduct(dirs[i]) * dirs[i];
/*if(collision_info)
{
// Report fall collision
if(old_speed.Y < m_speed.Y - 0.1)
{
CollisionInfo info;
info.t = COLLISION_FALL;
info.speed = m_speed.Y - old_speed.Y;
collision_info->push_back(info);
}
}*/
}
}
} // xyz
/*
Check the nodes under the player to see from which node the
player is sneaking from, if any.
*/
{
v3s16 pos_i_bottom = floatToInt(position - v3f(0,BS/2,0), BS);
v2f player_p2df(position.X, position.Z);
f32 min_distance_f = 100000.0*BS;
// If already seeking from some node, compare to it.
/*if(m_sneak_node_exists)
{
v3f sneaknode_pf = intToFloat(m_sneak_node, BS);
v2f sneaknode_p2df(sneaknode_pf.X, sneaknode_pf.Z);
f32 d_horiz_f = player_p2df.getDistanceFrom(sneaknode_p2df);
f32 d_vert_f = fabs(sneaknode_pf.Y + BS*0.5 - position.Y);
// Ignore if player is not on the same level (likely dropped)
if(d_vert_f < 0.15*BS)
min_distance_f = d_horiz_f;
}*/
v3s16 new_sneak_node = m_sneak_node;
for(s16 x=-1; x<=1; x++)
for(s16 z=-1; z<=1; z++)
{
v3s16 p = pos_i_bottom + v3s16(x,0,z);
v3f pf = intToFloat(p, BS);
v2f node_p2df(pf.X, pf.Z);
f32 distance_f = player_p2df.getDistanceFrom(node_p2df);
f32 max_axis_distance_f = MYMAX(
fabs(player_p2df.X-node_p2df.X),
fabs(player_p2df.Y-node_p2df.Y));
if(distance_f > min_distance_f ||
max_axis_distance_f > 0.5*BS + sneak_max + 0.1*BS)
continue;
try{
// The node to be sneaked on has to be walkable
if(nodemgr->get(map.getNode(p)).walkable == false)
continue;
// And the node above it has to be nonwalkable
if(nodemgr->get(map.getNode(p+v3s16(0,1,0))).walkable == true)
continue;
}
catch(InvalidPositionException &e)
{
continue;
}
min_distance_f = distance_f;
new_sneak_node = p;
}
bool sneak_node_found = (min_distance_f < 100000.0*BS*0.9);
if(control.sneak && m_sneak_node_exists)
{
if(sneak_node_found)
m_sneak_node = new_sneak_node;
}
else
{
m_sneak_node = new_sneak_node;
m_sneak_node_exists = sneak_node_found;
}
/*
If sneaking, the player's collision box can be in air, so
this has to be set explicitly
*/
if(sneak_node_found && control.sneak)
touching_ground = true;
/*
Check if player must crawl
*/
bool must_crawl = false;
v3s16 pos_head_i = floatToInt(v3f(position.X,position.Y+m_eyeOffsetMax+BS*0.05f,position.Z), BS);
for(s16 z = -1; z <= 1; z++)
for(s16 x = -1; x <= 1; x++)
{
try{
// Player collides into walkable nodes
v3s16 np(pos_head_i.X+x,pos_head_i.Y,pos_head_i.Z+z);
if(nodemgr->get(map.getNode(np)).walkable == false)
continue;
core::aabbox3d<f32> nodebox = getNodeBox(np, BS);
if( (m_must_crawl || control.crawl) //shall we test it?
&& playerbox_standing.intersectsWithBox(nodebox) //colliding with the node?
)
{
must_crawl = true;
}
}
catch(InvalidPositionException &e)
{}
}
m_must_crawl = must_crawl;
}
/*
Set new position
*/
setPosition(position);
/*
Report collisions
*/
if(collision_info)
{
// Report fall collision
if(old_speed.Y < m_speed.Y - 0.1 && !standing_on_unloaded)
{
CollisionInfo info;
info.t = COLLISION_FALL;
info.speed = m_speed.Y - old_speed.Y;
collision_info->push_back(info);
}
}
}
void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d)
{
move(dtime, map, pos_max_d, NULL);
}
void LocalPlayer::applyControl(float dtime)
{
// Clear stuff
swimming_up = false;
// Random constants
f32 walk_acceleration = 4.0 * BS;
f32 walkspeed_max = 4.0 * BS;
setPitch(control.pitch);
setYaw(control.yaw);
v3f move_direction = v3f(0,0,1);
move_direction.rotateXZBy(getYaw());
v3f speed = v3f(0,0,0);
bool free_move = g_settings->getBool("free_move");
bool fast_move = g_settings->getBool("fast_move");
bool continuous_forward = g_settings->getBool("continuous_forward");
if(free_move || is_climbing)
{
v3f speed = getSpeed();
speed.Y = 0;
setSpeed(speed);
}
// Whether superspeed mode is used or not
bool superspeed = false;
// If free movement and fast movement, always move fast
if(free_move && fast_move)
superspeed = true;
// If must crawl - then crawl ;)
if(m_must_crawl) control.crawl = true;
// Auxiliary button 1 (E)
if(control.aux1)
{
if(free_move)
{
// In free movement mode, aux1 descends
v3f speed = getSpeed();
if(fast_move)
speed.Y = -20*BS;
else
speed.Y = -walkspeed_max;
setSpeed(speed);
}
else if(is_climbing)
{
v3f speed = getSpeed();
speed.Y = -3*BS;
setSpeed(speed);
}
else
{
// If not free movement but fast is allowed, aux1 is
// "Turbo button"
if(fast_move)
superspeed = true;
}
}
if(continuous_forward)
speed += move_direction;
if(control.up)
{
if(continuous_forward)
superspeed = true;
else
speed += move_direction;
}
if(control.down)
{
speed -= move_direction;
}
if(control.left)
{
speed += move_direction.crossProduct(v3f(0,1,0));
}
if(control.right)
{
speed += move_direction.crossProduct(v3f(0,-1,0));
}
if(control.jump)
{
if(free_move)
{
v3f speed = getSpeed();
if(fast_move)
speed.Y = 20*BS;
else
speed.Y = walkspeed_max;
setSpeed(speed);
}
else if(touching_ground)
{
/*
NOTE: The d value in move() affects jump height by
raising the height at which the jump speed is kept
at its starting value
*/
v3f speed = getSpeed();
if(speed.Y >= -0.5*BS)
{
speed.Y = 6.5*BS;
setSpeed(speed);
}
}
// Use the oscillating value for getting out of water
// (so that the player doesn't fly on the surface)
else if(in_water)
{
v3f speed = getSpeed();
speed.Y = 1.5*BS;
setSpeed(speed);
swimming_up = true;
}
else if(is_climbing)
{
v3f speed = getSpeed();
speed.Y = 3*BS;
setSpeed(speed);
}
}
// The speed of the player (Y is ignored)
if(superspeed)
speed = speed.normalize() * walkspeed_max * 5.0;
else if(control.sneak || control.crawl)
speed = speed.normalize() * walkspeed_max / 3.0;
else
speed = speed.normalize() * walkspeed_max;
f32 inc = walk_acceleration * BS * dtime;
// Faster acceleration if fast and free movement
if(free_move && fast_move)
inc = walk_acceleration * BS * dtime * 10;
// Accelerate to target speed with maximum increment
accelerate(speed, inc);
static const f32 eyes_delta = 10.f;
if(control.crawl)
{
//crouching
if(m_eyeOffset.Y > m_eyeOffsetMin + 0.01f)
m_eyeOffset.Y += (m_eyeOffsetMin-m_eyeOffset.Y) * eyes_delta * dtime;
else m_eyeOffset.Y = m_eyeOffsetMin;
}
else
{
//standing
if(m_eyeOffset.Y < m_eyeOffsetMax - 0.01f)
m_eyeOffset.Y += (m_eyeOffsetMax-m_eyeOffset.Y) * eyes_delta * dtime;
else m_eyeOffset.Y = m_eyeOffsetMax;
}
}
#endif

View File

@ -22,6 +22,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common_irrlicht.h"
#include "inventory.h"
#include <string>
#include <sstream>
#include "utility.h"
#define PLAYERNAME_SIZE 20
@ -54,6 +57,22 @@ public:
m_speed = speed;
}
void setClan(u8 clanu)
{
clan = clanu;
playerimage = std::string("mt_" + itos(clan) + ".png");
}
u8 getClan()
{
return clan;
}
std::string getPlayerImage()
{
return playerimage;
}
// Y direction is ignored
void accelerate(v3f target_speed, f32 max_increase);
@ -158,6 +177,11 @@ public:
u16 hp;
// Clans: 0 = normal (shouldn't exist, but just in the case of hackers), 1 = Secret Agents, 2 = Ninjas
u8 clan;
std::string playerimage;
u16 peer_id;
protected:

View File

@ -1,261 +0,0 @@
/*
Minetest-c55
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef PLAYER_HEADER
#define PLAYER_HEADER
#include "common_irrlicht.h"
#include "inventory.h"
#define PLAYERNAME_SIZE 20
#define PLAYERNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
class Map;
class IGameDef;
struct CollisionInfo;
class Player
{
public:
Player(IGameDef *gamedef);
virtual ~Player();
void resetInventory();
//void move(f32 dtime, Map &map);
virtual void move(f32 dtime, Map &map, f32 pos_max_d) = 0;
v3f getSpeed()
{
return m_speed;
}
void setSpeed(v3f speed)
{
m_speed = speed;
}
// Y direction is ignored
void accelerate(v3f target_speed, f32 max_increase);
v3f getPosition()
{
return m_position;
}
v3s16 getLightPosition() const;
v3f getEyeOffset()
{
// This is at the height of the eyes of the current figure
// return v3f(0, BS+BS/2, 0);
// This is more like in minecraft
//return v3f(0,BS+(5*BS)/8,0);
return m_eyeOffset;
}
v3f getEyePosition()
{
return m_position + getEyeOffset();
}
virtual void setPosition(const v3f &position)
{
m_position = position;
}
void setPitch(f32 pitch)
{
m_pitch = pitch;
}
virtual void setYaw(f32 yaw)
{
m_yaw = yaw;
}
f32 getPitch()
{
return m_pitch;
}
f32 getYaw()
{
return m_yaw;
}
f32 getRadPitch()
{
return -1.0 * m_pitch * core::DEGTORAD;
}
f32 getRadYaw()
{
return (m_yaw + 90.) * core::DEGTORAD;
}
virtual void updateName(const char *name)
{
snprintf(m_name, PLAYERNAME_SIZE, "%s", name);
}
const char * getName() const
{
return m_name;
}
virtual bool isLocal() const = 0;
virtual void updateLight(u8 light_at_pos)
{
light = light_at_pos;
}
// NOTE: Use peer_id == 0 for disconnected
/*virtual bool isClientConnected() { return false; }
virtual void setClientConnected(bool) {}*/
/*
serialize() writes a bunch of text that can contain
any characters except a '\0', and such an ending that
deSerialize stops reading exactly at the right point.
*/
void serialize(std::ostream &os);
void deSerialize(std::istream &is);
bool touching_ground;
// This oscillates so that the player jumps a bit above the surface
bool in_water;
// This is more stable and defines the maximum speed of the player
bool in_water_stable;
bool is_climbing;
bool swimming_up;
u8 light;
Inventory inventory;
// Actual inventory is backed up here when creative mode is used
Inventory *inventory_backup;
u16 hp;
u16 peer_id;
protected:
IGameDef *m_gamedef;
char m_name[PLAYERNAME_SIZE];
f32 m_pitch;
f32 m_yaw;
v3f m_speed;
v3f m_position;
v3f m_eyeOffset;
static f32 m_eyeOffsetMax;
static f32 m_eyeOffsetMin;
public:
};
#ifndef SERVER
struct PlayerControl
{
PlayerControl()
{
up = false;
down = false;
left = false;
right = false;
jump = false;
aux1 = false;
sneak = false;
pitch = 0;
yaw = 0;
crawl = false;
}
PlayerControl(
bool a_up,
bool a_down,
bool a_left,
bool a_right,
bool a_jump,
bool a_aux1,
bool a_sneak,
float a_pitch,
float a_yaw,
bool a_crawl
)
{
up = a_up;
down = a_down;
left = a_left;
right = a_right;
jump = a_jump;
aux1 = a_aux1;
sneak = a_sneak;
pitch = a_pitch;
yaw = a_yaw;
crawl = a_crawl;
}
bool up;
bool down;
bool left;
bool right;
bool jump;
bool aux1;
bool sneak;
float pitch;
float yaw;
bool crawl;
};
class LocalPlayer : public Player
{
public:
LocalPlayer(IGameDef *gamedef);
virtual ~LocalPlayer();
bool isLocal() const
{
return true;
}
void move(f32 dtime, Map &map, f32 pos_max_d,
core::list<CollisionInfo> *collision_info);
void move(f32 dtime, Map &map, f32 pos_max_d);
void applyControl(float dtime);
PlayerControl control;
private:
// This is used for determining the sneaking range
v3s16 m_sneak_node;
// Whether the player is allowed to sneak
bool m_sneak_node_exists;
// Whether player can't stand
bool m_must_crouch;
};
#endif // !SERVER
#endif

View File

@ -4009,7 +4009,7 @@ void Server::RespawnPlayer(Player *player)
srp->setHP(20);
bool repositioned = scriptapi_on_respawnplayer(m_lua, srp);
if(!repositioned){
v3f pos = findSpawnPos(m_env->getServerMap());
v3f pos = findSpawnPos(m_env->getServerMap(), player->getClan());
player->setPosition(pos);
srp->m_last_good_position = pos;
srp->m_last_good_position_age = 0;
@ -4176,7 +4176,7 @@ const ModSpec* Server::getModSpec(const std::string &modname)
return NULL;
}
v3f findSpawnPos(ServerMap &map)
v3f findSpawnPos(ServerMap &map, u8 clan)
{
//return v3f(50,50,50)*BS;
@ -4188,10 +4188,23 @@ v3f findSpawnPos(ServerMap &map)
#endif
#if 1
// Try to find a good place a few times
for(s32 i=0; i<1000; i++)
s32 baserange = 1;
switch(clan)
{
s32 range = 1 + i;
case 0:
baserange = 1;
break;
case 1:
baserange = -1000;
break;
case 2:
baserange = 1000;
break;
}
// Try to find a good place a few times
for(s32 i=0; i<50; i++)
{
s32 range = baserange + i;
// We're going to try to throw the player to this position
v2s16 nodepos2d = v2s16(-range + (myrand()%(range*2)),
-range + (myrand()%(range*2)));
@ -4299,8 +4312,9 @@ ServerRemotePlayer *Server::emergePlayer(const char *name, u16 peer_id)
infostream<<"Server: Finding spawn place for player \""
<<name<<"\""<<std::endl;
v3f pos = findSpawnPos(m_env->getServerMap());
v3f pos = findSpawnPos(m_env->getServerMap(), m_env->getPlayer(name)->getClan());
player = new ServerRemotePlayer(m_env, pos, peer_id, name);
ServerRemotePlayer *srp = static_cast<ServerRemotePlayer*>(player);

View File

@ -43,7 +43,7 @@ class IWritableCraftDefManager;
/*
Some random functions
*/
v3f findSpawnPos(ServerMap &map);
v3f findSpawnPos(ServerMap &map, u8 clan);
/*
A structure containing the data needed for queueing the fetching

View File

@ -162,6 +162,8 @@ std::string ServerRemotePlayer::getClientInitializationData()
writeF1000(os, getPitch());
// yaw
writeF1000(os, getYaw());
// clan
writeF1000(os, getClan());
return os.str();
}

View File

@ -1,262 +0,0 @@
/*
Minetest-c55
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "serverremoteplayer.h"
#include "main.h" // For g_settings
#include "settings.h"
#include "log.h"
#include "gamedef.h"
#include "inventory.h"
#include "environment.h"
#include "materials.h"
ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env):
Player(env->getGameDef()),
ServerActiveObject(env, v3f(0,0,0)),
m_last_good_position(0,0,0),
m_last_good_position_age(0),
m_wield_index(0),
m_inventory_not_sent(false),
m_hp_not_sent(false),
m_respawn_active(false),
m_is_in_environment(false),
m_time_from_last_punch(0),
m_position_not_sent(false)
{
}
ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 peer_id_,
const char *name_):
Player(env->getGameDef()),
ServerActiveObject(env, pos_),
m_last_good_position(0,0,0),
m_last_good_position_age(0),
m_wield_index(0),
m_inventory_not_sent(false),
m_hp_not_sent(false),
m_is_in_environment(false),
m_time_from_last_punch(0),
m_position_not_sent(false)
{
setPosition(pos_);
peer_id = peer_id_;
updateName(name_);
}
ServerRemotePlayer::~ServerRemotePlayer()
{
}
void ServerRemotePlayer::setPosition(const v3f &position)
{
Player::setPosition(position);
ServerActiveObject::setBasePosition(position);
m_position_not_sent = true;
}
Inventory* ServerRemotePlayer::getInventory()
{
return &inventory;
}
const Inventory* ServerRemotePlayer::getInventory() const
{
return &inventory;
}
InventoryLocation ServerRemotePlayer::getInventoryLocation() const
{
InventoryLocation loc;
loc.setPlayer(getName());
return loc;
}
void ServerRemotePlayer::setInventoryModified()
{
m_inventory_not_sent = true;
}
std::string ServerRemotePlayer::getWieldList() const
{
return "main";
}
int ServerRemotePlayer::getWieldIndex() const
{
return m_wield_index;
}
void ServerRemotePlayer::setWieldIndex(int i)
{
m_wield_index = i;
}
/* ServerActiveObject interface */
void ServerRemotePlayer::addedToEnvironment()
{
assert(!m_is_in_environment);
m_is_in_environment = true;
}
void ServerRemotePlayer::removingFromEnvironment()
{
assert(m_is_in_environment);
m_is_in_environment = false;
}
bool ServerRemotePlayer::unlimitedTransferDistance() const
{
return g_settings->getBool("unlimited_player_transfer_distance");
}
void ServerRemotePlayer::step(float dtime, bool send_recommended)
{
m_time_from_last_punch += dtime;
if(send_recommended == false)
return;
if(m_position_not_sent)
{
m_position_not_sent = false;
std::ostringstream os(std::ios::binary);
// command (0 = update position)
writeU8(os, 0);
// pos
writeV3F1000(os, getPosition());
// pitch
writeF1000(os, getPitch());
// yaw
writeF1000(os, getYaw());
// create message and add to list
ActiveObjectMessage aom(getId(), false, os.str());
m_messages_out.push_back(aom);
}
}
std::string ServerRemotePlayer::getClientInitializationData()
{
std::ostringstream os(std::ios::binary);
// version
writeU8(os, 0);
// name
os<<serializeString(getName());
// pos
writeV3F1000(os, getPosition());
// pitch
writeF1000(os, getPitch());
// yaw
writeF1000(os, getYaw());
return os.str();
}
std::string ServerRemotePlayer::getStaticData()
{
assert(0);
return "";
}
void ServerRemotePlayer::punch(ServerActiveObject *puncher,
float time_from_last_punch)
{
if(!puncher)
return;
// No effect if PvP disabled
if(g_settings->getBool("enable_pvp") == false){
if(puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER)
return;
}
// "Material" properties of a player
MaterialProperties mp;
mp.diggability = DIGGABLE_NORMAL;
mp.crackiness = -0.5;
mp.cuttability = 0.5;
IItemDefManager *idef = m_env->getGameDef()->idef();
ItemStack punchitem = puncher->getWieldedItem();
ToolDiggingProperties tp =
punchitem.getToolDiggingProperties(idef);
HittingProperties hitprop = getHittingProperties(&mp, &tp,
time_from_last_punch);
actionstream<<"Player "<<getName()<<" punched by "
<<puncher->getDescription()<<", damage "<<hitprop.hp
<<" HP"<<std::endl;
setHP(getHP() - hitprop.hp);
punchitem.addWear(hitprop.wear, idef);
puncher->setWieldedItem(punchitem);
if(hitprop.hp != 0)
{
std::ostringstream os(std::ios::binary);
// command (1 = punched)
writeU8(os, 1);
// damage
writeS16(os, hitprop.hp);
// create message and add to list
ActiveObjectMessage aom(getId(), false, os.str());
m_messages_out.push_back(aom);
}
}
void ServerRemotePlayer::rightClick(ServerActiveObject *clicker)
{
}
void ServerRemotePlayer::setPos(v3f pos)
{
setPosition(pos);
// Movement caused by this command is always valid
m_last_good_position = pos;
m_last_good_position_age = 0;
}
void ServerRemotePlayer::moveTo(v3f pos, bool continuous)
{
setPosition(pos);
// Movement caused by this command is always valid
m_last_good_position = pos;
m_last_good_position_age = 0;
}
void ServerRemotePlayer::setHP(s16 hp_)
{
s16 oldhp = hp;
// FIXME: don't hardcode maximum HP, make configurable per object
if(hp_ < 0)
hp_ = 0;
else if(hp_ > 20)
hp_ = 20;
hp = hp_;
if(hp != oldhp)
m_hp_not_sent = true;
}
s16 ServerRemotePlayer::getHP()
{
return hp;
}

View File

@ -1,455 +0,0 @@
/*
Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
(c) 2010 Perttu Ahola <celeron55@gmail.com>
*/
#include "utility.h"
#include "gettime.h"
#include "sha1.h"
#include "base64.h"
#include "log.h"
#include <iomanip>
TimeTaker::TimeTaker(const char *name, u32 *result)
{
m_name = name;
m_result = result;
m_running = true;
m_time1 = getTimeMs();
}
u32 TimeTaker::stop(bool quiet)
{
if(m_running)
{
u32 time2 = getTimeMs();
u32 dtime = time2 - m_time1;
if(m_result != NULL)
{
(*m_result) += dtime;
}
else
{
if(quiet == false)
infostream<<m_name<<" took "<<dtime<<"ms"<<std::endl;
}
m_running = false;
return dtime;
}
return 0;
}
u32 TimeTaker::getTime()
{
u32 time2 = getTimeMs();
u32 dtime = time2 - m_time1;
return dtime;
}
const v3s16 g_6dirs[6] =
{
// +right, +top, +back
v3s16( 0, 0, 1), // back
v3s16( 0, 1, 0), // top
v3s16( 1, 0, 0), // right
v3s16( 0, 0,-1), // front
v3s16( 0,-1, 0), // bottom
v3s16(-1, 0, 0) // left
};
const v3s16 g_26dirs[26] =
{
// +right, +top, +back
v3s16( 0, 0, 1), // back
v3s16( 0, 1, 0), // top
v3s16( 1, 0, 0), // right
v3s16( 0, 0,-1), // front
v3s16( 0,-1, 0), // bottom
v3s16(-1, 0, 0), // left
// 6
v3s16(-1, 1, 0), // top left
v3s16( 1, 1, 0), // top right
v3s16( 0, 1, 1), // top back
v3s16( 0, 1,-1), // top front
v3s16(-1, 0, 1), // back left
v3s16( 1, 0, 1), // back right
v3s16(-1, 0,-1), // front left
v3s16( 1, 0,-1), // front right
v3s16(-1,-1, 0), // bottom left
v3s16( 1,-1, 0), // bottom right
v3s16( 0,-1, 1), // bottom back
v3s16( 0,-1,-1), // bottom front
// 18
v3s16(-1, 1, 1), // top back-left
v3s16( 1, 1, 1), // top back-right
v3s16(-1, 1,-1), // top front-left
v3s16( 1, 1,-1), // top front-right
v3s16(-1,-1, 1), // bottom back-left
v3s16( 1,-1, 1), // bottom back-right
v3s16(-1,-1,-1), // bottom front-left
v3s16( 1,-1,-1), // bottom front-right
// 26
};
const v3s16 g_27dirs[27] =
{
// +right, +top, +back
v3s16( 0, 0, 1), // back
v3s16( 0, 1, 0), // top
v3s16( 1, 0, 0), // right
v3s16( 0, 0,-1), // front
v3s16( 0,-1, 0), // bottom
v3s16(-1, 0, 0), // left
// 6
v3s16(-1, 1, 0), // top left
v3s16( 1, 1, 0), // top right
v3s16( 0, 1, 1), // top back
v3s16( 0, 1,-1), // top front
v3s16(-1, 0, 1), // back left
v3s16( 1, 0, 1), // back right
v3s16(-1, 0,-1), // front left
v3s16( 1, 0,-1), // front right
v3s16(-1,-1, 0), // bottom left
v3s16( 1,-1, 0), // bottom right
v3s16( 0,-1, 1), // bottom back
v3s16( 0,-1,-1), // bottom front
// 18
v3s16(-1, 1, 1), // top back-left
v3s16( 1, 1, 1), // top back-right
v3s16(-1, 1,-1), // top front-left
v3s16( 1, 1,-1), // top front-right
v3s16(-1,-1, 1), // bottom back-left
v3s16( 1,-1, 1), // bottom back-right
v3s16(-1,-1,-1), // bottom front-left
v3s16( 1,-1,-1), // bottom front-right
// 26
v3s16(0,0,0),
};
static unsigned long next = 1;
/* RAND_MAX assumed to be 32767 */
int myrand(void)
{
next = next * 1103515245 + 12345;
return((unsigned)(next/65536) % 32768);
}
void mysrand(unsigned seed)
{
next = seed;
}
int myrand_range(int min, int max)
{
if(max-min > MYRAND_MAX)
{
errorstream<<"WARNING: myrand_range: max-min > MYRAND_MAX"<<std::endl;
assert(0);
}
if(min > max)
{
assert(0);
return max;
}
return (myrand()%(max-min+1))+min;
}
/*
blockpos: position of block in block coordinates
camera_pos: position of camera in nodes
camera_dir: an unit vector pointing to camera direction
range: viewing range
*/
bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
f32 camera_fov, f32 range, f32 *distance_ptr)
{
v3s16 blockpos_nodes = blockpos_b * MAP_BLOCKSIZE;
// Block center position
v3f blockpos(
((float)blockpos_nodes.X + MAP_BLOCKSIZE/2) * BS,
((float)blockpos_nodes.Y + MAP_BLOCKSIZE/2) * BS,
((float)blockpos_nodes.Z + MAP_BLOCKSIZE/2) * BS
);
// Block position relative to camera
v3f blockpos_relative = blockpos - camera_pos;
// Distance in camera direction (+=front, -=back)
f32 dforward = blockpos_relative.dotProduct(camera_dir);
// Total distance
f32 d = blockpos_relative.getLength();
if(distance_ptr)
*distance_ptr = d;
// If block is very close, it is always in sight
if(d < 1.44*1.44*MAP_BLOCKSIZE*BS/2)
return true;
// If block is far away, it's not in sight
if(d > range)
return false;
// Maximum radius of a block
f32 block_max_radius = 0.5*1.44*1.44*MAP_BLOCKSIZE*BS;
// If block is (nearly) touching the camera, don't
// bother validating further (that is, render it anyway)
if(d < block_max_radius)
return true;
// Cosine of the angle between the camera direction
// and the block direction (camera_dir is an unit vector)
f32 cosangle = dforward / d;
// Compensate for the size of the block
// (as the block has to be shown even if it's a bit off FOV)
// This is an estimate, plus an arbitary factor
cosangle += block_max_radius / d * 0.5;
// If block is not in the field of view, skip it
if(cosangle < cos(camera_fov / 2))
return false;
return true;
}
// Creates a string encoded in JSON format (almost equivalent to a C string literal)
std::string serializeJsonString(const std::string &plain)
{
std::ostringstream os(std::ios::binary);
os<<"\"";
for(size_t i = 0; i < plain.size(); i++)
{
char c = plain[i];
switch(c)
{
case '"': os<<"\\\""; break;
case '\\': os<<"\\\\"; break;
case '/': os<<"\\/"; break;
case '\b': os<<"\\b"; break;
case '\f': os<<"\\f"; break;
case '\n': os<<"\\n"; break;
case '\r': os<<"\\r"; break;
case '\t': os<<"\\t"; break;
default:
{
if(c >= 32 && c <= 126)
{
os<<c;
}
else
{
u32 cnum = (u32) (u8) c;
os<<"\\u"<<std::hex<<std::setw(4)<<std::setfill('0')<<cnum;
}
break;
}
}
}
os<<"\"";
return os.str();
}
// Reads a string encoded in JSON format
std::string deSerializeJsonString(std::istream &is)
{
std::ostringstream os(std::ios::binary);
char c, c2;
// Parse initial doublequote
is >> c;
if(c != '"')
throw SerializationError("JSON string must start with doublequote");
// Parse characters
for(;;)
{
c = is.get();
if(is.eof())
throw SerializationError("JSON string ended prematurely");
if(c == '"')
{
return os.str();
}
else if(c == '\\')
{
c2 = is.get();
if(is.eof())
throw SerializationError("JSON string ended prematurely");
switch(c2)
{
default: os<<c2; break;
case 'b': os<<'\b'; break;
case 'f': os<<'\f'; break;
case 'n': os<<'\n'; break;
case 'r': os<<'\r'; break;
case 't': os<<'\t'; break;
case 'u':
{
char hexdigits[4+1];
is.read(hexdigits, 4);
if(is.eof())
throw SerializationError("JSON string ended prematurely");
hexdigits[4] = 0;
std::istringstream tmp_is(hexdigits, std::ios::binary);
int hexnumber;
tmp_is >> std::hex >> hexnumber;
os<<((char)hexnumber);
break;
}
}
}
else
{
os<<c;
}
}
return os.str();
}
// Get an sha-1 hash of the player's name combined with
// the password entered. That's what the server uses as
// their password. (Exception : if the password field is
// blank, we send a blank password - this is for backwards
// compatibility with password-less players).
std::string translatePassword(std::string playername, std::wstring password)
{
if(password.length() == 0)
return "";
std::string slt = playername + wide_to_narrow(password);
SHA1 sha1;
sha1.addBytes(slt.c_str(), slt.length());
unsigned char *digest = sha1.getDigest();
std::string pwd = base64_encode(digest, 20);
free(digest);
return pwd;
}
PointedThing::PointedThing():
type(POINTEDTHING_NOTHING),
node_undersurface(0,0,0),
node_abovesurface(0,0,0),
object_id(-1),
is_fake(false)
{}
std::string PointedThing::dump() const
{
std::ostringstream os(std::ios::binary);
if(type == POINTEDTHING_NOTHING)
{
os<<"[nothing]";
}
else if(type == POINTEDTHING_NODE)
{
const v3s16 &u = node_undersurface;
const v3s16 &a = node_abovesurface;
os<<"[node under="<<u.X<<","<<u.Y<<","<<u.Z
<< " above="<<a.X<<","<<a.Y<<","<<a.Z
+ << (is_fake?" fake]":"]");
}
else if(type == POINTEDTHING_OBJECT)
{
os<<"[object "<<object_id<<"]";
}
else
{
os<<"[unknown PointedThing]";
}
return os.str();
}
void PointedThing::serialize(std::ostream &os) const
{
writeU8(os, 0); // version
writeU8(os, (u8)type);
if(type == POINTEDTHING_NOTHING)
{
// nothing
}
else if(type == POINTEDTHING_NODE)
{
writeV3S16(os, node_undersurface);
writeV3S16(os, node_abovesurface);
}
else if(type == POINTEDTHING_OBJECT)
{
writeS16(os, object_id);
}
}
void PointedThing::deSerialize(std::istream &is)
{
int version = readU8(is);
if(version != 0) throw SerializationError(
"unsupported PointedThing version");
type = (PointedThingType) readU8(is);
if(type == POINTEDTHING_NOTHING)
{
// nothing
}
else if(type == POINTEDTHING_NODE)
{
node_undersurface = readV3S16(is);
node_abovesurface = readV3S16(is);
}
else if(type == POINTEDTHING_OBJECT)
{
object_id = readS16(is);
}
else
{
throw SerializationError(
"unsupported PointedThingType");
}
}
bool PointedThing::operator==(const PointedThing &pt2) const
{
if(type != pt2.type)
return false;
if(type == POINTEDTHING_NODE)
{
if(node_undersurface != pt2.node_undersurface)
return false;
if(node_abovesurface != pt2.node_abovesurface)
return false;
}
else if(type == POINTEDTHING_OBJECT)
{
if(object_id != pt2.object_id)
return false;
}
return true;
}
bool PointedThing::operator!=(const PointedThing &pt2) const
{
return !(*this == pt2);
}

View File

@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <jmutex.h>
#include <jmutexautolock.h>
#include <cstring>
#include <cstdlib>
#include "common_irrlicht.h"
#include "debug.h"

File diff suppressed because it is too large Load Diff