forked from oerkki/voxelands
camp beds pt2
This commit is contained in:
parent
c8a2a51ee1
commit
38eeea4d55
|
@ -1722,7 +1722,7 @@ void content_mapnode_furniture(bool repeat)
|
|||
lists::add("creative",i);
|
||||
f->suffocation_per_second = 0;
|
||||
if (f->initial_metadata == NULL)
|
||||
f->initial_metadata = new BedNodeMetadata();
|
||||
f->initial_metadata = new CampBedNodeMetadata();
|
||||
|
||||
i = CONTENT_BED_CAMP_FOOT;
|
||||
f = &content_features(i);
|
||||
|
|
|
@ -725,7 +725,7 @@ void content_mob_init()
|
|||
f->hp = 30;
|
||||
f->model = "sheep.b3d";
|
||||
f->model_scale = v3f(0.8,0.8,0.8);
|
||||
f->model_rotation = v3f(0,-90,0);
|
||||
f->model_rotation = v3f(0,180,0);
|
||||
f->model_offset = v3f(0,0.6,0);
|
||||
f->setTexture("mob_sheep.png");
|
||||
f->setAnimationFrames(MA_STAND,40,60);
|
||||
|
|
|
@ -289,6 +289,173 @@ std::string BedNodeMetadata::getDrawSpecString(Player *player)
|
|||
return spec;
|
||||
}
|
||||
|
||||
/*
|
||||
CampBedNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
CampBedNodeMetadata proto_CampBedNodeMetadata();
|
||||
|
||||
CampBedNodeMetadata::CampBedNodeMetadata()
|
||||
{
|
||||
m_owner = "";
|
||||
m_nope = false;
|
||||
m_used = false;
|
||||
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
}
|
||||
u16 CampBedNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_BED_CAMP_HEAD;
|
||||
}
|
||||
NodeMetadata* CampBedNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
CampBedNodeMetadata *d = new CampBedNodeMetadata();
|
||||
d->m_owner = deSerializeString(is);
|
||||
int temp;
|
||||
is>>temp;
|
||||
d->m_nope = !!temp;
|
||||
is>>temp;
|
||||
d->m_used = !!temp;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* CampBedNodeMetadata::clone()
|
||||
{
|
||||
CampBedNodeMetadata *d = new CampBedNodeMetadata();
|
||||
d->m_owner = m_owner;
|
||||
d->m_nope = m_nope;
|
||||
d->m_used = m_used;
|
||||
return d;
|
||||
}
|
||||
void CampBedNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<serializeString(m_owner);
|
||||
os<<itos(m_nope) << " ";
|
||||
os<<itos(m_used) << " ";
|
||||
}
|
||||
bool CampBedNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||
{
|
||||
if (!m_used)
|
||||
return false;
|
||||
m_ticks++;
|
||||
if (m_ticks < 2)
|
||||
return false;
|
||||
|
||||
MapNode n = env->getMap().getNodeNoEx(pos);
|
||||
v3s16 fp = pos+n.getEffectedRotation();
|
||||
if (fp == pos)
|
||||
return false;
|
||||
|
||||
MapNode nn = env->getMap().getNodeNoEx(fp);
|
||||
nn.setContent(CONTENT_PARCEL);
|
||||
env->getMap().addNodeWithEvent(fp,nn);
|
||||
NodeMetadata *meta = env->getMap().getNodeMetadata(fp);
|
||||
if (meta) {
|
||||
Inventory* inv = meta->getInventory();
|
||||
if (inv) {
|
||||
InventoryList *l = inv->getList("0");
|
||||
if (l) {
|
||||
// add random dead grass/fur to parcel
|
||||
{
|
||||
u16 c = myrand_range(1,4);
|
||||
InventoryItem *item = InventoryItem::create(CONTENT_DEADGRASS,c);
|
||||
item = l->addItem(item);
|
||||
if (item)
|
||||
delete item;
|
||||
}
|
||||
if (myrand_range(0,1)) {
|
||||
InventoryItem *item = InventoryItem::create(CONTENT_CRAFTITEM_FUR,1);
|
||||
item = l->addItem(item);
|
||||
if (item)
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
n.setContent(CONTENT_DEADGRASS);
|
||||
env->setPostStepNodeSwap(pos,n);
|
||||
|
||||
return true;
|
||||
}
|
||||
bool CampBedNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
if (m_owner != "")
|
||||
return true;
|
||||
if (m_used)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
bool CampBedNodeMetadata::receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player)
|
||||
{
|
||||
if (fields["wake"] != "") {
|
||||
if (player->in_bed)
|
||||
m_used = false;
|
||||
m_nope = false;
|
||||
player->in_bed = false;
|
||||
m_owner = "";
|
||||
return true;
|
||||
}else if (fields["sleep"] != "") {
|
||||
if (m_used)
|
||||
return false;
|
||||
if (m_owner != "")
|
||||
return false;
|
||||
if (player->wake_timeout > 0.0) {
|
||||
m_nope = true;
|
||||
return true;
|
||||
}
|
||||
m_nope = false;
|
||||
player->in_bed = true;
|
||||
m_used = true;
|
||||
m_ticks = 0;
|
||||
m_owner = player->getName();
|
||||
return true;
|
||||
}else if (player->getName() == m_owner) { // this will happen if the player escape closes the form
|
||||
if (player->in_bed)
|
||||
m_used = false;
|
||||
m_nope = false;
|
||||
player->in_bed = false;
|
||||
m_owner = "";
|
||||
return true;
|
||||
}else if (m_nope) {
|
||||
m_nope = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
std::string CampBedNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
std::string spec("size[5,2.5]");
|
||||
if (m_owner == "") {
|
||||
if (m_used) {
|
||||
spec += "label[1.25,1;";
|
||||
spec += gettext("This bed is too uncomfortable to sleep in.");
|
||||
spec += "]";
|
||||
}else 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,1;3,1;wake;";
|
||||
spec += gettext("Get out of bed");
|
||||
spec += "]";
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
ChestNodeMetadata
|
||||
|
|
|
@ -128,6 +128,31 @@ private:
|
|||
bool m_nope;
|
||||
};
|
||||
|
||||
class CampBedNodeMetadata : public NodeMetadata
|
||||
{
|
||||
public:
|
||||
CampBedNodeMetadata();
|
||||
//~BedNodeMetadata();
|
||||
|
||||
virtual u16 typeId() const;
|
||||
static NodeMetadata* create(std::istream &is);
|
||||
virtual NodeMetadata* clone();
|
||||
virtual void serializeBody(std::ostream &os);
|
||||
|
||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||
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;
|
||||
bool m_used;
|
||||
int m_ticks;
|
||||
};
|
||||
|
||||
class ChestNodeMetadata : public NodeMetadata
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -765,7 +765,6 @@ void ServerEnvironment::step(float dtime)
|
|||
std::list<v3s16> players_blockpos;
|
||||
|
||||
bool sleepskip = true;
|
||||
bool did_wake = false;
|
||||
|
||||
/*
|
||||
Handle players
|
||||
|
@ -846,7 +845,6 @@ void ServerEnvironment::step(float dtime)
|
|||
setTimeOfDay(18000);
|
||||
}
|
||||
// wake up
|
||||
did_wake = true;
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue