sleeping in beds pt1
This commit is contained in:
parent
940d0a07d2
commit
2041d64a95
|
@ -232,7 +232,10 @@ Client::Client(
|
||||||
m_access_denied(false),
|
m_access_denied(false),
|
||||||
m_time_of_day_set(false),
|
m_time_of_day_set(false),
|
||||||
m_last_time_of_day_f(-1),
|
m_last_time_of_day_f(-1),
|
||||||
m_time_of_day_update_timer(0)
|
m_time_of_day_update_timer(0),
|
||||||
|
m_sleeping(false),
|
||||||
|
m_waking(false),
|
||||||
|
m_sleep_state(0.0)
|
||||||
{
|
{
|
||||||
m_mesh_update_thread.m_env = &m_env;
|
m_mesh_update_thread.m_env = &m_env;
|
||||||
m_packetcounter_timer = 0.0;
|
m_packetcounter_timer = 0.0;
|
||||||
|
@ -311,6 +314,18 @@ void Client::step(float dtime)
|
||||||
m_ignore_damage_timer = 0.0;
|
m_ignore_damage_timer = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_sleeping) {
|
||||||
|
m_sleep_state += dtime;
|
||||||
|
if (m_sleep_state > 1.0)
|
||||||
|
m_sleep_state = 1.0;
|
||||||
|
}else if (m_waking) {
|
||||||
|
m_sleep_state -= dtime;
|
||||||
|
if (m_sleep_state < 0.5) {
|
||||||
|
m_sleep_state = 0.0;
|
||||||
|
m_waking = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_time_of_day_update_timer += dtime;
|
m_time_of_day_update_timer += dtime;
|
||||||
|
|
||||||
//infostream<<"Client steps "<<dtime<<std::endl;
|
//infostream<<"Client steps "<<dtime<<std::endl;
|
||||||
|
@ -1592,7 +1607,15 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
||||||
break;
|
break;
|
||||||
case ENV_EVENT_NODE_PARTICLES: // node particles
|
case ENV_EVENT_NODE_PARTICLES: // node particles
|
||||||
break;
|
break;
|
||||||
case ENV_EVENT_NODEMOD: // nodemod
|
case ENV_EVENT_SLEEP: // go to sleep
|
||||||
|
m_sleeping = true;
|
||||||
|
m_waking = false;
|
||||||
|
m_sleep_state = 0.5;
|
||||||
|
break;
|
||||||
|
case ENV_EVENT_WAKE: // wake up
|
||||||
|
m_sleeping = false;
|
||||||
|
m_waking = true;
|
||||||
|
m_sleep_state = 1.0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
infostream<<"Client: unknown env_event: "<<type<<": "<<ev<<std::endl;
|
infostream<<"Client: unknown env_event: "<<type<<": "<<ev<<std::endl;
|
||||||
|
|
|
@ -342,6 +342,8 @@ public:
|
||||||
bool getFormState() {return m_form_open;}
|
bool getFormState() {return m_form_open;}
|
||||||
void setFormState(bool state) {m_form_open = state;}
|
void setFormState(bool state) {m_form_open = state;}
|
||||||
|
|
||||||
|
u8 getSleepAlpha() {return m_sleep_state*255;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Virtual methods from con::PeerHandler
|
// Virtual methods from con::PeerHandler
|
||||||
|
@ -408,10 +410,15 @@ private:
|
||||||
|
|
||||||
Queue<ClientEvent> m_client_event_queue;
|
Queue<ClientEvent> m_client_event_queue;
|
||||||
|
|
||||||
// time_of_day speed approximation for old protocol
|
// time_of_day speed approximation for old protocol
|
||||||
bool m_time_of_day_set;
|
bool m_time_of_day_set;
|
||||||
float m_last_time_of_day_f;
|
float m_last_time_of_day_f;
|
||||||
float m_time_of_day_update_timer;
|
float m_time_of_day_update_timer;
|
||||||
|
|
||||||
|
// sleep effects
|
||||||
|
bool m_sleeping;
|
||||||
|
bool m_waking;
|
||||||
|
float m_sleep_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !SERVER
|
#endif // !SERVER
|
||||||
|
|
|
@ -1231,6 +1231,8 @@ void content_mapnode_furniture(bool repeat)
|
||||||
lists::add("craftguide",i);
|
lists::add("craftguide",i);
|
||||||
lists::add("creative",i);
|
lists::add("creative",i);
|
||||||
f->suffocation_per_second = 0;
|
f->suffocation_per_second = 0;
|
||||||
|
if (f->initial_metadata == NULL)
|
||||||
|
f->initial_metadata = new BedNodeMetadata();
|
||||||
|
|
||||||
i = CONTENT_BED_FOOT;
|
i = CONTENT_BED_FOOT;
|
||||||
f = &content_features(i);
|
f = &content_features(i);
|
||||||
|
@ -1290,6 +1292,8 @@ void content_mapnode_furniture(bool repeat)
|
||||||
lists::add("craftguide",i);
|
lists::add("craftguide",i);
|
||||||
lists::add("creative",i);
|
lists::add("creative",i);
|
||||||
f->suffocation_per_second = 0;
|
f->suffocation_per_second = 0;
|
||||||
|
if (f->initial_metadata == NULL)
|
||||||
|
f->initial_metadata = new BedNodeMetadata();
|
||||||
|
|
||||||
i = CONTENT_BED_BLUE_FOOT;
|
i = CONTENT_BED_BLUE_FOOT;
|
||||||
f = &content_features(i);
|
f = &content_features(i);
|
||||||
|
@ -1349,6 +1353,8 @@ void content_mapnode_furniture(bool repeat)
|
||||||
lists::add("craftguide",i);
|
lists::add("craftguide",i);
|
||||||
lists::add("creative",i);
|
lists::add("creative",i);
|
||||||
f->suffocation_per_second = 0;
|
f->suffocation_per_second = 0;
|
||||||
|
if (f->initial_metadata == NULL)
|
||||||
|
f->initial_metadata = new BedNodeMetadata();
|
||||||
|
|
||||||
i = CONTENT_BED_GREEN_FOOT;
|
i = CONTENT_BED_GREEN_FOOT;
|
||||||
f = &content_features(i);
|
f = &content_features(i);
|
||||||
|
@ -1408,6 +1414,8 @@ void content_mapnode_furniture(bool repeat)
|
||||||
lists::add("craftguide",i);
|
lists::add("craftguide",i);
|
||||||
lists::add("creative",i);
|
lists::add("creative",i);
|
||||||
f->suffocation_per_second = 0;
|
f->suffocation_per_second = 0;
|
||||||
|
if (f->initial_metadata == NULL)
|
||||||
|
f->initial_metadata = new BedNodeMetadata();
|
||||||
|
|
||||||
i = CONTENT_BED_ORANGE_FOOT;
|
i = CONTENT_BED_ORANGE_FOOT;
|
||||||
f = &content_features(i);
|
f = &content_features(i);
|
||||||
|
@ -1467,6 +1475,8 @@ void content_mapnode_furniture(bool repeat)
|
||||||
lists::add("craftguide",i);
|
lists::add("craftguide",i);
|
||||||
lists::add("creative",i);
|
lists::add("creative",i);
|
||||||
f->suffocation_per_second = 0;
|
f->suffocation_per_second = 0;
|
||||||
|
if (f->initial_metadata == NULL)
|
||||||
|
f->initial_metadata = new BedNodeMetadata();
|
||||||
|
|
||||||
i = CONTENT_BED_PURPLE_FOOT;
|
i = CONTENT_BED_PURPLE_FOOT;
|
||||||
f = &content_features(i);
|
f = &content_features(i);
|
||||||
|
@ -1526,6 +1536,8 @@ void content_mapnode_furniture(bool repeat)
|
||||||
lists::add("craftguide",i);
|
lists::add("craftguide",i);
|
||||||
lists::add("creative",i);
|
lists::add("creative",i);
|
||||||
f->suffocation_per_second = 0;
|
f->suffocation_per_second = 0;
|
||||||
|
if (f->initial_metadata == NULL)
|
||||||
|
f->initial_metadata = new BedNodeMetadata();
|
||||||
|
|
||||||
i = CONTENT_BED_RED_FOOT;
|
i = CONTENT_BED_RED_FOOT;
|
||||||
f = &content_features(i);
|
f = &content_features(i);
|
||||||
|
@ -1585,6 +1597,8 @@ void content_mapnode_furniture(bool repeat)
|
||||||
lists::add("craftguide",i);
|
lists::add("craftguide",i);
|
||||||
lists::add("creative",i);
|
lists::add("creative",i);
|
||||||
f->suffocation_per_second = 0;
|
f->suffocation_per_second = 0;
|
||||||
|
if (f->initial_metadata == NULL)
|
||||||
|
f->initial_metadata = new BedNodeMetadata();
|
||||||
|
|
||||||
i = CONTENT_BED_YELLOW_FOOT;
|
i = CONTENT_BED_YELLOW_FOOT;
|
||||||
f = &content_features(i);
|
f = &content_features(i);
|
||||||
|
@ -1644,6 +1658,8 @@ void content_mapnode_furniture(bool repeat)
|
||||||
lists::add("craftguide",i);
|
lists::add("craftguide",i);
|
||||||
lists::add("creative",i);
|
lists::add("creative",i);
|
||||||
f->suffocation_per_second = 0;
|
f->suffocation_per_second = 0;
|
||||||
|
if (f->initial_metadata == NULL)
|
||||||
|
f->initial_metadata = new BedNodeMetadata();
|
||||||
|
|
||||||
i = CONTENT_BED_BLACK_FOOT;
|
i = CONTENT_BED_BLACK_FOOT;
|
||||||
f = &content_features(i);
|
f = &content_features(i);
|
||||||
|
|
|
@ -65,7 +65,7 @@ void SignNodeMetadata::serializeBody(std::ostream &os)
|
||||||
{
|
{
|
||||||
os<<serializeString(m_text);
|
os<<serializeString(m_text);
|
||||||
}
|
}
|
||||||
std::string SignNodeMetadata::getDrawSpecString()
|
std::string SignNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
std::string spec("size[5,2.5]");
|
std::string spec("size[5,2.5]");
|
||||||
spec += "field[0.75,0;4,1.5;text;;";
|
spec += "field[0.75,0;4,1.5;text;;";
|
||||||
|
@ -128,7 +128,7 @@ bool LockingSignNodeMetadata::receiveFields(std::string formname, std::map<std::
|
||||||
m_text = fields["text"];
|
m_text = fields["text"];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string LockingSignNodeMetadata::getDrawSpecString()
|
std::string LockingSignNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
std::string spec("size[5,2.5]");
|
std::string spec("size[5,2.5]");
|
||||||
spec += "field[0.75,0;4,1.5;text;;";
|
spec += "field[0.75,0;4,1.5;text;;";
|
||||||
|
@ -186,6 +186,109 @@ std::wstring FlagNodeMetadata::infoText()
|
||||||
return narrow_to_wide(buff);
|
return narrow_to_wide(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
BedNodeMetadata
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Prototype
|
||||||
|
BedNodeMetadata proto_BedNodeMetadata();
|
||||||
|
|
||||||
|
BedNodeMetadata::BedNodeMetadata()
|
||||||
|
{
|
||||||
|
NodeMetadata::registerType(typeId(), create);
|
||||||
|
m_owner = "";
|
||||||
|
m_nope = false;
|
||||||
|
}
|
||||||
|
u16 BedNodeMetadata::typeId() const
|
||||||
|
{
|
||||||
|
return CONTENT_BED_HEAD;
|
||||||
|
}
|
||||||
|
NodeMetadata* BedNodeMetadata::create(std::istream &is)
|
||||||
|
{
|
||||||
|
BedNodeMetadata *d = new BedNodeMetadata();
|
||||||
|
d->setOwner(deSerializeString(is));
|
||||||
|
int temp;
|
||||||
|
is>>temp;
|
||||||
|
d->m_nope = !!temp;
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
NodeMetadata* BedNodeMetadata::clone()
|
||||||
|
{
|
||||||
|
BedNodeMetadata *d = new BedNodeMetadata();
|
||||||
|
d->m_owner = m_owner;
|
||||||
|
d->m_nope = m_nope;
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
void BedNodeMetadata::serializeBody(std::ostream &os)
|
||||||
|
{
|
||||||
|
os<<serializeString(m_owner);
|
||||||
|
os<<itos(m_nope) << " ";
|
||||||
|
}
|
||||||
|
bool BedNodeMetadata::nodeRemovalDisabled()
|
||||||
|
{
|
||||||
|
if (m_owner != "")
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool BedNodeMetadata::receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player)
|
||||||
|
{
|
||||||
|
if (fields["wake"] != "") {
|
||||||
|
m_nope = false;
|
||||||
|
player->in_bed = false;
|
||||||
|
m_owner = "";
|
||||||
|
return true;
|
||||||
|
}else if (fields["sleep"] != "") {
|
||||||
|
if (m_owner != "")
|
||||||
|
return false;
|
||||||
|
if (player->wake_timeout > 0.0) {
|
||||||
|
m_nope = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
m_nope = false;
|
||||||
|
player->in_bed = true;
|
||||||
|
m_owner = player->getName();
|
||||||
|
return true;
|
||||||
|
}else if (player->getName() == m_owner) { // this will happen if the player escape closes the form
|
||||||
|
m_nope = false;
|
||||||
|
player->in_bed = false;
|
||||||
|
m_owner = "";
|
||||||
|
return true;
|
||||||
|
}else if (m_nope) {
|
||||||
|
m_nope = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::string BedNodeMetadata::getDrawSpecString(Player *player)
|
||||||
|
{
|
||||||
|
std::string spec("size[5,2.5]");
|
||||||
|
if (m_owner == "") {
|
||||||
|
if (m_nope) {
|
||||||
|
spec += "label[1.25,1;";
|
||||||
|
spec += gettext("You can't sleep yet.");
|
||||||
|
spec += "]";
|
||||||
|
}else{
|
||||||
|
spec += "button[1.25,1;3,1;sleep;";
|
||||||
|
spec += gettext("Go to sleep");
|
||||||
|
spec += "]";
|
||||||
|
}
|
||||||
|
}else if (m_owner != player->getName()) {
|
||||||
|
spec += "label[1.25,1;";
|
||||||
|
spec += gettext("Someone else is sleeping here.");
|
||||||
|
spec += "]";
|
||||||
|
}else if (m_nope) {
|
||||||
|
spec += "label[1.25,1;";
|
||||||
|
spec += gettext("You can't sleep yet.");
|
||||||
|
spec += "]";
|
||||||
|
}else{
|
||||||
|
spec += "button_exit[1.25,2;3,1;wake;";
|
||||||
|
spec += gettext("Get out of bed");
|
||||||
|
spec += "]";
|
||||||
|
}
|
||||||
|
return spec;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ChestNodeMetadata
|
ChestNodeMetadata
|
||||||
*/
|
*/
|
||||||
|
@ -240,7 +343,7 @@ bool ChestNodeMetadata::nodeRemovalDisabled()
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string ChestNodeMetadata::getDrawSpecString()
|
std::string ChestNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
"size[8,9]"
|
"size[8,9]"
|
||||||
|
@ -314,7 +417,7 @@ bool LockingChestNodeMetadata::nodeRemovalDisabled()
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string LockingChestNodeMetadata::getDrawSpecString()
|
std::string LockingChestNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
"size[8,9]"
|
"size[8,9]"
|
||||||
|
@ -388,7 +491,7 @@ bool SafeNodeMetadata::nodeRemovalDisabled()
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string SafeNodeMetadata::getDrawSpecString()
|
std::string SafeNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
"size[8,9]"
|
"size[8,9]"
|
||||||
|
@ -442,7 +545,7 @@ void ParcelNodeMetadata::serializeBody(std::ostream &os)
|
||||||
{
|
{
|
||||||
m_inventory->serialize(os);
|
m_inventory->serialize(os);
|
||||||
}
|
}
|
||||||
std::string ParcelNodeMetadata::getDrawSpecString()
|
std::string ParcelNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
"size[8,4]"
|
"size[8,4]"
|
||||||
|
@ -538,7 +641,7 @@ bool CreativeChestNodeMetadata::receiveFields(std::string formname, std::map<std
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string CreativeChestNodeMetadata::getDrawSpecString()
|
std::string CreativeChestNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
char buff[256];
|
char buff[256];
|
||||||
std::vector<lists::ListData> &list = lists::get("creative");
|
std::vector<lists::ListData> &list = lists::get("creative");
|
||||||
|
@ -816,7 +919,7 @@ bool FurnaceNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
std::string FurnaceNodeMetadata::getDrawSpecString()
|
std::string FurnaceNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
std::string spec("size[8,9]");
|
std::string spec("size[8,9]");
|
||||||
spec += "list[current_name;fuel;2,3;1,1;]";
|
spec += "list[current_name;fuel;2,3;1,1;]";
|
||||||
|
@ -1091,7 +1194,7 @@ bool LockingFurnaceNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
std::string LockingFurnaceNodeMetadata::getDrawSpecString()
|
std::string LockingFurnaceNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
std::string spec("size[8,9]");
|
std::string spec("size[8,9]");
|
||||||
spec += "list[current_name;fuel;2,3;1,1;]";
|
spec += "list[current_name;fuel;2,3;1,1;]";
|
||||||
|
@ -1355,7 +1458,7 @@ bool IncineratorNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *en
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
std::string IncineratorNodeMetadata::getDrawSpecString()
|
std::string IncineratorNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
std::string spec("size[8,7]");
|
std::string spec("size[8,7]");
|
||||||
spec += "label[1,0.5;";
|
spec += "label[1,0.5;";
|
||||||
|
@ -1583,7 +1686,7 @@ bool CraftGuideNodeMetadata::receiveFields(std::string formname, std::map<std::s
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string CraftGuideNodeMetadata::getDrawSpecString()
|
std::string CraftGuideNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
InventoryList *l = m_inventory->getList("result");
|
InventoryList *l = m_inventory->getList("result");
|
||||||
InventoryItem *q = l->getItem(0);
|
InventoryItem *q = l->getItem(0);
|
||||||
|
@ -1864,7 +1967,7 @@ bool ReverseCraftGuideNodeMetadata::receiveFields(std::string formname, std::map
|
||||||
//nothing happened
|
//nothing happened
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::string ReverseCraftGuideNodeMetadata::getDrawSpecString()
|
std::string ReverseCraftGuideNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -2070,7 +2173,7 @@ bool CookBookNodeMetadata::receiveFields(std::string formname, std::map<std::str
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string CookBookNodeMetadata::getDrawSpecString()
|
std::string CookBookNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
std::vector<lists::ListData> &list = lists::get("cooking");
|
std::vector<lists::ListData> &list = lists::get("cooking");
|
||||||
|
|
||||||
|
@ -2285,7 +2388,7 @@ bool DeCraftNodeMetadata::receiveFields(std::string formname, std::map<std::stri
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string DeCraftNodeMetadata::getDrawSpecString()
|
std::string DeCraftNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
std::vector<lists::ListData> &list = lists::get("decrafting");
|
std::vector<lists::ListData> &list = lists::get("decrafting");
|
||||||
char buff[256];
|
char buff[256];
|
||||||
|
@ -2389,7 +2492,7 @@ bool BookNodeMetadata::receiveFields(std::string formname, std::map<std::string,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BookNodeMetadata::getDrawSpecString()
|
std::string BookNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
std::string spec("size[6,6]");
|
std::string spec("size[6,6]");
|
||||||
spec += "field[1,1;5,1;title;";
|
spec += "field[1,1;5,1;title;";
|
||||||
|
@ -2488,7 +2591,7 @@ bool DiaryNodeMetadata::receiveFields(std::string formname, std::map<std::string
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DiaryNodeMetadata::getDrawSpecString()
|
std::string DiaryNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
std::string spec("size[6,6]");
|
std::string spec("size[6,6]");
|
||||||
spec += "field[1,1;5,1;title;";
|
spec += "field[1,1;5,1;title;";
|
||||||
|
@ -2660,7 +2763,7 @@ bool BookShelfNodeMetadata::nodeRemovalDisabled()
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string BookShelfNodeMetadata::getDrawSpecString()
|
std::string BookShelfNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
"size[8,7]"
|
"size[8,7]"
|
||||||
|
@ -2727,6 +2830,7 @@ NodeMetadata* ClockNodeMetadata::create(std::istream &is)
|
||||||
NodeMetadata* ClockNodeMetadata::clone()
|
NodeMetadata* ClockNodeMetadata::clone()
|
||||||
{
|
{
|
||||||
ClockNodeMetadata *d = new ClockNodeMetadata();
|
ClockNodeMetadata *d = new ClockNodeMetadata();
|
||||||
|
d->m_time = m_time;
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
void ClockNodeMetadata::serializeBody(std::ostream &os)
|
void ClockNodeMetadata::serializeBody(std::ostream &os)
|
||||||
|
@ -2939,7 +3043,7 @@ bool CauldronNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::string CauldronNodeMetadata::getDrawSpecString()
|
std::string CauldronNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
std::string("size[8,7]"
|
std::string("size[8,7]"
|
||||||
|
@ -3202,7 +3306,7 @@ bool ForgeNodeMetadata::receiveFields(std::string formname, std::map<std::string
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string ForgeNodeMetadata::getDrawSpecString()
|
std::string ForgeNodeMetadata::getDrawSpecString(Player *player)
|
||||||
{
|
{
|
||||||
std::string spec("size[8,8]");
|
std::string spec("size[8,8]");
|
||||||
if (m_show_craft) {
|
if (m_show_craft) {
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
m_text = fields["text"];
|
m_text = fields["text"];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public:
|
||||||
virtual std::string getText(){ return m_text; }
|
virtual std::string getText(){ return m_text; }
|
||||||
void setText(std::string t){ m_text = t; }
|
void setText(std::string t){ m_text = t; }
|
||||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
|
|
||||||
|
@ -106,6 +106,28 @@ private:
|
||||||
std::string m_owner;
|
std::string m_owner;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class BedNodeMetadata : public NodeMetadata
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BedNodeMetadata();
|
||||||
|
//~BedNodeMetadata();
|
||||||
|
|
||||||
|
virtual u16 typeId() const;
|
||||||
|
static NodeMetadata* create(std::istream &is);
|
||||||
|
virtual NodeMetadata* clone();
|
||||||
|
virtual void serializeBody(std::ostream &os);
|
||||||
|
|
||||||
|
virtual bool nodeRemovalDisabled();
|
||||||
|
|
||||||
|
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||||
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_owner;
|
||||||
|
std::string m_sleeper;
|
||||||
|
bool m_nope;
|
||||||
|
};
|
||||||
|
|
||||||
class ChestNodeMetadata : public NodeMetadata
|
class ChestNodeMetadata : public NodeMetadata
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -119,7 +141,7 @@ public:
|
||||||
virtual std::wstring infoText();
|
virtual std::wstring infoText();
|
||||||
virtual Inventory* getInventory() {return m_inventory;}
|
virtual Inventory* getInventory() {return m_inventory;}
|
||||||
virtual bool nodeRemovalDisabled();
|
virtual bool nodeRemovalDisabled();
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
|
|
||||||
|
@ -140,7 +162,7 @@ public:
|
||||||
virtual std::wstring infoText();
|
virtual std::wstring infoText();
|
||||||
virtual Inventory* getInventory() {return m_inventory;}
|
virtual Inventory* getInventory() {return m_inventory;}
|
||||||
virtual bool nodeRemovalDisabled();
|
virtual bool nodeRemovalDisabled();
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
|
|
||||||
|
@ -167,7 +189,7 @@ public:
|
||||||
virtual std::wstring infoText();
|
virtual std::wstring infoText();
|
||||||
virtual Inventory* getInventory() {return m_inventory;}
|
virtual Inventory* getInventory() {return m_inventory;}
|
||||||
virtual bool nodeRemovalDisabled();
|
virtual bool nodeRemovalDisabled();
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
|
|
||||||
|
@ -195,7 +217,7 @@ public:
|
||||||
virtual Inventory* getInventory() {return m_inventory;}
|
virtual Inventory* getInventory() {return m_inventory;}
|
||||||
virtual bool nodeRemovalDisabled();
|
virtual bool nodeRemovalDisabled();
|
||||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u16 m_page;
|
u16 m_page;
|
||||||
|
@ -213,7 +235,7 @@ public:
|
||||||
virtual NodeMetadata* clone();
|
virtual NodeMetadata* clone();
|
||||||
virtual void serializeBody(std::ostream &os);
|
virtual void serializeBody(std::ostream &os);
|
||||||
virtual Inventory* getInventory() {return m_inventory;}
|
virtual Inventory* getInventory() {return m_inventory;}
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Inventory *m_inventory;
|
Inventory *m_inventory;
|
||||||
|
@ -253,7 +275,7 @@ public:
|
||||||
virtual void inventoryModified();
|
virtual void inventoryModified();
|
||||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||||
virtual bool nodeRemovalDisabled();
|
virtual bool nodeRemovalDisabled();
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
virtual std::vector<NodeBox> getNodeBoxes(MapNode &n);
|
virtual std::vector<NodeBox> getNodeBoxes(MapNode &n);
|
||||||
|
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
|
@ -282,7 +304,7 @@ public:
|
||||||
virtual void inventoryModified();
|
virtual void inventoryModified();
|
||||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||||
virtual bool nodeRemovalDisabled();
|
virtual bool nodeRemovalDisabled();
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
virtual std::vector<NodeBox> getNodeBoxes(MapNode &n);
|
virtual std::vector<NodeBox> getNodeBoxes(MapNode &n);
|
||||||
|
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
|
@ -340,7 +362,7 @@ public:
|
||||||
virtual void inventoryModified();
|
virtual void inventoryModified();
|
||||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||||
virtual bool nodeRemovalDisabled();
|
virtual bool nodeRemovalDisabled();
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
virtual std::vector<NodeBox> getNodeBoxes(MapNode &n);
|
virtual std::vector<NodeBox> getNodeBoxes(MapNode &n);
|
||||||
|
|
||||||
bool m_should_fire;
|
bool m_should_fire;
|
||||||
|
@ -370,7 +392,7 @@ public:
|
||||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
u16 getPage() {return m_page;}
|
u16 getPage() {return m_page;}
|
||||||
|
|
||||||
|
@ -397,7 +419,7 @@ public:
|
||||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
u16 getPage() {return m_page;}
|
u16 getPage() {return m_page;}
|
||||||
|
|
||||||
|
@ -428,7 +450,7 @@ public:
|
||||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
u16 getPage() {return m_page;}
|
u16 getPage() {return m_page;}
|
||||||
|
|
||||||
|
@ -454,7 +476,7 @@ public:
|
||||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
u16 getPage() {return m_page;}
|
u16 getPage() {return m_page;}
|
||||||
|
|
||||||
|
@ -476,7 +498,7 @@ public:
|
||||||
virtual bool nodeRemovalDisabled();
|
virtual bool nodeRemovalDisabled();
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
std::string getContent() { return m_content; }
|
std::string getContent() { return m_content; }
|
||||||
|
|
||||||
|
@ -498,7 +520,7 @@ public:
|
||||||
virtual bool nodeRemovalDisabled();
|
virtual bool nodeRemovalDisabled();
|
||||||
virtual bool import(NodeMetadata *meta);
|
virtual bool import(NodeMetadata *meta);
|
||||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
virtual std::string getOwner(){ return m_owner; }
|
virtual std::string getOwner(){ return m_owner; }
|
||||||
virtual void setOwner(std::string t){ m_owner = t; }
|
virtual void setOwner(std::string t){ m_owner = t; }
|
||||||
|
@ -547,7 +569,7 @@ public:
|
||||||
virtual void serializeBody(std::ostream &os);
|
virtual void serializeBody(std::ostream &os);
|
||||||
virtual Inventory* getInventory() {return m_inventory;}
|
virtual Inventory* getInventory() {return m_inventory;}
|
||||||
virtual bool nodeRemovalDisabled();
|
virtual bool nodeRemovalDisabled();
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
virtual std::vector<NodeBox> getNodeBoxes(MapNode &n);
|
virtual std::vector<NodeBox> getNodeBoxes(MapNode &n);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -583,7 +605,7 @@ public:
|
||||||
virtual void inventoryModified();
|
virtual void inventoryModified();
|
||||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||||
virtual bool nodeRemovalDisabled();
|
virtual bool nodeRemovalDisabled();
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
virtual std::vector<NodeBox> getNodeBoxes(MapNode &n);
|
virtual std::vector<NodeBox> getNodeBoxes(MapNode &n);
|
||||||
|
|
||||||
u8 m_water_level;
|
u8 m_water_level;
|
||||||
|
@ -613,7 +635,7 @@ public:
|
||||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||||
virtual bool nodeRemovalDisabled();
|
virtual bool nodeRemovalDisabled();
|
||||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||||
virtual std::string getDrawSpecString();
|
virtual std::string getDrawSpecString(Player *player);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_show_craft;
|
bool m_show_craft;
|
||||||
|
|
|
@ -204,8 +204,9 @@ u32 Environment::getDayNightRatio()
|
||||||
return time_to_daynight_ratio(m_time_of_day_f*24000.0);
|
return time_to_daynight_ratio(m_time_of_day_f*24000.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Environment::stepTimeOfDay(float dtime)
|
float Environment::stepTimeOfDay(float dtime)
|
||||||
{
|
{
|
||||||
|
float r = m_time_of_day_f;
|
||||||
m_time_counter += dtime;
|
m_time_counter += dtime;
|
||||||
f32 speed = m_time_of_day_speed * 24000./(24.*3600);
|
f32 speed = m_time_of_day_speed * 24000./(24.*3600);
|
||||||
u32 units = (u32)(m_time_counter*speed);
|
u32 units = (u32)(m_time_counter*speed);
|
||||||
|
@ -229,6 +230,9 @@ void Environment::stepTimeOfDay(float dtime)
|
||||||
if (m_time_of_day_f < 0.0)
|
if (m_time_of_day_f < 0.0)
|
||||||
m_time_of_day_f += 1.0;
|
m_time_of_day_f += 1.0;
|
||||||
}
|
}
|
||||||
|
if (m_time_of_day_f < r)
|
||||||
|
return (m_time_of_day_f+1.0)-r;
|
||||||
|
return m_time_of_day_f-r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -301,7 +305,8 @@ ServerEnvironment::ServerEnvironment(ServerMap *map, Server *server):
|
||||||
m_server(server),
|
m_server(server),
|
||||||
m_send_recommended_timer(0),
|
m_send_recommended_timer(0),
|
||||||
m_game_time(0),
|
m_game_time(0),
|
||||||
m_game_time_fraction_counter(0)
|
m_game_time_fraction_counter(0),
|
||||||
|
m_players_sleeping(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -739,7 +744,8 @@ void ServerEnvironment::step(float dtime)
|
||||||
|
|
||||||
//TimeTaker timer("ServerEnv step");
|
//TimeTaker timer("ServerEnv step");
|
||||||
|
|
||||||
stepTimeOfDay(dtime);
|
float time_diff = stepTimeOfDay(dtime);
|
||||||
|
time_diff *= 24000.0;
|
||||||
|
|
||||||
// Get some settings
|
// Get some settings
|
||||||
bool footprints = g_settings->getBool("enable_footprints");
|
bool footprints = g_settings->getBool("enable_footprints");
|
||||||
|
@ -758,17 +764,27 @@ void ServerEnvironment::step(float dtime)
|
||||||
bool blockstep = m_active_blocks_management_interval.step(dtime, 2.0);
|
bool blockstep = m_active_blocks_management_interval.step(dtime, 2.0);
|
||||||
std::list<v3s16> players_blockpos;
|
std::list<v3s16> players_blockpos;
|
||||||
|
|
||||||
|
bool sleepskip = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Handle players
|
Handle players
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
ScopeProfiler sp(g_profiler, "SEnv: handle players avg", SPT_AVG);
|
ScopeProfiler sp(g_profiler, "SEnv: handle players avg", SPT_AVG);
|
||||||
|
int pc = 0;
|
||||||
for (core::list<Player*>::Iterator i = m_players.begin(); i != m_players.end(); i++) {
|
for (core::list<Player*>::Iterator i = m_players.begin(); i != m_players.end(); i++) {
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
|
|
||||||
// Ignore disconnected players
|
// Ignore disconnected players
|
||||||
if (player->peer_id == 0)
|
if (player->peer_id == 0)
|
||||||
continue;
|
continue;
|
||||||
|
pc++;
|
||||||
|
|
||||||
|
if (!player->in_bed)
|
||||||
|
sleepskip = false;
|
||||||
|
|
||||||
|
if (player->wake_timeout > 0.0)
|
||||||
|
player->wake_timeout -= time_diff;
|
||||||
|
|
||||||
v3f playerpos = player->getPosition();
|
v3f playerpos = player->getPosition();
|
||||||
|
|
||||||
|
@ -809,12 +825,55 @@ void ServerEnvironment::step(float dtime)
|
||||||
players_blockpos.push_back(blockpos);
|
players_blockpos.push_back(blockpos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!pc)
|
||||||
|
sleepskip = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Manage active block list
|
Manage active block list
|
||||||
*/
|
*/
|
||||||
if (blockstep) {
|
if (blockstep) {
|
||||||
|
if (sleepskip) {
|
||||||
|
if (m_players_sleeping) {
|
||||||
|
// advance time to dawn or dusk
|
||||||
|
if (m_time_of_day < 6000) {
|
||||||
|
setTimeOfDay(6000);
|
||||||
|
}else if (m_time_of_day > 18000) {
|
||||||
|
m_time++;
|
||||||
|
setTimeOfDay(6000);
|
||||||
|
}else{
|
||||||
|
setTimeOfDay(18000);
|
||||||
|
}
|
||||||
|
// wake up
|
||||||
|
addEnvEvent(ENV_EVENT_WAKE,v3f(0,0,0),"");
|
||||||
|
for (core::list<Player*>::Iterator i = m_players.begin(); i != m_players.end(); i++) {
|
||||||
|
Player *player = *i;
|
||||||
|
|
||||||
|
// Ignore disconnected players
|
||||||
|
if (player->peer_id == 0)
|
||||||
|
continue;
|
||||||
|
player->in_bed = false;
|
||||||
|
player->wake_timeout = 10000;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// go to sleep
|
||||||
|
addEnvEvent(ENV_EVENT_SLEEP,v3f(0,0,0),"");
|
||||||
|
}
|
||||||
|
|
||||||
|
m_players_sleeping = !m_players_sleeping;
|
||||||
|
}else if (m_players_sleeping) {
|
||||||
|
// wake up
|
||||||
|
addEnvEvent(ENV_EVENT_WAKE,v3f(0,0,0),"");
|
||||||
|
for (core::list<Player*>::Iterator i = m_players.begin(); i != m_players.end(); i++) {
|
||||||
|
Player *player = *i;
|
||||||
|
|
||||||
|
// Ignore disconnected players
|
||||||
|
if (player->peer_id == 0)
|
||||||
|
continue;
|
||||||
|
player->in_bed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ScopeProfiler sp(g_profiler, "SEnv: manage act. block list avg /2s", SPT_AVG);
|
ScopeProfiler sp(g_profiler, "SEnv: manage act. block list avg /2s", SPT_AVG);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -56,7 +56,8 @@ class ServerActiveObject;
|
||||||
#define ENV_EVENT_DIG_PARTICLES 2
|
#define ENV_EVENT_DIG_PARTICLES 2
|
||||||
#define ENV_EVENT_PUNCH_PARTICLES 3
|
#define ENV_EVENT_PUNCH_PARTICLES 3
|
||||||
#define ENV_EVENT_NODE_PARTICLES 4
|
#define ENV_EVENT_NODE_PARTICLES 4
|
||||||
#define ENV_EVENT_NODEMOD 5
|
#define ENV_EVENT_SLEEP 5
|
||||||
|
#define ENV_EVENT_WAKE 6
|
||||||
|
|
||||||
#define ENV_SEASON_SUMMER 0
|
#define ENV_SEASON_SUMMER 0
|
||||||
#define ENV_SEASON_AUTUMN 1
|
#define ENV_SEASON_AUTUMN 1
|
||||||
|
@ -71,6 +72,15 @@ struct EnvEvent {
|
||||||
|
|
||||||
EnvEvent():
|
EnvEvent():
|
||||||
type(ENV_EVENT_NONE),
|
type(ENV_EVENT_NONE),
|
||||||
|
pos(0,0,0),
|
||||||
|
data(""),
|
||||||
|
except_player(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
EnvEvent(u8 ctype):
|
||||||
|
type(ctype),
|
||||||
|
pos(0,0,0),
|
||||||
data(""),
|
data(""),
|
||||||
except_player(NULL)
|
except_player(NULL)
|
||||||
{
|
{
|
||||||
|
@ -156,7 +166,7 @@ public:
|
||||||
return m_time_of_day_f;
|
return m_time_of_day_f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stepTimeOfDay(float dtime);
|
float stepTimeOfDay(float dtime);
|
||||||
|
|
||||||
void setTimeOfDaySpeed(float speed)
|
void setTimeOfDaySpeed(float speed)
|
||||||
{
|
{
|
||||||
|
@ -437,6 +447,8 @@ private:
|
||||||
u32 m_game_time;
|
u32 m_game_time;
|
||||||
// A helper variable for incrementing the latter
|
// A helper variable for incrementing the latter
|
||||||
float m_game_time_fraction_counter;
|
float m_game_time_fraction_counter;
|
||||||
|
// whether players are sleeping
|
||||||
|
int m_players_sleeping;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
|
|
|
@ -173,7 +173,7 @@ public:
|
||||||
NodeMetadata *meta = m_client->getEnv().getMap().getNodeMetadata(m_p);
|
NodeMetadata *meta = m_client->getEnv().getMap().getNodeMetadata(m_p);
|
||||||
if (!meta)
|
if (!meta)
|
||||||
return "";
|
return "";
|
||||||
return meta->getDrawSpecString();
|
return meta->getDrawSpecString(m_client->getLocalPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeMetadata *getMeta()
|
NodeMetadata *getMeta()
|
||||||
|
@ -1807,7 +1807,7 @@ void the_game(
|
||||||
|
|
||||||
if (input->wasKeyDown(getKeySetting(VLKC_EXAMINE)) && !random_input) {
|
if (input->wasKeyDown(getKeySetting(VLKC_EXAMINE)) && !random_input) {
|
||||||
// If metadata provides an inventory view, activate it
|
// If metadata provides an inventory view, activate it
|
||||||
if (meta && meta->getDrawSpecString() != "") {
|
if (meta && meta->getDrawSpecString(client.getLocalPlayer()) != "") {
|
||||||
infostream<<"Launching custom inventory view"<<std::endl;
|
infostream<<"Launching custom inventory view"<<std::endl;
|
||||||
|
|
||||||
InventoryLocation inventoryloc;
|
InventoryLocation inventoryloc;
|
||||||
|
@ -1816,7 +1816,7 @@ void the_game(
|
||||||
/* Create menu */
|
/* Create menu */
|
||||||
|
|
||||||
GUIFormSpecMenu *menu = new GUIFormSpecMenu(guienv, guiroot, -1, &g_menumgr, &client);
|
GUIFormSpecMenu *menu = new GUIFormSpecMenu(guienv, guiroot, -1, &g_menumgr, &client);
|
||||||
menu->setFormSpec(meta->getDrawSpecString(), inventoryloc);
|
menu->setFormSpec(meta->getDrawSpecString(client.getLocalPlayer()), inventoryloc);
|
||||||
menu->setFormIO(new NodeMetadataFormIO(nodepos, &client));
|
menu->setFormIO(new NodeMetadataFormIO(nodepos, &client));
|
||||||
menu->drop();
|
menu->drop();
|
||||||
{
|
{
|
||||||
|
|
|
@ -284,7 +284,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldSpec spec = FieldSpec(
|
FieldSpec spec = FieldSpec(
|
||||||
narrow_to_wide(fname.c_str()),
|
fname.c_str(),
|
||||||
narrow_to_wide(flabel.c_str()),
|
narrow_to_wide(flabel.c_str()),
|
||||||
narrow_to_wide(fdefault.c_str()),
|
narrow_to_wide(fdefault.c_str()),
|
||||||
258+m_fields.size()
|
258+m_fields.size()
|
||||||
|
@ -354,7 +354,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
||||||
errorstream<<"WARNING: invalid use of label without a size[] element"<<std::endl;
|
errorstream<<"WARNING: invalid use of label without a size[] element"<<std::endl;
|
||||||
|
|
||||||
FieldSpec spec = FieldSpec(
|
FieldSpec spec = FieldSpec(
|
||||||
narrow_to_wide(""),
|
"",
|
||||||
narrow_to_wide(flabel.c_str()),
|
narrow_to_wide(flabel.c_str()),
|
||||||
narrow_to_wide(""),
|
narrow_to_wide(""),
|
||||||
258+m_fields.size()
|
258+m_fields.size()
|
||||||
|
@ -377,7 +377,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
||||||
errorstream<<"WARNING: invalid use of button without a size[] element"<<std::endl;
|
errorstream<<"WARNING: invalid use of button without a size[] element"<<std::endl;
|
||||||
|
|
||||||
FieldSpec spec = FieldSpec(
|
FieldSpec spec = FieldSpec(
|
||||||
narrow_to_wide(fname.c_str()),
|
fname.c_str(),
|
||||||
narrow_to_wide(flabel.c_str()),
|
narrow_to_wide(flabel.c_str()),
|
||||||
narrow_to_wide(""),
|
narrow_to_wide(""),
|
||||||
258+m_fields.size()
|
258+m_fields.size()
|
||||||
|
@ -404,7 +404,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
||||||
errorstream<<"WARNING: invalid use of image_button without a size[] element"<<std::endl;
|
errorstream<<"WARNING: invalid use of image_button without a size[] element"<<std::endl;
|
||||||
|
|
||||||
FieldSpec spec = FieldSpec(
|
FieldSpec spec = FieldSpec(
|
||||||
narrow_to_wide(fname.c_str()),
|
fname.c_str(),
|
||||||
narrow_to_wide(flabel.c_str()),
|
narrow_to_wide(flabel.c_str()),
|
||||||
narrow_to_wide(fimage.c_str()),
|
narrow_to_wide(fimage.c_str()),
|
||||||
258+m_fields.size()
|
258+m_fields.size()
|
||||||
|
@ -656,11 +656,11 @@ void GUIFormSpecMenu::acceptInput()
|
||||||
const FieldSpec &s = m_fields[i];
|
const FieldSpec &s = m_fields[i];
|
||||||
if (s.send) {
|
if (s.send) {
|
||||||
if (s.is_button) {
|
if (s.is_button) {
|
||||||
fields[wide_to_narrow(s.fname.c_str())] = s.flabel.c_str();
|
fields[s.fname.c_str()] = L"true";
|
||||||
}else{
|
}else{
|
||||||
e = getElementFromId(s.fid);
|
e = getElementFromId(s.fid);
|
||||||
if (e != NULL)
|
if (e != NULL)
|
||||||
fields[wide_to_narrow(s.fname.c_str())] = e->getText();
|
fields[s.fname.c_str()] = e->getText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ class GUIFormSpecMenu : public GUIModalMenu
|
||||||
FieldSpec()
|
FieldSpec()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
FieldSpec(const std::wstring name, const std::wstring label, const std::wstring fdeflt, int id):
|
FieldSpec(const std::string name, const std::wstring label, const std::wstring fdeflt, int id):
|
||||||
fname(name),
|
fname(name),
|
||||||
flabel(label),
|
flabel(label),
|
||||||
fdefault(fdeflt),
|
fdefault(fdeflt),
|
||||||
|
@ -154,7 +154,7 @@ class GUIFormSpecMenu : public GUIModalMenu
|
||||||
is_button = false;
|
is_button = false;
|
||||||
is_exit = false;
|
is_exit = false;
|
||||||
}
|
}
|
||||||
std::wstring fname;
|
std::string fname;
|
||||||
std::wstring flabel;
|
std::wstring flabel;
|
||||||
std::wstring fdefault;
|
std::wstring fdefault;
|
||||||
int fid;
|
int fid;
|
||||||
|
|
|
@ -3752,7 +3752,9 @@ void ClientMap::renderPostFx()
|
||||||
m_camera_mutex.Unlock();
|
m_camera_mutex.Unlock();
|
||||||
video::SColor post_effect_color(0,0,0,0);
|
video::SColor post_effect_color(0,0,0,0);
|
||||||
|
|
||||||
if (m_client->getFormState()) {
|
if (m_client->getSleepAlpha() > 0) {
|
||||||
|
post_effect_color = video::SColor(m_client->getSleepAlpha(),0,0,0);
|
||||||
|
}else if (m_client->getFormState()) {
|
||||||
post_effect_color = video::SColor(128,0,0,0);
|
post_effect_color = video::SColor(128,0,0,0);
|
||||||
}else{
|
}else{
|
||||||
MapNode n = getNodeNoEx(floatToInt(camera_position, BS));
|
MapNode n = getNodeNoEx(floatToInt(camera_position, BS));
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
virtual bool nodeRemovalDisabled(){return false;}
|
virtual bool nodeRemovalDisabled(){return false;}
|
||||||
// Used to make custom inventory menus.
|
// Used to make custom inventory menus.
|
||||||
// See format in guiInventoryMenu.cpp.
|
// See format in guiInventoryMenu.cpp.
|
||||||
virtual std::string getDrawSpecString(){return "";}
|
virtual std::string getDrawSpecString(Player *player){return "";}
|
||||||
// the node owner - if not "" then only the owner can dig the node
|
// the node owner - if not "" then only the owner can dig the node
|
||||||
virtual std::string getOwner(){ return std::string(""); }
|
virtual std::string getOwner(){ return std::string(""); }
|
||||||
virtual void setOwner(std::string t){ }
|
virtual void setOwner(std::string t){ }
|
||||||
|
|
|
@ -48,6 +48,8 @@ Player::Player():
|
||||||
in_water_stable(false),
|
in_water_stable(false),
|
||||||
is_climbing(false),
|
is_climbing(false),
|
||||||
swimming_up(false),
|
swimming_up(false),
|
||||||
|
in_bed(false),
|
||||||
|
wake_timeout(0.0),
|
||||||
craftresult_is_preview(true),
|
craftresult_is_preview(true),
|
||||||
hp(20),
|
hp(20),
|
||||||
air(20),
|
air(20),
|
||||||
|
@ -226,6 +228,7 @@ void Player::serialize(std::ostream &os)
|
||||||
}
|
}
|
||||||
if (m_given_clothes)
|
if (m_given_clothes)
|
||||||
args.set("clothes_given","true");
|
args.set("clothes_given","true");
|
||||||
|
args.setFloat("wake_timeout",wake_timeout);
|
||||||
|
|
||||||
args.writeLines(os);
|
args.writeLines(os);
|
||||||
|
|
||||||
|
@ -300,6 +303,12 @@ void Player::deSerialize(std::istream &is)
|
||||||
m_given_clothes = false;
|
m_given_clothes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args.exists("wake_timeout")) {
|
||||||
|
wake_timeout = args.getFloat("wake_timeout");
|
||||||
|
}else{
|
||||||
|
wake_timeout = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
inventory.deSerialize(is);
|
inventory.deSerialize(is);
|
||||||
checkInventory();
|
checkInventory();
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,6 +180,11 @@ public:
|
||||||
bool is_climbing;
|
bool is_climbing;
|
||||||
bool swimming_up;
|
bool swimming_up;
|
||||||
|
|
||||||
|
// whether the player is in bed
|
||||||
|
bool in_bed;
|
||||||
|
// set for 10 hours (10000) after the player last woke up
|
||||||
|
f32 wake_timeout;
|
||||||
|
|
||||||
u8 light;
|
u8 light;
|
||||||
|
|
||||||
Inventory inventory;
|
Inventory inventory;
|
||||||
|
|
|
@ -5536,12 +5536,14 @@ void Server::SendEnvEvent(u8 type, v3f pos, std::string &data, Player *except_pl
|
||||||
if (except_player != NULL && except_player->peer_id == client->peer_id)
|
if (except_player != NULL && except_player->peer_id == client->peer_id)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Player *player = m_env.getPlayer(client->peer_id);
|
if (type != ENV_EVENT_WAKE && type != ENV_EVENT_SLEEP) {
|
||||||
if (player) {
|
Player *player = m_env.getPlayer(client->peer_id);
|
||||||
// don't send to far off players (2 mapblocks)
|
if (player) {
|
||||||
v3f player_pos = player->getPosition();
|
// don't send to far off players (2 mapblocks)
|
||||||
if (player_pos.getDistanceFrom(pos) > 320.0)
|
v3f player_pos = player->getPosition();
|
||||||
continue;
|
if (player_pos.getDistanceFrom(pos) > 320.0)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send as reliable
|
// Send as reliable
|
||||||
|
|
Loading…
Reference in New Issue