forked from oerkki/voxelands
split up content_nodemeta.cpp
This commit is contained in:
parent
8ba807f266
commit
58164a9dcb
|
@ -197,7 +197,20 @@ set(common_SRCS
|
|||
log.cpp
|
||||
content_sao.cpp
|
||||
mapgen.cpp
|
||||
content_nodemeta.cpp
|
||||
nodemeta/content_nodemeta_circuits.cpp
|
||||
nodemeta/content_nodemeta_sign.cpp
|
||||
nodemeta/content_nodemeta_flag.cpp
|
||||
nodemeta/content_nodemeta_bed.cpp
|
||||
nodemeta/content_nodemeta_storage_old.cpp
|
||||
nodemeta/content_nodemeta_storage_prefill.cpp
|
||||
nodemeta/content_nodemeta_borderstone.cpp
|
||||
nodemeta/content_nodemeta_cooking.cpp
|
||||
nodemeta/content_nodemeta_tnt.cpp
|
||||
nodemeta/content_nodemeta_incinerator.cpp
|
||||
nodemeta/content_nodemeta_blocks.cpp
|
||||
nodemeta/content_nodemeta_forge.cpp
|
||||
nodemeta/content_nodemeta_book.cpp
|
||||
nodemeta/content_nodemeta_book_guide.cpp
|
||||
content_craft.cpp
|
||||
content_craftitem.cpp
|
||||
content_clothesitem.cpp
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,284 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_nodemeta.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2017 <lisa@ltmnet.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 3 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, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "content_mapnode.h"
|
||||
#include "environment.h"
|
||||
|
||||
|
||||
/*
|
||||
BedNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
BedNodeMetadata proto_BedNodeMetadata();
|
||||
|
||||
BedNodeMetadata::BedNodeMetadata()
|
||||
{
|
||||
m_owner = "";
|
||||
m_nope = false;
|
||||
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
}
|
||||
u16 BedNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_BED_HEAD;
|
||||
}
|
||||
NodeMetadata* BedNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
BedNodeMetadata *d = new BedNodeMetadata();
|
||||
d->m_owner = 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,1;3,1;wake;";
|
||||
spec += gettext("Get out of bed");;
|
||||
spec += "]";
|
||||
}
|
||||
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;
|
||||
|
||||
// add random dead grass/fur to parcel
|
||||
{
|
||||
u16 c = myrand_range(1,4);
|
||||
InventoryItem *item = InventoryItem::create(CONTENT_DEADGRASS,c);
|
||||
env->dropToParcel(pos,item);
|
||||
}
|
||||
if (myrand_range(0,1)) {
|
||||
InventoryItem *item = InventoryItem::create(CONTENT_CRAFTITEM_FUR,1);
|
||||
env->dropToParcel(pos,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;
|
||||
}
|
|
@ -0,0 +1,501 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_nodemeta.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2017 <lisa@ltmnet.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 3 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, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "inventory.h"
|
||||
#include "content_mapnode.h"
|
||||
#include "environment.h"
|
||||
|
||||
/*
|
||||
BookShelfNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
BookShelfNodeMetadata proto_BookShelfNodeMetadata;
|
||||
|
||||
BookShelfNodeMetadata::BookShelfNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("0", 14);
|
||||
InventoryList *l = m_inventory->getList("0");
|
||||
l->setStackable(false);
|
||||
l->addAllowed(CONTENT_BOOK);
|
||||
l->addAllowed(CONTENT_COOK_BOOK);
|
||||
l->addAllowed(CONTENT_DECRAFT_BOOK);
|
||||
l->addAllowed(CONTENT_DIARY_BOOK);
|
||||
l->addAllowed(CONTENT_CRAFT_BOOK);
|
||||
l->addAllowed(CONTENT_RCRAFT_BOOK);
|
||||
}
|
||||
BookShelfNodeMetadata::~BookShelfNodeMetadata()
|
||||
{
|
||||
delete m_inventory;
|
||||
}
|
||||
u16 BookShelfNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_BOOKSHELF;
|
||||
}
|
||||
NodeMetadata* BookShelfNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
BookShelfNodeMetadata *d = new BookShelfNodeMetadata();
|
||||
d->m_inventory->deSerialize(is);
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* BookShelfNodeMetadata::clone()
|
||||
{
|
||||
BookShelfNodeMetadata *d = new BookShelfNodeMetadata();
|
||||
*d->m_inventory = *m_inventory;
|
||||
return d;
|
||||
}
|
||||
void BookShelfNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
m_inventory->serialize(os);
|
||||
}
|
||||
bool BookShelfNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
/*
|
||||
Disable removal if chest contains something
|
||||
*/
|
||||
InventoryList *list = m_inventory->getList("0");
|
||||
if(list == NULL)
|
||||
return false;
|
||||
if(list->getUsedSlots() == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
std::string BookShelfNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
return
|
||||
"size[8,7]"
|
||||
"list[current_name;0;0.5,0;7,2;]"
|
||||
"list[current_player;main;0,3;8,4;]";
|
||||
}
|
||||
std::vector<NodeBox> BookShelfNodeMetadata::getNodeBoxes(MapNode &n)
|
||||
{
|
||||
std::vector<NodeBox> boxes;
|
||||
boxes.clear();
|
||||
|
||||
InventoryList *list = m_inventory->getList("0");
|
||||
if(list == NULL)
|
||||
return boxes;
|
||||
if(list->getUsedSlots() == 0)
|
||||
return boxes;
|
||||
|
||||
f32 x = 0;
|
||||
f32 y = 0;
|
||||
f32 h = 0;
|
||||
|
||||
for (s16 i=0; i<14; i++) {
|
||||
if (list->getItem(i) == NULL)
|
||||
continue;
|
||||
x = (i%7)*0.125;
|
||||
y = (i/7)*-0.5;
|
||||
h = ((i%7)%2)*0.0625;
|
||||
|
||||
boxes.push_back(NodeBox(
|
||||
(-0.4375+x)*BS,(0.0625+y)*BS,-0.4375*BS,(-0.3125+x)*BS,(0.375+y+h)*BS,-0.0625*BS
|
||||
));
|
||||
boxes.push_back(NodeBox(
|
||||
(0.3125-x)*BS,(0.0625+y)*BS,0.0625*BS,(0.4375-x)*BS,(0.375+y+h)*BS,0.4375*BS
|
||||
));
|
||||
}
|
||||
|
||||
return transformNodeBox(n,boxes);
|
||||
}
|
||||
|
||||
/*
|
||||
ClockNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
ClockNodeMetadata proto_ClockNodeMetadata;
|
||||
|
||||
ClockNodeMetadata::ClockNodeMetadata():
|
||||
m_time(0)
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
}
|
||||
u16 ClockNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_CLOCK;
|
||||
}
|
||||
NodeMetadata* ClockNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
ClockNodeMetadata *d = new ClockNodeMetadata();
|
||||
int temp;
|
||||
is>>temp;
|
||||
d->m_time = temp;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* ClockNodeMetadata::clone()
|
||||
{
|
||||
ClockNodeMetadata *d = new ClockNodeMetadata();
|
||||
d->m_time = m_time;
|
||||
return d;
|
||||
}
|
||||
void ClockNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<itos(m_time) << " ";
|
||||
}
|
||||
std::vector<NodeBox> ClockNodeMetadata::getNodeBoxes(MapNode &n) {
|
||||
std::vector<NodeBox> boxes;
|
||||
boxes.clear();
|
||||
|
||||
u16 h = m_time/100;
|
||||
u16 m = (u16)((float)(m_time%100)/1.6667);
|
||||
|
||||
u16 v[4];
|
||||
v[0] = h/10;
|
||||
v[1] = h%10;
|
||||
v[2] = m/10;
|
||||
v[3] = m%10;
|
||||
|
||||
f32 x[4] = {-0.125,0.0625,0.3125,0.5};
|
||||
|
||||
u8 b[10] = {0xFC,0x0C,0xB6,0x9E,0x4E,0xDA,0xFA,0x8C,0xFE,0xDE};
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
if ((b[v[i]]&0x80))
|
||||
boxes.push_back(NodeBox((-0.25+x[i])*BS,0.0625*BS,-0.125*BS,(-0.0625+x[i])*BS,0.125*BS,-0.0625*BS));
|
||||
if ((b[v[i]]&0x04))
|
||||
boxes.push_back(NodeBox((-0.125+x[i])*BS,-0.0625*BS,-0.125*BS,(-0.0625+x[i])*BS,0.0625*BS,-0.0625*BS));
|
||||
if ((b[v[i]]&0x08))
|
||||
boxes.push_back(NodeBox((-0.125+x[i])*BS,-0.25*BS,-0.125*BS,(-0.0625+x[i])*BS,-0.125*BS,-0.0625*BS));
|
||||
if ((b[v[i]]&0x10))
|
||||
boxes.push_back(NodeBox((-0.25+x[i])*BS,-0.3125*BS,-0.125*BS,(-0.0625+x[i])*BS,-0.25*BS,-0.0625*BS));
|
||||
if ((b[v[i]]&0x20))
|
||||
boxes.push_back(NodeBox((-0.25+x[i])*BS,-0.25*BS,-0.125*BS,(-0.1875+x[i])*BS,-0.125*BS,-0.0625*BS));
|
||||
if ((b[v[i]]&0x40))
|
||||
boxes.push_back(NodeBox((-0.25+x[i])*BS,-0.0625*BS,-0.125*BS,(-0.1875+x[i])*BS,0.0625*BS,-0.0625*BS));
|
||||
if ((b[v[i]]&0x02))
|
||||
boxes.push_back(NodeBox((-0.1875+x[i])*BS,-0.125*BS,-0.125*BS,(-0.125+x[i])*BS,-0.0625*BS,-0.0625*BS));
|
||||
}
|
||||
|
||||
return transformNodeBox(n,boxes);
|
||||
}
|
||||
bool ClockNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||
{
|
||||
u32 t = env->getTimeOfDay();
|
||||
t /= 10;
|
||||
if (t == m_time)
|
||||
return false;
|
||||
m_time = t;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
CauldronNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
CauldronNodeMetadata proto_CauldronNodeMetadata;
|
||||
|
||||
CauldronNodeMetadata::CauldronNodeMetadata():
|
||||
m_water_level(0),
|
||||
m_water_heated(false),
|
||||
m_water_hot(false),
|
||||
m_fuel_time(0.0),
|
||||
m_src_time(0.0),
|
||||
m_cool_time(0.0)
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("fuel", 1);
|
||||
}
|
||||
CauldronNodeMetadata::~CauldronNodeMetadata()
|
||||
{
|
||||
delete m_inventory;
|
||||
}
|
||||
u16 CauldronNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_CAULDRON;
|
||||
}
|
||||
NodeMetadata* CauldronNodeMetadata::clone()
|
||||
{
|
||||
CauldronNodeMetadata *d = new CauldronNodeMetadata();
|
||||
d->m_fuel_time = m_fuel_time;
|
||||
d->m_src_time = m_src_time;
|
||||
d->m_water_level = m_water_level;
|
||||
d->m_water_heated = m_water_heated;
|
||||
d->m_water_hot = m_water_hot;
|
||||
*d->m_inventory = *m_inventory;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* CauldronNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
CauldronNodeMetadata *d = new CauldronNodeMetadata();
|
||||
|
||||
d->m_inventory->deSerialize(is);
|
||||
int temp;
|
||||
is>>temp;
|
||||
d->m_fuel_time = (float)temp/10;
|
||||
is>>temp;
|
||||
d->m_src_time = (float)temp/10;
|
||||
is>>temp;
|
||||
d->m_cool_time = (float)temp/10;
|
||||
is>>temp;
|
||||
d->m_water_level = temp;
|
||||
is>>temp;
|
||||
d->m_water_heated = !!temp;
|
||||
is>>temp;
|
||||
d->m_water_hot = !!temp;
|
||||
|
||||
return d;
|
||||
}
|
||||
void CauldronNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
m_inventory->serialize(os);
|
||||
os<<itos(m_fuel_time*10)<<" ";
|
||||
os<<itos(m_src_time*10)<<" ";
|
||||
os<<itos(m_cool_time*10)<<" ";
|
||||
os<<itos(m_water_level)<<" ";
|
||||
os<<itos(m_water_heated ? 1 : 0)<<" ";
|
||||
os<<itos(m_water_hot ? 1 : 0)<<" ";
|
||||
}
|
||||
std::wstring CauldronNodeMetadata::infoText()
|
||||
{
|
||||
if (m_fuel_time)
|
||||
return narrow_to_wide(gettext("Cauldron is active"));
|
||||
if (m_water_level) {
|
||||
if (m_water_hot)
|
||||
return narrow_to_wide(gettext("Cauldron is hot"));
|
||||
if (m_water_heated)
|
||||
return narrow_to_wide(gettext("Cauldron is cool"));
|
||||
}else{
|
||||
return narrow_to_wide(gettext("Cauldron is empty"));
|
||||
}
|
||||
InventoryList *list = m_inventory->getList("fuel");
|
||||
if (list && list->getUsedSlots() > 0)
|
||||
return narrow_to_wide(gettext("Cauldron is inactive"));
|
||||
return narrow_to_wide(gettext("Cauldron is out of fuel"));
|
||||
}
|
||||
bool CauldronNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
/*
|
||||
Disable removal if not empty
|
||||
*/
|
||||
InventoryList *list = m_inventory->getList("fuel");
|
||||
|
||||
if (list && list->getUsedSlots() > 0)
|
||||
return true;
|
||||
if (m_water_level)
|
||||
return true;
|
||||
return false;
|
||||
|
||||
}
|
||||
void CauldronNodeMetadata::inventoryModified()
|
||||
{
|
||||
vlprintf(CN_INFO,"Cauldron inventory modification callback");
|
||||
}
|
||||
bool CauldronNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||
{
|
||||
if (m_fuel_time > 0.0) {
|
||||
if (!m_water_heated)
|
||||
m_src_time += dtime;
|
||||
m_fuel_time -= dtime;
|
||||
}
|
||||
|
||||
InventoryList *list = m_inventory->getList("fuel");
|
||||
bool should_heat = false;
|
||||
|
||||
if (m_water_level) {
|
||||
if (m_water_hot) {
|
||||
m_cool_time -= dtime;
|
||||
if (m_cool_time < 20.0)
|
||||
m_water_hot = false;
|
||||
}else if (!m_water_heated) {
|
||||
m_cool_time = 120.0;
|
||||
if (m_src_time < 2.0) {
|
||||
should_heat = true;
|
||||
}else{
|
||||
m_water_hot = true;
|
||||
m_water_heated = true;
|
||||
m_src_time = 0.0;
|
||||
}
|
||||
}else if (list && list->getUsedSlots() > 0) {
|
||||
m_cool_time -= dtime;
|
||||
if (m_cool_time < 0.0)
|
||||
m_water_heated = false;
|
||||
}
|
||||
}else{
|
||||
m_water_hot = false;
|
||||
m_water_heated = false;
|
||||
}
|
||||
|
||||
if (should_heat && m_fuel_time <= 0.0) {
|
||||
InventoryList *list = m_inventory->getList("fuel");
|
||||
InventoryItem *fitem;
|
||||
if (list && list->getUsedSlots() > 0 && (fitem = list->getItem(0)) != NULL && fitem->isFuel()) {
|
||||
if ((fitem->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
|
||||
m_fuel_time = ((CraftItem*)fitem)->getFuelTime();
|
||||
}else if ((fitem->getContent()&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
|
||||
m_fuel_time = ((ToolItem*)fitem)->getFuelTime();
|
||||
}else{
|
||||
m_fuel_time = ((MaterialItem*)fitem)->getFuelTime();
|
||||
}
|
||||
content_t c = fitem->getContent();
|
||||
list->decrementMaterials(1);
|
||||
if (c == CONTENT_TOOLITEM_STEELBUCKET_LAVA)
|
||||
list->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0,0));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
std::string CauldronNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
std::string spec("size[8,7]");
|
||||
|
||||
spec += "label[1,0.5;";
|
||||
spec += gettext("Add fuel, then punch to add or remove water");;
|
||||
spec += "]";
|
||||
spec += "label[3.5,1.5;";
|
||||
spec += gettext("Fuel");;
|
||||
spec += "]";
|
||||
spec += "list[current_name;fuel;4,1;1,1;]";
|
||||
spec += "list[current_player;main;0,3;8,4;]";
|
||||
|
||||
return spec;
|
||||
}
|
||||
std::vector<NodeBox> CauldronNodeMetadata::getNodeBoxes(MapNode &n) {
|
||||
std::vector<NodeBox> boxes;
|
||||
boxes.clear();
|
||||
|
||||
if (m_fuel_time)
|
||||
boxes.push_back(NodeBox(-0.125*BS,-0.5*BS,-0.125*BS,0.125*BS,-0.25*BS,0.125*BS));
|
||||
|
||||
if (m_water_level) {
|
||||
switch (m_water_level) {
|
||||
case 1:
|
||||
boxes.push_back(NodeBox(-0.375*BS,-0.0625*BS,-0.375*BS,0.375*BS,0.0625*BS,0.375*BS));
|
||||
break;
|
||||
case 2:
|
||||
boxes.push_back(NodeBox(-0.375*BS,-0.0625*BS,-0.375*BS,0.375*BS,0.1875*BS,0.375*BS));
|
||||
break;
|
||||
case 3:
|
||||
boxes.push_back(NodeBox(-0.375*BS,-0.0625*BS,-0.375*BS,0.375*BS,0.3125*BS,0.375*BS));
|
||||
break;
|
||||
default:
|
||||
boxes.push_back(NodeBox(-0.375*BS,-0.0625*BS,-0.375*BS,0.375*BS,0.4375*BS,0.375*BS));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return transformNodeBox(n,boxes);
|
||||
}
|
||||
|
||||
/*
|
||||
BushNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
BushNodeMetadata proto_BushNodeMetadata;
|
||||
|
||||
BushNodeMetadata::BushNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("main", 1);
|
||||
|
||||
m_days_since_growth = 0;
|
||||
}
|
||||
BushNodeMetadata::~BushNodeMetadata()
|
||||
{
|
||||
}
|
||||
u16 BushNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_BUSH_RASPBERRY;
|
||||
}
|
||||
NodeMetadata* BushNodeMetadata::clone()
|
||||
{
|
||||
BushNodeMetadata *d = new BushNodeMetadata();
|
||||
*d->m_inventory = *m_inventory;
|
||||
d->m_days_since_growth = m_days_since_growth;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* BushNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
BushNodeMetadata *d = new BushNodeMetadata();
|
||||
|
||||
d->m_inventory->deSerialize(is);
|
||||
|
||||
return d;
|
||||
}
|
||||
void BushNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
m_inventory->serialize(os);
|
||||
}
|
||||
void BushNodeMetadata::inventoryModified()
|
||||
{
|
||||
vlprintf(CN_INFO,"Bush inventory modification callback");
|
||||
}
|
||||
bool BushNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||
{
|
||||
if (berryCount() > 8)
|
||||
return false;
|
||||
if (env->getSeason() != ENV_SEASON_SPRING)
|
||||
return false;
|
||||
u32 day = env->getTime();
|
||||
if (day-m_days_since_growth < 10) {
|
||||
return true;
|
||||
}
|
||||
|
||||
InventoryList *list = m_inventory->getList("main");
|
||||
if (!list)
|
||||
return true;
|
||||
|
||||
InventoryItem *item;
|
||||
|
||||
MapNode n = env->getMap().getNodeNoEx(pos);
|
||||
content_t berry = content_features(n.getContent()).special_alternate_node;
|
||||
if (berry == CONTENT_IGNORE)
|
||||
return false;
|
||||
|
||||
item = new CraftItem(berry,2,0);
|
||||
|
||||
item = list->addItem(item);
|
||||
if (item)
|
||||
delete item;
|
||||
|
||||
m_days_since_growth = day;
|
||||
|
||||
return true;
|
||||
}
|
||||
u16 BushNodeMetadata::berryCount()
|
||||
{
|
||||
InventoryList *list = m_inventory->getList("main");
|
||||
if (!list)
|
||||
return 0;
|
||||
|
||||
InventoryItem *item = list->getItem(0);
|
||||
if (!item)
|
||||
return 0;
|
||||
|
||||
return item->getCount();
|
||||
}
|
|
@ -0,0 +1,322 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_nodemeta.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2017 <lisa@ltmnet.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 3 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, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "content_mapnode.h"
|
||||
#include "player.h"
|
||||
|
||||
/*
|
||||
BookNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
BookNodeMetadata proto_BookNodeMetadata;
|
||||
|
||||
BookNodeMetadata::BookNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_title = "Book";
|
||||
m_content = "";
|
||||
}
|
||||
|
||||
u16 BookNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_BOOK_OPEN;
|
||||
}
|
||||
NodeMetadata* BookNodeMetadata::clone()
|
||||
{
|
||||
BookNodeMetadata *d = new BookNodeMetadata();
|
||||
d->m_title = m_title;
|
||||
d->m_content = m_content;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* BookNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
BookNodeMetadata *d = new BookNodeMetadata();
|
||||
d->m_title = deSerializeString(is);
|
||||
d->m_content = deSerializeString(is);
|
||||
return d;
|
||||
}
|
||||
void BookNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<serializeString(m_title);
|
||||
os<<serializeString(m_content);
|
||||
}
|
||||
bool BookNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
if (m_content != "")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
bool BookNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
if (meta->typeId() != CONTENT_BOOK)
|
||||
return false;
|
||||
|
||||
ClosedBookNodeMetadata *m = (ClosedBookNodeMetadata*)meta;
|
||||
m_title = wide_to_narrow(m->infoText());
|
||||
m_content = m->getContent();
|
||||
return true;
|
||||
}
|
||||
bool BookNodeMetadata::receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player)
|
||||
{
|
||||
m_title = fields["title"];
|
||||
m_content = fields["content"];
|
||||
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = m_content.find("]",pos)) != std::string::npos) {
|
||||
m_content.replace(pos,1,")");
|
||||
pos++;
|
||||
}
|
||||
pos = 0;
|
||||
while ((pos = m_content.find("[",pos)) != std::string::npos) {
|
||||
m_content.replace(pos,1,"(");
|
||||
pos++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string BookNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
std::string spec("size[6,6]");
|
||||
spec += "field[1,1;5,1;title;";
|
||||
spec += gettext("Title");;
|
||||
spec += ";";
|
||||
spec += m_title;
|
||||
spec += "]";
|
||||
spec += "field[1,2;5,2;content;";
|
||||
spec += gettext("Content");;
|
||||
spec += ";";
|
||||
spec += m_content;
|
||||
spec += "]";
|
||||
spec += "button_exit[2,5;3,1;submit;";
|
||||
spec += gettext("Save");;
|
||||
spec += "]";
|
||||
return spec;
|
||||
}
|
||||
|
||||
/*
|
||||
DiaryNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
DiaryNodeMetadata proto_DiaryNodeMetadata;
|
||||
|
||||
DiaryNodeMetadata::DiaryNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_title = gettext("Diary");
|
||||
m_content = "";
|
||||
}
|
||||
|
||||
u16 DiaryNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_DIARY_BOOK_OPEN;
|
||||
}
|
||||
NodeMetadata* DiaryNodeMetadata::clone()
|
||||
{
|
||||
DiaryNodeMetadata *d = new DiaryNodeMetadata();
|
||||
d->m_owner = m_owner;
|
||||
d->m_title = m_title;
|
||||
d->m_content = m_content;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* DiaryNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
DiaryNodeMetadata *d = new DiaryNodeMetadata();
|
||||
d->m_owner = deSerializeString(is);
|
||||
d->m_title = deSerializeString(is);
|
||||
d->m_content = deSerializeString(is);
|
||||
return d;
|
||||
}
|
||||
void DiaryNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<serializeString(m_owner);
|
||||
os<<serializeString(m_title);
|
||||
os<<serializeString(m_content);
|
||||
}
|
||||
bool DiaryNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
if (m_content != "")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
bool DiaryNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
if (meta->typeId() != CONTENT_BOOK)
|
||||
return false;
|
||||
|
||||
ClosedBookNodeMetadata *m = (ClosedBookNodeMetadata*)meta;
|
||||
m_owner = m->getOwner();
|
||||
m_title = wide_to_narrow(m->infoText());
|
||||
m_content = m->getContent();
|
||||
return true;
|
||||
}
|
||||
bool DiaryNodeMetadata::receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player)
|
||||
{
|
||||
if (m_owner == "")
|
||||
m_owner = player->getName();
|
||||
if (player->getName() != m_owner)
|
||||
return false;
|
||||
m_title = fields["title"];
|
||||
m_content = fields["content"];
|
||||
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = m_content.find("]",pos)) != std::string::npos) {
|
||||
m_content.replace(pos,1,")");
|
||||
pos++;
|
||||
}
|
||||
pos = 0;
|
||||
while ((pos = m_content.find("[",pos)) != std::string::npos) {
|
||||
m_content.replace(pos,1,"(");
|
||||
pos++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string DiaryNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
std::string spec("size[6,6]");
|
||||
spec += "field[1,1;5,1;title;";
|
||||
spec += gettext("Title");;
|
||||
spec += ";";
|
||||
spec += m_title;
|
||||
spec += "]";
|
||||
spec += "field[1,2;5,2;content;";
|
||||
spec += gettext("Content");;
|
||||
spec += ";";
|
||||
spec += m_content;
|
||||
spec += "]";
|
||||
spec += "button_exit[2,5;3,1;submit;";
|
||||
spec += gettext("Save");;
|
||||
spec += "]";
|
||||
return spec;
|
||||
}
|
||||
|
||||
/*
|
||||
ClosedBookNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
ClosedBookNodeMetadata proto_ClosedBookNodeMetadata;
|
||||
|
||||
ClosedBookNodeMetadata::ClosedBookNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_page = 0;
|
||||
m_owner = "";
|
||||
m_title = "";
|
||||
m_content = "";
|
||||
}
|
||||
u16 ClosedBookNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_BOOK;
|
||||
}
|
||||
NodeMetadata* ClosedBookNodeMetadata::clone()
|
||||
{
|
||||
ClosedBookNodeMetadata *d = new ClosedBookNodeMetadata();
|
||||
d->m_page = m_page;
|
||||
d->m_owner = m_owner;
|
||||
d->m_title = m_title;
|
||||
d->m_content = m_content;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* ClosedBookNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
ClosedBookNodeMetadata *d = new ClosedBookNodeMetadata();
|
||||
|
||||
d->m_owner = deSerializeString(is);
|
||||
d->m_title = deSerializeString(is);
|
||||
d->m_content = deSerializeString(is);
|
||||
is>>d->m_page;
|
||||
|
||||
return d;
|
||||
}
|
||||
void ClosedBookNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<serializeString(m_owner);
|
||||
os<<serializeString(m_title);
|
||||
os<<serializeString(m_content);
|
||||
os<<itos(m_page) << " ";
|
||||
}
|
||||
std::string ClosedBookNodeMetadata::getText()
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
std::wstring ClosedBookNodeMetadata::infoText()
|
||||
{
|
||||
return narrow_to_wide(m_title.c_str());
|
||||
}
|
||||
bool ClosedBookNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool ClosedBookNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
switch (meta->typeId()) {
|
||||
case CONTENT_CRAFT_BOOK_OPEN:
|
||||
{
|
||||
CraftGuideNodeMetadata *cm = (CraftGuideNodeMetadata*)meta;
|
||||
m_page = cm->getPage();
|
||||
m_title = wide_to_narrow(cm->infoText());
|
||||
break;
|
||||
}
|
||||
case CONTENT_RCRAFT_BOOK_OPEN:
|
||||
{
|
||||
ReverseCraftGuideNodeMetadata *cm = (ReverseCraftGuideNodeMetadata*)meta;
|
||||
m_page = cm->getPage();
|
||||
m_title = wide_to_narrow(cm->infoText());
|
||||
break;
|
||||
}
|
||||
case CONTENT_DECRAFT_BOOK_OPEN:
|
||||
{
|
||||
DeCraftNodeMetadata *cm = (DeCraftNodeMetadata*)meta;
|
||||
m_page = cm->getPage();
|
||||
m_title = wide_to_narrow(cm->infoText());
|
||||
break;
|
||||
}
|
||||
case CONTENT_BOOK_OPEN:
|
||||
{
|
||||
BookNodeMetadata *bm = (BookNodeMetadata*)meta;
|
||||
m_title = wide_to_narrow(bm->infoText());
|
||||
m_content = bm->getContent();
|
||||
break;
|
||||
}
|
||||
case CONTENT_DIARY_BOOK_OPEN:
|
||||
{
|
||||
DiaryNodeMetadata *dm = (DiaryNodeMetadata*)meta;
|
||||
m_owner = dm->getOwner();
|
||||
m_title = wide_to_narrow(dm->infoText());
|
||||
m_content = dm->getContent();
|
||||
break;
|
||||
}
|
||||
default:;
|
||||
}
|
||||
return false;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,69 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_nodemeta.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2017 <lisa@ltmnet.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 3 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, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "inventory.h"
|
||||
#include "content_mapnode.h"
|
||||
|
||||
/*
|
||||
BorderStoneNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
BorderStoneNodeMetadata proto_BorderStoneNodeMetadata;
|
||||
|
||||
BorderStoneNodeMetadata::BorderStoneNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
}
|
||||
BorderStoneNodeMetadata::~BorderStoneNodeMetadata()
|
||||
{
|
||||
}
|
||||
u16 BorderStoneNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_BORDERSTONE;
|
||||
}
|
||||
NodeMetadata* BorderStoneNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
BorderStoneNodeMetadata *d = new BorderStoneNodeMetadata();
|
||||
d->setOwner(deSerializeString(is));
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* BorderStoneNodeMetadata::clone()
|
||||
{
|
||||
BorderStoneNodeMetadata *d = new BorderStoneNodeMetadata();
|
||||
return d;
|
||||
}
|
||||
void BorderStoneNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<serializeString(m_text);
|
||||
}
|
||||
std::wstring BorderStoneNodeMetadata::infoText()
|
||||
{
|
||||
char buff[256];
|
||||
snprintf(buff, 256, gettext("Border Stone owned by '%s'"), m_text.c_str());
|
||||
return narrow_to_wide(buff);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,823 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_nodemeta.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2017 <lisa@ltmnet.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 3 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, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "inventory.h"
|
||||
#include "content_mapnode.h"
|
||||
#include "environment.h"
|
||||
|
||||
/*
|
||||
FurnaceNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
FurnaceNodeMetadata proto_FurnaceNodeMetadata;
|
||||
|
||||
FurnaceNodeMetadata::FurnaceNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("fuel", 1);
|
||||
m_inventory->addList("src", 1);
|
||||
m_inventory->addList("dst", 4);
|
||||
|
||||
m_step_accumulator = 0;
|
||||
m_fuel_totaltime = 0;
|
||||
m_fuel_time = 0;
|
||||
m_src_totaltime = 0;
|
||||
m_src_time = 0;
|
||||
}
|
||||
FurnaceNodeMetadata::~FurnaceNodeMetadata()
|
||||
{
|
||||
delete m_inventory;
|
||||
}
|
||||
u16 FurnaceNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_FURNACE;
|
||||
}
|
||||
NodeMetadata* FurnaceNodeMetadata::clone()
|
||||
{
|
||||
FurnaceNodeMetadata *d = new FurnaceNodeMetadata();
|
||||
*d->m_inventory = *m_inventory;
|
||||
d->m_fuel_totaltime = m_fuel_totaltime;
|
||||
d->m_fuel_time = m_fuel_time;
|
||||
d->m_src_totaltime = m_src_totaltime;
|
||||
d->m_src_time = m_src_time;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* FurnaceNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
FurnaceNodeMetadata *d = new FurnaceNodeMetadata();
|
||||
|
||||
d->m_inventory->deSerialize(is);
|
||||
|
||||
int temp;
|
||||
is>>temp;
|
||||
d->m_fuel_totaltime = (float)temp/10;
|
||||
is>>temp;
|
||||
d->m_fuel_time = (float)temp/10;
|
||||
|
||||
return d;
|
||||
}
|
||||
void FurnaceNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
m_inventory->serialize(os);
|
||||
os<<itos(m_fuel_totaltime*10)<<" ";
|
||||
os<<itos(m_fuel_time*10)<<" ";
|
||||
}
|
||||
std::wstring FurnaceNodeMetadata::infoText()
|
||||
{
|
||||
//return "Furnace";
|
||||
if (m_fuel_time >= m_fuel_totaltime) {
|
||||
const InventoryList *src_list = m_inventory->getList("src");
|
||||
assert(src_list);
|
||||
const InventoryItem *src_item = src_list->getItem(0);
|
||||
|
||||
if (src_item && src_item->isCookable(COOK_FURNACE)) {
|
||||
InventoryList *dst_list = m_inventory->getList("dst");
|
||||
if(!dst_list->roomForCookedItem(src_item))
|
||||
return narrow_to_wide(gettext("Furnace is overloaded"));
|
||||
return narrow_to_wide(gettext("Furnace is out of fuel"));
|
||||
}else{
|
||||
return narrow_to_wide(gettext("Furnace is inactive"));
|
||||
}
|
||||
}else{
|
||||
std::wstring s = narrow_to_wide(gettext("Furnace is active"));
|
||||
// Do this so it doesn't always show (0%) for weak fuel
|
||||
if (m_fuel_totaltime > 3) {
|
||||
s += L" (";
|
||||
s += itows(m_fuel_time/m_fuel_totaltime*100);
|
||||
s += L"%)";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
bool FurnaceNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
/*
|
||||
Disable removal if furnace is not empty
|
||||
*/
|
||||
InventoryList *list[3] = {m_inventory->getList("src"),
|
||||
m_inventory->getList("dst"), m_inventory->getList("fuel")};
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (list[i] == NULL)
|
||||
continue;
|
||||
if (list[i]->getUsedSlots() == 0)
|
||||
continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
void FurnaceNodeMetadata::inventoryModified()
|
||||
{
|
||||
vlprintf(CN_INFO,"Furnace inventory modification callback");
|
||||
}
|
||||
bool FurnaceNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||
{
|
||||
{
|
||||
MapNode n = env->getMap().getNodeNoEx(pos).getContent();
|
||||
if (n.getContent() == CONTENT_FURNACE_ACTIVE) {
|
||||
n.param1 = n.param2;
|
||||
n.setContent(CONTENT_FURNACE);
|
||||
env->setPostStepNodeSwap(pos,n);
|
||||
}
|
||||
}
|
||||
|
||||
if (dtime > 60.0)
|
||||
vlprintf(CN_INFO,"Furnace stepping a long time (%f)",dtime);
|
||||
// Update at a fixed frequency
|
||||
const float interval = 2.0;
|
||||
m_step_accumulator += dtime;
|
||||
bool changed = false;
|
||||
while (m_step_accumulator > interval) {
|
||||
m_step_accumulator -= interval;
|
||||
dtime = interval;
|
||||
|
||||
InventoryList *dst_list = m_inventory->getList("dst");
|
||||
assert(dst_list);
|
||||
|
||||
InventoryList *src_list = m_inventory->getList("src");
|
||||
assert(src_list);
|
||||
InventoryItem *src_item = src_list->getItem(0);
|
||||
|
||||
bool room_available = false;
|
||||
|
||||
if (src_item && src_item->isCookable(COOK_FURNACE))
|
||||
room_available = dst_list->roomForCookedItem(src_item);
|
||||
|
||||
// Start only if there are free slots in dst, so that it can
|
||||
// accomodate any result item
|
||||
if (room_available) {
|
||||
m_src_totaltime = 3;
|
||||
}else{
|
||||
m_src_time = 0;
|
||||
m_src_totaltime = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
If fuel is burning, increment the burn counters.
|
||||
If item finishes cooking, move it to result.
|
||||
*/
|
||||
if (m_fuel_time < m_fuel_totaltime) {
|
||||
m_fuel_time += dtime;
|
||||
m_src_time += dtime;
|
||||
if (m_src_time >= m_src_totaltime && m_src_totaltime > 0.001 && src_item) {
|
||||
InventoryItem *cookresult = src_item->createCookResult();
|
||||
dst_list->addItem(cookresult);
|
||||
src_list->decrementMaterials(1);
|
||||
m_src_time = 0;
|
||||
m_src_totaltime = 0;
|
||||
}
|
||||
changed = true;
|
||||
|
||||
// If the fuel was not used up this step, just keep burning it
|
||||
if (m_fuel_time < m_fuel_totaltime)
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
Get the source again in case it has all burned
|
||||
*/
|
||||
src_item = src_list->getItem(0);
|
||||
|
||||
/*
|
||||
If there is no source item, or the source item is not cookable,
|
||||
or the furnace is still cooking, or the furnace became overloaded, stop loop.
|
||||
*/
|
||||
if (
|
||||
src_item == NULL
|
||||
|| !room_available
|
||||
|| m_fuel_time < m_fuel_totaltime
|
||||
|| dst_list->roomForCookedItem(src_item) == false
|
||||
) {
|
||||
m_step_accumulator = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
//vlprintf(CN_INFO,"Furnace is out of fuel");
|
||||
|
||||
InventoryList *fuel_list = m_inventory->getList("fuel");
|
||||
assert(fuel_list);
|
||||
InventoryItem *fuel_item = fuel_list->getItem(0);
|
||||
if (fuel_item && fuel_item->isFuel()) {
|
||||
if ((fuel_item->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
|
||||
m_fuel_totaltime = ((CraftItem*)fuel_item)->getFuelTime();
|
||||
}else if ((fuel_item->getContent()&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
|
||||
m_fuel_totaltime = ((ToolItem*)fuel_item)->getFuelTime();
|
||||
}else{
|
||||
m_fuel_totaltime = ((MaterialItem*)fuel_item)->getFuelTime();
|
||||
}
|
||||
m_fuel_time = 0;
|
||||
content_t c = fuel_item->getContent();
|
||||
fuel_list->decrementMaterials(1);
|
||||
if (c == CONTENT_TOOLITEM_STEELBUCKET_LAVA) {
|
||||
fuel_list->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0,0));
|
||||
}
|
||||
changed = true;
|
||||
}else{
|
||||
m_step_accumulator = 0;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
std::string FurnaceNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
std::string spec("size[8,9]");
|
||||
spec += "list[current_name;fuel;2,3;1,1;]";
|
||||
spec += "ring[2,3;1;#FF0000;";
|
||||
float v = 0;
|
||||
if (m_fuel_totaltime > 0.0)
|
||||
v = 100.0-((100.0/m_fuel_totaltime)*m_fuel_time);
|
||||
spec += itos((int)v);
|
||||
spec += "]";
|
||||
spec += "list[current_name;src;2,1;1,1;]";
|
||||
spec += "list[current_name;dst;5,1;2,2;]";
|
||||
spec += "list[current_player;main;0,5;8,4;]";
|
||||
return spec;
|
||||
}
|
||||
std::vector<NodeBox> FurnaceNodeMetadata::getNodeBoxes(MapNode &n)
|
||||
{
|
||||
std::vector<NodeBox> boxes;
|
||||
boxes.clear();
|
||||
|
||||
if (m_fuel_time < m_fuel_totaltime) {
|
||||
boxes.push_back(NodeBox(
|
||||
-0.3125*BS,-0.25*BS,-0.4*BS,0.3125*BS,0.125*BS,-0.3*BS
|
||||
));
|
||||
}
|
||||
|
||||
return transformNodeBox(n,boxes);
|
||||
}
|
||||
bool FurnaceNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
if (meta->typeId() != CONTENT_LOCKABLE_FURNACE)
|
||||
return false;
|
||||
LockingFurnaceNodeMetadata *l = (LockingFurnaceNodeMetadata*)meta;
|
||||
*m_inventory = *l->getInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
LockingFurnaceNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
LockingFurnaceNodeMetadata proto_LockingFurnaceNodeMetadata;
|
||||
|
||||
LockingFurnaceNodeMetadata::LockingFurnaceNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("fuel", 1);
|
||||
m_inventory->addList("src", 1);
|
||||
m_inventory->addList("dst", 4);
|
||||
|
||||
m_step_accumulator = 0;
|
||||
m_fuel_totaltime = 0;
|
||||
m_fuel_time = 0;
|
||||
m_src_totaltime = 0;
|
||||
m_src_time = 0;
|
||||
m_lock = 0;
|
||||
}
|
||||
LockingFurnaceNodeMetadata::~LockingFurnaceNodeMetadata()
|
||||
{
|
||||
delete m_inventory;
|
||||
}
|
||||
u16 LockingFurnaceNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_LOCKABLE_FURNACE;
|
||||
}
|
||||
NodeMetadata* LockingFurnaceNodeMetadata::clone()
|
||||
{
|
||||
LockingFurnaceNodeMetadata *d = new LockingFurnaceNodeMetadata();
|
||||
*d->m_inventory = *m_inventory;
|
||||
d->m_fuel_totaltime = m_fuel_totaltime;
|
||||
d->m_fuel_time = m_fuel_time;
|
||||
d->m_src_totaltime = m_src_totaltime;
|
||||
d->m_src_time = m_src_time;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* LockingFurnaceNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
LockingFurnaceNodeMetadata *d = new LockingFurnaceNodeMetadata();
|
||||
|
||||
d->m_inventory->deSerialize(is);
|
||||
d->setOwner(deSerializeString(is));
|
||||
d->setInventoryOwner(deSerializeString(is));
|
||||
|
||||
int temp;
|
||||
is>>temp;
|
||||
d->m_fuel_totaltime = (float)temp/10;
|
||||
is>>temp;
|
||||
d->m_fuel_time = (float)temp/10;
|
||||
is>>temp;
|
||||
d->m_lock = (float)temp/10;
|
||||
|
||||
return d;
|
||||
}
|
||||
void LockingFurnaceNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
m_inventory->serialize(os);
|
||||
os<<serializeString(m_owner);
|
||||
os<<serializeString(m_inv_owner);
|
||||
os<<itos(m_fuel_totaltime*10)<<" ";
|
||||
os<<itos(m_fuel_time*10)<<" ";
|
||||
os<<itos(m_lock*10)<<" ";
|
||||
}
|
||||
std::wstring LockingFurnaceNodeMetadata::infoText()
|
||||
{
|
||||
char buff[256];
|
||||
char* s;
|
||||
char e[128];
|
||||
std::string ostr = m_owner;
|
||||
|
||||
e[0] = 0;
|
||||
|
||||
if (m_inv_owner != "")
|
||||
ostr += ","+m_inv_owner;
|
||||
|
||||
if (m_fuel_time >= m_fuel_totaltime) {
|
||||
const InventoryList *src_list = m_inventory->getList("src");
|
||||
assert(src_list);
|
||||
const InventoryItem *src_item = src_list->getItem(0);
|
||||
|
||||
if(src_item && src_item->isCookable(COOK_FURNACE)) {
|
||||
InventoryList *dst_list = m_inventory->getList("dst");
|
||||
if (!dst_list->roomForCookedItem(src_item)) {
|
||||
s = gettext("Locking Furnace is overloaded");
|
||||
}else{
|
||||
s = gettext("Locking Furnace is out of fuel");
|
||||
}
|
||||
}else{
|
||||
s = gettext("Locking Furnace is inactive");
|
||||
}
|
||||
}else{
|
||||
s = gettext("Locking Furnace is active");
|
||||
// Do this so it doesn't always show (0%) for weak fuel
|
||||
if (m_fuel_totaltime > 3) {
|
||||
uint32_t tt = m_fuel_time/m_fuel_totaltime*100;
|
||||
snprintf(e,128, " (%d%%)",tt);
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(buff,256,"%s (%s)%s",s,ostr.c_str(),e);
|
||||
return narrow_to_wide(buff);
|
||||
}
|
||||
bool LockingFurnaceNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
/*
|
||||
Disable removal if furnace is not empty
|
||||
*/
|
||||
InventoryList *list[3] = {m_inventory->getList("src"),
|
||||
m_inventory->getList("dst"), m_inventory->getList("fuel")};
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
if(list[i] == NULL)
|
||||
continue;
|
||||
if(list[i]->getUsedSlots() == 0)
|
||||
continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
void LockingFurnaceNodeMetadata::inventoryModified()
|
||||
{
|
||||
vlprintf(CN_INFO,"LockingFurnace inventory modification callback");
|
||||
}
|
||||
bool LockingFurnaceNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||
{
|
||||
{
|
||||
MapNode n = env->getMap().getNodeNoEx(pos);
|
||||
if (n.getContent() == CONTENT_LOCKABLE_FURNACE_ACTIVE) {
|
||||
n.param1 = n.param2;
|
||||
n.setContent(CONTENT_LOCKABLE_FURNACE);
|
||||
env->setPostStepNodeSwap(pos,n);
|
||||
}
|
||||
}
|
||||
if (dtime > 60.0)
|
||||
vlprintf(CN_INFO,"LockingFurnace stepping a long time (%f)",dtime);
|
||||
// Update at a fixed frequency
|
||||
const float interval = 2.0;
|
||||
m_step_accumulator += dtime;
|
||||
bool changed = false;
|
||||
while(m_step_accumulator > interval) {
|
||||
m_step_accumulator -= interval;
|
||||
dtime = interval;
|
||||
|
||||
//infostream<<"Furnace step dtime="<<dtime<<std::endl;
|
||||
|
||||
InventoryList *dst_list = m_inventory->getList("dst");
|
||||
assert(dst_list);
|
||||
|
||||
InventoryList *src_list = m_inventory->getList("src");
|
||||
assert(src_list);
|
||||
InventoryItem *src_item = src_list->getItem(0);
|
||||
|
||||
bool room_available = false;
|
||||
|
||||
if (src_item && src_item->isCookable(COOK_FURNACE)) {
|
||||
room_available = dst_list->roomForCookedItem(src_item);
|
||||
m_lock = 300.0;
|
||||
changed = true;
|
||||
}else if (m_lock < 0.0) {
|
||||
setInventoryOwner("");
|
||||
changed = true;
|
||||
}else{
|
||||
m_lock -= dtime;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
// Start only if there are free slots in dst, so that it can
|
||||
// accomodate any result item
|
||||
if (room_available) {
|
||||
m_src_totaltime = 3;
|
||||
}else{
|
||||
m_src_time = 0;
|
||||
m_src_totaltime = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
If fuel is burning, increment the burn counters.
|
||||
If item finishes cooking, move it to result.
|
||||
*/
|
||||
if (m_fuel_time < m_fuel_totaltime) {
|
||||
m_fuel_time += dtime;
|
||||
m_src_time += dtime;
|
||||
if (m_src_time >= m_src_totaltime && m_src_totaltime > 0.001 && src_item) {
|
||||
InventoryItem *cookresult = src_item->createCookResult();
|
||||
dst_list->addItem(cookresult);
|
||||
src_list->decrementMaterials(1);
|
||||
m_src_time = 0;
|
||||
m_src_totaltime = 0;
|
||||
}
|
||||
changed = true;
|
||||
|
||||
// If the fuel was not used up this step, just keep burning it
|
||||
if (m_fuel_time < m_fuel_totaltime)
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
Get the source again in case it has all burned
|
||||
*/
|
||||
src_item = src_list->getItem(0);
|
||||
|
||||
/*
|
||||
If there is no source item, or the source item is not cookable,
|
||||
or the furnace is still cooking, or the furnace became overloaded, stop loop.
|
||||
*/
|
||||
if (
|
||||
src_item == NULL
|
||||
|| !room_available ||
|
||||
m_fuel_time < m_fuel_totaltime
|
||||
|| dst_list->roomForCookedItem(src_item) == false
|
||||
) {
|
||||
m_step_accumulator = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
//vlprintf(CN_INFO,"Furnace is out of fuel");
|
||||
|
||||
InventoryList *fuel_list = m_inventory->getList("fuel");
|
||||
assert(fuel_list);
|
||||
InventoryItem *fuel_item = fuel_list->getItem(0);
|
||||
if (fuel_item && fuel_item->isFuel()) {
|
||||
if ((fuel_item->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
|
||||
m_fuel_totaltime = ((CraftItem*)fuel_item)->getFuelTime();
|
||||
}else if ((fuel_item->getContent()&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
|
||||
m_fuel_totaltime = ((ToolItem*)fuel_item)->getFuelTime();
|
||||
}else{
|
||||
m_fuel_totaltime = ((MaterialItem*)fuel_item)->getFuelTime();
|
||||
}
|
||||
m_fuel_time = 0;
|
||||
content_t c = fuel_item->getContent();
|
||||
fuel_list->decrementMaterials(1);
|
||||
if (c == CONTENT_TOOLITEM_STEELBUCKET_LAVA) {
|
||||
fuel_list->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0,0));
|
||||
}
|
||||
changed = true;
|
||||
}else{
|
||||
m_step_accumulator = 0;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
std::string LockingFurnaceNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
std::string spec("size[8,9]");
|
||||
spec += "list[current_name;fuel;2,3;1,1;]";
|
||||
spec += "ring[2,3;1;#FF0000;";
|
||||
float v = 0;
|
||||
if (m_fuel_totaltime > 0.0)
|
||||
v = 100.0-((100.0/m_fuel_totaltime)*m_fuel_time);
|
||||
spec += itos((int)v);
|
||||
spec += "]";
|
||||
spec += "list[current_name;src;2,1;1,1;]";
|
||||
spec += "list[current_name;dst;5,1;2,2;]";
|
||||
spec += "list[current_player;main;0,5;8,4;]";
|
||||
return spec;
|
||||
}
|
||||
std::vector<NodeBox> LockingFurnaceNodeMetadata::getNodeBoxes(MapNode &n)
|
||||
{
|
||||
std::vector<NodeBox> boxes;
|
||||
boxes.clear();
|
||||
|
||||
if (m_fuel_time < m_fuel_totaltime) {
|
||||
boxes.push_back(NodeBox(
|
||||
-0.3125*BS,-0.25*BS,-0.4*BS,0.3125*BS,0.125*BS,-0.3*BS
|
||||
));
|
||||
}
|
||||
|
||||
return transformNodeBox(n,boxes);
|
||||
}
|
||||
bool LockingFurnaceNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
if (meta->typeId() != CONTENT_FURNACE)
|
||||
return false;
|
||||
FurnaceNodeMetadata *l = (FurnaceNodeMetadata*)meta;
|
||||
*m_inventory = *l->getInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
CampFireNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
CampFireNodeMetadata proto_CampFireNodeMetadata;
|
||||
|
||||
CampFireNodeMetadata::CampFireNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("fuel", 1);
|
||||
m_inventory->addList("src", 1);
|
||||
m_inventory->addList("dst", 1);
|
||||
|
||||
m_step_accumulator = 0;
|
||||
m_fuel_totaltime = 0;
|
||||
m_fuel_time = 0;
|
||||
m_src_totaltime = 0;
|
||||
m_src_time = 0;
|
||||
}
|
||||
CampFireNodeMetadata::~CampFireNodeMetadata()
|
||||
{
|
||||
delete m_inventory;
|
||||
}
|
||||
u16 CampFireNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_CAMPFIRE;
|
||||
}
|
||||
NodeMetadata* CampFireNodeMetadata::clone()
|
||||
{
|
||||
CampFireNodeMetadata *d = new CampFireNodeMetadata();
|
||||
*d->m_inventory = *m_inventory;
|
||||
d->m_fuel_totaltime = m_fuel_totaltime;
|
||||
d->m_fuel_time = m_fuel_time;
|
||||
d->m_src_totaltime = m_src_totaltime;
|
||||
d->m_src_time = m_src_time;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* CampFireNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
CampFireNodeMetadata *d = new CampFireNodeMetadata();
|
||||
|
||||
d->m_inventory->deSerialize(is);
|
||||
|
||||
int temp;
|
||||
is>>temp;
|
||||
d->m_fuel_totaltime = (float)temp/10;
|
||||
is>>temp;
|
||||
d->m_fuel_time = (float)temp/10;
|
||||
|
||||
return d;
|
||||
}
|
||||
void CampFireNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
m_inventory->serialize(os);
|
||||
os<<itos(m_fuel_totaltime*10)<<" ";
|
||||
os<<itos(m_fuel_time*10)<<" ";
|
||||
}
|
||||
std::wstring CampFireNodeMetadata::infoText()
|
||||
{
|
||||
char buff[256];
|
||||
char* s;
|
||||
char e[128];
|
||||
e[0] = 0;
|
||||
|
||||
if (m_fuel_time >= m_fuel_totaltime) {
|
||||
const InventoryList *src_list = m_inventory->getList("src");
|
||||
assert(src_list);
|
||||
const InventoryItem *src_item = src_list->getItem(0);
|
||||
|
||||
if (src_item && src_item->isCookable(COOK_FIRE)) {
|
||||
InventoryList *dst_list = m_inventory->getList("dst");
|
||||
if(!dst_list->roomForCookedItem(src_item)) {
|
||||
s = gettext("CampFire is overloaded");
|
||||
}else{
|
||||
s = gettext("CampFire is out of fuel");
|
||||
}
|
||||
}else{
|
||||
s = gettext("CampFire is inactive");
|
||||
}
|
||||
}else{
|
||||
s = gettext("CampFire is active");
|
||||
// Do this so it doesn't always show (0%) for weak fuel
|
||||
if (m_fuel_totaltime > 3) {
|
||||
uint32_t tt = m_fuel_time/m_fuel_totaltime*100;
|
||||
snprintf(e,128, " (%d%%)",tt);
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(buff,256,"%s%s",s,e);
|
||||
return narrow_to_wide(buff);
|
||||
}
|
||||
bool CampFireNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
/*
|
||||
Disable removal if furnace is not empty
|
||||
*/
|
||||
InventoryList *list[3] = {m_inventory->getList("src"),
|
||||
m_inventory->getList("dst"), m_inventory->getList("fuel")};
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (list[i] == NULL)
|
||||
continue;
|
||||
if (list[i]->getUsedSlots() == 0)
|
||||
continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
void CampFireNodeMetadata::inventoryModified()
|
||||
{
|
||||
vlprintf(CN_INFO,"CampFire inventory modification callback");
|
||||
}
|
||||
bool CampFireNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||
{
|
||||
{
|
||||
MapNode n = env->getMap().getNodeNoEx(pos).getContent();
|
||||
if (n.getContent() == CONTENT_FURNACE_ACTIVE) {
|
||||
n.param1 = n.param2;
|
||||
n.setContent(CONTENT_FURNACE);
|
||||
env->setPostStepNodeSwap(pos,n);
|
||||
}
|
||||
}
|
||||
|
||||
if (dtime > 60.0)
|
||||
vlprintf(CN_INFO,"CampFire stepping a long time (%f)",dtime);
|
||||
// Update at a fixed frequency
|
||||
const float interval = 2.0;
|
||||
m_step_accumulator += dtime;
|
||||
bool changed = false;
|
||||
while (m_step_accumulator > interval) {
|
||||
m_step_accumulator -= interval;
|
||||
dtime = interval;
|
||||
|
||||
InventoryList *dst_list = m_inventory->getList("dst");
|
||||
assert(dst_list);
|
||||
|
||||
InventoryList *src_list = m_inventory->getList("src");
|
||||
assert(src_list);
|
||||
InventoryItem *src_item = src_list->getItem(0);
|
||||
|
||||
bool room_available = false;
|
||||
|
||||
if (src_item && src_item->isCookable(COOK_FIRE))
|
||||
room_available = dst_list->roomForCookedItem(src_item);
|
||||
|
||||
// Start only if there are free slots in dst, so that it can
|
||||
// accomodate any result item
|
||||
if (room_available) {
|
||||
m_src_totaltime = 3;
|
||||
}else{
|
||||
m_src_time = 0;
|
||||
m_src_totaltime = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
If fuel is burning, increment the burn counters.
|
||||
If item finishes cooking, move it to result.
|
||||
*/
|
||||
if (m_fuel_time < m_fuel_totaltime) {
|
||||
m_fuel_time += dtime;
|
||||
m_src_time += dtime;
|
||||
if (m_src_time >= m_src_totaltime && m_src_totaltime > 0.001 && src_item) {
|
||||
InventoryItem *cookresult = src_item->createCookResult();
|
||||
dst_list->addItem(cookresult);
|
||||
src_list->decrementMaterials(1);
|
||||
m_src_time = 0;
|
||||
m_src_totaltime = 0;
|
||||
}
|
||||
changed = true;
|
||||
|
||||
// If the fuel was not used up this step, just keep burning it
|
||||
if (m_fuel_time < m_fuel_totaltime)
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
Get the source again in case it has all burned
|
||||
*/
|
||||
src_item = src_list->getItem(0);
|
||||
|
||||
/*
|
||||
If there is no source item, or the source item is not cookable,
|
||||
or the furnace is still cooking, or the furnace became overloaded, stop loop.
|
||||
*/
|
||||
if (
|
||||
src_item == NULL
|
||||
|| !room_available
|
||||
|| m_fuel_time < m_fuel_totaltime
|
||||
|| dst_list->roomForCookedItem(src_item) == false
|
||||
) {
|
||||
m_step_accumulator = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
//vlprintf(CN_INFO,"CampFire is out of fuel");
|
||||
|
||||
InventoryList *fuel_list = m_inventory->getList("fuel");
|
||||
assert(fuel_list);
|
||||
InventoryItem *fuel_item = fuel_list->getItem(0);
|
||||
if (fuel_item && fuel_item->isFuel()) {
|
||||
if ((fuel_item->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
|
||||
m_fuel_totaltime = ((CraftItem*)fuel_item)->getFuelTime();
|
||||
}else if ((fuel_item->getContent()&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
|
||||
m_fuel_totaltime = ((ToolItem*)fuel_item)->getFuelTime();
|
||||
}else{
|
||||
m_fuel_totaltime = ((MaterialItem*)fuel_item)->getFuelTime();
|
||||
}
|
||||
m_fuel_totaltime *= 2.0;
|
||||
m_fuel_time = 0;
|
||||
content_t c = fuel_item->getContent();
|
||||
fuel_list->decrementMaterials(1);
|
||||
if (c == CONTENT_TOOLITEM_STEELBUCKET_LAVA) {
|
||||
fuel_list->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0,0));
|
||||
}
|
||||
changed = true;
|
||||
}else{
|
||||
m_step_accumulator = 0;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
std::string CampFireNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
std::string spec("size[8,9]");
|
||||
spec += "list[current_name;fuel;2,2;1,1;]";
|
||||
spec += "list[current_name;src;5,1;1,1;]";
|
||||
spec += "list[current_name;dst;5,3;1,1;]";
|
||||
spec += "list[current_player;main;0,5;8,4;]";
|
||||
return spec;
|
||||
}
|
||||
std::vector<NodeBox> CampFireNodeMetadata::getNodeBoxes(MapNode &n)
|
||||
{
|
||||
std::vector<NodeBox> boxes;
|
||||
boxes.clear();
|
||||
|
||||
if (m_fuel_time < m_fuel_totaltime) {
|
||||
boxes.push_back(NodeBox(
|
||||
-0.3125*BS,-0.25*BS,-0.4*BS,0.3125*BS,0.125*BS,-0.3*BS
|
||||
));
|
||||
}
|
||||
|
||||
return transformNodeBox(n,boxes);
|
||||
}
|
||||
|
||||
bool CampFireNodeMetadata::isActive()
|
||||
{
|
||||
if (m_fuel_time >= m_fuel_totaltime)
|
||||
return false;
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_nodemeta.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2014 <lisa@ltmnet.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 3 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, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "content_mapnode.h"
|
||||
|
||||
/*
|
||||
FlagNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
FlagNodeMetadata proto_FlagNodeMetadata();
|
||||
|
||||
FlagNodeMetadata::FlagNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
}
|
||||
u16 FlagNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_FLAG;
|
||||
}
|
||||
NodeMetadata* FlagNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
FlagNodeMetadata *d = new FlagNodeMetadata();
|
||||
d->setOwner(deSerializeString(is));
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* FlagNodeMetadata::clone()
|
||||
{
|
||||
FlagNodeMetadata *d = new FlagNodeMetadata();
|
||||
d->m_owner = m_owner;
|
||||
return d;
|
||||
}
|
||||
void FlagNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<serializeString(m_owner);
|
||||
}
|
||||
std::wstring FlagNodeMetadata::infoText()
|
||||
{
|
||||
char buff[256];
|
||||
snprintf(buff, 256, gettext("%s's Home Flag"), m_owner.c_str());
|
||||
return narrow_to_wide(buff);
|
||||
}
|
|
@ -0,0 +1,285 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_nodemeta.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2017 <lisa@ltmnet.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 3 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, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "inventory.h"
|
||||
#include "content_mapnode.h"
|
||||
#include "content_craft.h"
|
||||
#include "environment.h"
|
||||
#include "enchantment.h"
|
||||
|
||||
/*
|
||||
ForgeNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
ForgeNodeMetadata proto_ForgeNodeMetadata;
|
||||
|
||||
ForgeNodeMetadata::ForgeNodeMetadata():
|
||||
m_show_craft(false)
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("mithril", 9);
|
||||
m_inventory->addList("gem", 9);
|
||||
m_inventory->addList("craft", 9);
|
||||
m_inventory->addList("craftresult", 1);
|
||||
{
|
||||
InventoryList *l = m_inventory->getList("mithril");
|
||||
l->addAllowed(CONTENT_CRAFTITEM_MITHRIL_UNBOUND);
|
||||
}
|
||||
{
|
||||
InventoryList *l = m_inventory->getList("gem");
|
||||
l->addAllowed(CONTENT_CRAFTITEM_RUBY);
|
||||
l->addAllowed(CONTENT_CRAFTITEM_TURQUOISE);
|
||||
l->addAllowed(CONTENT_CRAFTITEM_AMETHYST);
|
||||
l->addAllowed(CONTENT_CRAFTITEM_SAPPHIRE);
|
||||
l->addAllowed(CONTENT_CRAFTITEM_SUNSTONE);
|
||||
}
|
||||
}
|
||||
ForgeNodeMetadata::~ForgeNodeMetadata()
|
||||
{
|
||||
}
|
||||
u16 ForgeNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_FORGE;
|
||||
}
|
||||
NodeMetadata* ForgeNodeMetadata::clone()
|
||||
{
|
||||
ForgeNodeMetadata *d = new ForgeNodeMetadata();
|
||||
d->m_show_craft = m_show_craft;
|
||||
*d->m_inventory = *m_inventory;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* ForgeNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
ForgeNodeMetadata *d = new ForgeNodeMetadata();
|
||||
|
||||
d->m_inventory->deSerialize(is);
|
||||
int c;
|
||||
is>>c;
|
||||
d->m_show_craft = !!c;
|
||||
|
||||
return d;
|
||||
}
|
||||
void ForgeNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
m_inventory->serialize(os);
|
||||
os<<itos(m_show_craft ? 1 : 0)<<" ";
|
||||
}
|
||||
std::wstring ForgeNodeMetadata::infoText()
|
||||
{
|
||||
return narrow_to_wide(gettext("Forge"));
|
||||
}
|
||||
void ForgeNodeMetadata::inventoryModified()
|
||||
{
|
||||
vlprintf(CN_INFO,"Forge inventory modification callback");
|
||||
}
|
||||
bool ForgeNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||
{
|
||||
v3s16 abv = pos+v3s16(0,1,0);
|
||||
MapNode n = env->getMap().getNodeNoEx(abv);
|
||||
if (n.getContent() == CONTENT_AIR) {
|
||||
bool show_flame = false;
|
||||
if (m_show_craft) {
|
||||
InventoryItem *items[9];
|
||||
bool has_enchanted = false;
|
||||
InventoryList *clist = m_inventory->getList("craft");
|
||||
InventoryList *rlist = m_inventory->getList("craftresult");
|
||||
if (!clist || !rlist)
|
||||
return false;
|
||||
|
||||
for (u16 i=0; i<9; i++) {
|
||||
items[i] = clist->getItem(i);
|
||||
if (
|
||||
!has_enchanted
|
||||
&& items[i]
|
||||
&& (items[i]->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK
|
||||
&& items[i]->getData() > 0
|
||||
)
|
||||
has_enchanted = true;
|
||||
}
|
||||
|
||||
if (!has_enchanted)
|
||||
return false;
|
||||
|
||||
// Get result of crafting grid
|
||||
/* TODO: player/server args */
|
||||
InventoryItem *result = crafting::getResult(items,NULL,NULL);
|
||||
if (!result)
|
||||
return false;
|
||||
if (rlist->itemFits(0,result))
|
||||
show_flame = true;
|
||||
delete result;
|
||||
}else{
|
||||
InventoryList *mlist = m_inventory->getList("mithril");
|
||||
InventoryList *glist = m_inventory->getList("gem");
|
||||
if (!mlist || !glist)
|
||||
return false;
|
||||
InventoryItem *mithril = mlist->getItem(0);
|
||||
InventoryItem *gem = glist->getItem(0);
|
||||
if (mithril && gem)
|
||||
show_flame = true;
|
||||
}
|
||||
if (show_flame) {
|
||||
n.setContent(CONTENT_FORGE_FIRE);
|
||||
env->getMap().addNodeWithEvent(abv,n);
|
||||
}
|
||||
}else if (n.getContent() == CONTENT_FORGE_FIRE) {
|
||||
env->getMap().removeNodeWithEvent(abv);
|
||||
if (m_show_craft) {
|
||||
InventoryItem *items[9];
|
||||
bool has_enchanted = false;
|
||||
InventoryList *clist = m_inventory->getList("craft");
|
||||
InventoryList *rlist = m_inventory->getList("craftresult");
|
||||
if (!clist || !rlist)
|
||||
return false;
|
||||
|
||||
for (u16 i=0; i<9; i++) {
|
||||
items[i] = clist->getItem(i);
|
||||
if (
|
||||
!has_enchanted
|
||||
&& items[i]
|
||||
&& (items[i]->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK
|
||||
&& items[i]->getData() > 0
|
||||
)
|
||||
has_enchanted = true;
|
||||
}
|
||||
|
||||
if (!has_enchanted)
|
||||
return false;
|
||||
|
||||
// Get result of crafting grid
|
||||
/* TODO: player/server args */
|
||||
InventoryItem *result = crafting::getResult(items,NULL,NULL);
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
{
|
||||
u16 data = 0;
|
||||
for (u16 i=0; i<9; i++) {
|
||||
if (
|
||||
items[i]
|
||||
&& (items[i]->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK
|
||||
&& items[i]->getData() > 0
|
||||
)
|
||||
enchantment_set(&data,items[i]->getData());
|
||||
}
|
||||
result->setData(data);
|
||||
}
|
||||
if (!rlist->itemFits(0,result)) {
|
||||
delete result;
|
||||
return false;
|
||||
}
|
||||
|
||||
rlist->addItem(result);
|
||||
clist->decrementMaterials(1);
|
||||
|
||||
return true;
|
||||
}else{
|
||||
InventoryList *mlist = m_inventory->getList("mithril");
|
||||
InventoryList *glist = m_inventory->getList("gem");
|
||||
InventoryList *result = m_inventory->getList("craftresult");
|
||||
if (!mlist || !glist || !result)
|
||||
return false;
|
||||
InventoryItem *mithril = mlist->getItem(0);
|
||||
InventoryItem *gem = glist->getItem(0);
|
||||
if (!mithril || !gem)
|
||||
return false;
|
||||
u16 data = 0;
|
||||
if (!enchantment_enchant(&data,gem->getContent()))
|
||||
return false;
|
||||
InventoryItem *newitem = new CraftItem(CONTENT_CRAFTITEM_MITHRIL,1,data);
|
||||
if (!newitem)
|
||||
return false;
|
||||
if (!result->itemFits(0,newitem)) {
|
||||
delete newitem;
|
||||
return false;
|
||||
}
|
||||
result->addItem(newitem);
|
||||
mlist->decrementMaterials(1);
|
||||
glist->decrementMaterials(1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool ForgeNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
/*
|
||||
Disable removal if not empty
|
||||
*/
|
||||
InventoryList *list = m_inventory->getList("craft");
|
||||
if (list && list->getUsedSlots() > 0)
|
||||
return true;
|
||||
|
||||
list = m_inventory->getList("mithril");
|
||||
if (list && list->getUsedSlots() > 0)
|
||||
return true;
|
||||
|
||||
list = m_inventory->getList("gem");
|
||||
if (list && list->getUsedSlots() > 0)
|
||||
return true;
|
||||
|
||||
list = m_inventory->getList("craftresult");
|
||||
if (list && list->getUsedSlots() > 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
bool ForgeNodeMetadata::receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player)
|
||||
{
|
||||
if (fields["craft"] != "") {
|
||||
m_show_craft = true;
|
||||
}else if (fields["enchant"] != "") {
|
||||
m_show_craft = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
std::string ForgeNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
std::string spec("size[8,8]");
|
||||
if (m_show_craft) {
|
||||
spec += "list[current_name;craft;2,0;3,3;]";
|
||||
spec += "list[current_name;craftresult;6,1;1,1;]";
|
||||
spec += "button[3,3.2;3,1;enchant;";
|
||||
spec += gettext("Show Enchanting");;
|
||||
spec += "]";
|
||||
}else{
|
||||
spec += "list[current_name;mithril;1,1;1,1;ingot_bg.png]";
|
||||
spec += "list[current_name;gem;3,1;1,1;gem_bg.png]";
|
||||
spec += "list[current_name;craftresult;6,1;1,1;]";
|
||||
spec += "button[3,3.2;3,1;craft;";
|
||||
spec += gettext("Show Crafting");;
|
||||
spec += "]";
|
||||
}
|
||||
|
||||
spec += "list[current_player;main;0,3.8;8,1;0,8;]";
|
||||
spec += "list[current_player;main;0,5;8,3;8,-1;]";
|
||||
|
||||
return spec;
|
||||
}
|
|
@ -0,0 +1,226 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_nodemeta.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2014 <lisa@ltmnet.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 3 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, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "inventory.h"
|
||||
#include "content_mapnode.h"
|
||||
#include "environment.h"
|
||||
|
||||
/*
|
||||
IncineratorNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
IncineratorNodeMetadata proto_IncineratorNodeMetadata;
|
||||
|
||||
IncineratorNodeMetadata::IncineratorNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("fuel", 1);
|
||||
|
||||
m_should_fire = false;
|
||||
m_step_accumulator = 0;
|
||||
m_fuel_totaltime = 0;
|
||||
m_fuel_time = 0;
|
||||
}
|
||||
IncineratorNodeMetadata::~IncineratorNodeMetadata()
|
||||
{
|
||||
delete m_inventory;
|
||||
}
|
||||
u16 IncineratorNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_INCINERATOR;
|
||||
}
|
||||
NodeMetadata* IncineratorNodeMetadata::clone()
|
||||
{
|
||||
IncineratorNodeMetadata *d = new IncineratorNodeMetadata();
|
||||
*d->m_inventory = *m_inventory;
|
||||
d->m_fuel_totaltime = m_fuel_totaltime;
|
||||
d->m_fuel_time = m_fuel_time;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* IncineratorNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
IncineratorNodeMetadata *d = new IncineratorNodeMetadata();
|
||||
|
||||
d->m_inventory->deSerialize(is);
|
||||
int temp;
|
||||
is>>temp;
|
||||
d->m_fuel_totaltime = (float)temp/10;
|
||||
is>>temp;
|
||||
d->m_fuel_time = (float)temp/10;
|
||||
|
||||
return d;
|
||||
}
|
||||
void IncineratorNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
m_inventory->serialize(os);
|
||||
os<<itos(m_fuel_totaltime*10)<<" ";
|
||||
os<<itos(m_fuel_time*10)<<" ";
|
||||
}
|
||||
std::wstring IncineratorNodeMetadata::infoText()
|
||||
{
|
||||
if (m_fuel_time < m_fuel_totaltime)
|
||||
return narrow_to_wide(gettext("Incinerator is active"));
|
||||
InventoryList *fuel_list = m_inventory->getList("fuel");
|
||||
if (fuel_list) {
|
||||
InventoryItem *fuel_item = fuel_list->getItem(0);
|
||||
if (fuel_item && fuel_item->isFuel())
|
||||
return narrow_to_wide(gettext("Incinerator is active"));
|
||||
}
|
||||
return narrow_to_wide(gettext("Incinerator is inactive"));
|
||||
}
|
||||
bool IncineratorNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
/*
|
||||
Disable removal if not empty
|
||||
*/
|
||||
InventoryList *list = m_inventory->getList("fuel");
|
||||
|
||||
if (list && list->getUsedSlots() > 0)
|
||||
return true;
|
||||
return false;
|
||||
|
||||
}
|
||||
void IncineratorNodeMetadata::inventoryModified()
|
||||
{
|
||||
vlprintf(CN_INFO,"Incinerator inventory modification callback");
|
||||
}
|
||||
bool IncineratorNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||
{
|
||||
MapNode n = env->getMap().getNodeNoEx(pos);
|
||||
if (n.getContent() == CONTENT_INCINERATOR_ACTIVE) {
|
||||
n.param2 = n.param1;
|
||||
n.setContent(CONTENT_INCINERATOR);
|
||||
env->setPostStepNodeSwap(pos,n);
|
||||
}
|
||||
if (dtime > 60.0)
|
||||
vlprintf(CN_INFO,"Incinerator stepping a long time (%f)",dtime);
|
||||
// Update at a fixed frequency
|
||||
const float interval = 2.0;
|
||||
m_step_accumulator += dtime;
|
||||
bool changed = false;
|
||||
while(m_step_accumulator > interval) {
|
||||
m_step_accumulator -= interval;
|
||||
dtime = interval;
|
||||
|
||||
/*
|
||||
If fuel is burning, increment the burn counters.
|
||||
*/
|
||||
if (m_fuel_time < m_fuel_totaltime) {
|
||||
m_fuel_time += dtime;
|
||||
changed = true;
|
||||
|
||||
// If the fuel was not used up this step, just keep burning it
|
||||
if (m_fuel_time < m_fuel_totaltime)
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
If the furnace is still cooking, stop loop.
|
||||
*/
|
||||
if (m_fuel_time < m_fuel_totaltime) {
|
||||
m_step_accumulator = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!m_should_fire) {
|
||||
m_step_accumulator = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
//vlprintf(CN_INFO,"Furnace is out of fuel");
|
||||
|
||||
InventoryList *fuel_list = m_inventory->getList("fuel");
|
||||
assert(fuel_list);
|
||||
InventoryItem *fuel_item = fuel_list->getItem(0);
|
||||
if (fuel_item && fuel_item->isFuel()) {
|
||||
if ((fuel_item->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
|
||||
m_fuel_totaltime = ((CraftItem*)fuel_item)->getFuelTime();
|
||||
}else if ((fuel_item->getContent()&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
|
||||
m_fuel_totaltime = ((ToolItem*)fuel_item)->getFuelTime();
|
||||
}else{
|
||||
m_fuel_totaltime = ((MaterialItem*)fuel_item)->getFuelTime();
|
||||
}
|
||||
m_fuel_time = 0;
|
||||
content_t c = fuel_item->getContent();
|
||||
fuel_list->decrementMaterials(1);
|
||||
if (c == CONTENT_TOOLITEM_STEELBUCKET_LAVA) {
|
||||
fuel_list->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0,0));
|
||||
}
|
||||
m_should_fire = false;
|
||||
changed = true;
|
||||
}else{
|
||||
m_step_accumulator = 0;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
std::string IncineratorNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
std::string spec("size[8,7]");
|
||||
spec += "label[1,0.5;";
|
||||
spec += gettext("Add fuel, then punch to incinerate wielded item");;
|
||||
spec += "]";
|
||||
spec += "label[3,1.5;";
|
||||
spec += gettext("Fuel");;
|
||||
spec += "]";
|
||||
spec += "list[current_name;fuel;4,1;1,1;]";
|
||||
spec += "ring[4,1;1;#FF0000;";
|
||||
float v = 0;
|
||||
if (m_fuel_totaltime > 0.0)
|
||||
v = 100.0-((100.0/m_fuel_totaltime)*m_fuel_time);
|
||||
spec += itos((int)v);
|
||||
spec += "]";
|
||||
spec += "list[current_player;main;0,3;8,4;]";
|
||||
return spec;
|
||||
}
|
||||
std::vector<NodeBox> IncineratorNodeMetadata::getNodeBoxes(MapNode &n)
|
||||
{
|
||||
std::vector<NodeBox> boxes;
|
||||
boxes.clear();
|
||||
InventoryList *list = m_inventory->getList("fuel");
|
||||
InventoryItem *fitem;
|
||||
|
||||
if (
|
||||
(
|
||||
m_fuel_time < m_fuel_totaltime
|
||||
) || (
|
||||
list
|
||||
&& list->getUsedSlots() > 0
|
||||
&& (fitem = list->getItem(0)) != NULL
|
||||
&& fitem->isFuel()
|
||||
)
|
||||
) {
|
||||
boxes.push_back(NodeBox(
|
||||
-0.3125*BS,-0.25*BS,-0.4*BS,0.3125*BS,0.125*BS,-0.3*BS
|
||||
));
|
||||
}
|
||||
|
||||
return transformNodeBox(n,boxes);
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_nodemeta.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2017 <lisa@ltmnet.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 3 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, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "content_mapnode.h"
|
||||
#include "player.h"
|
||||
|
||||
|
||||
/*
|
||||
SignNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
SignNodeMetadata proto_SignNodeMetadata("");
|
||||
|
||||
SignNodeMetadata::SignNodeMetadata(std::string text):
|
||||
m_text(text)
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
}
|
||||
u16 SignNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_SIGN_WALL;
|
||||
}
|
||||
NodeMetadata* SignNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
std::string text = deSerializeString(is);
|
||||
return new SignNodeMetadata(text);
|
||||
}
|
||||
NodeMetadata* SignNodeMetadata::clone()
|
||||
{
|
||||
return new SignNodeMetadata(m_text);
|
||||
}
|
||||
void SignNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<serializeString(m_text);
|
||||
}
|
||||
std::string SignNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
std::string spec("size[5,2.5]");
|
||||
spec += "field[0.75,0;4,1.5;text;;";
|
||||
spec += m_text;
|
||||
spec += "]";
|
||||
spec += "button_exit[1.25,2;3,1;save;";
|
||||
spec += gettext("Save");
|
||||
spec += "]";
|
||||
return spec;
|
||||
}
|
||||
bool SignNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
if (meta->typeId() != CONTENT_LOCKABLE_SIGN_WALL)
|
||||
return false;
|
||||
LockingSignNodeMetadata *l = (LockingSignNodeMetadata*)meta;
|
||||
m_text = l->getText();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
LockingSignNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
LockingSignNodeMetadata proto_LockingSignNodeMetadata("");
|
||||
|
||||
LockingSignNodeMetadata::LockingSignNodeMetadata(std::string text):
|
||||
m_text(text)
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
}
|
||||
u16 LockingSignNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_LOCKABLE_SIGN_WALL;
|
||||
}
|
||||
NodeMetadata* LockingSignNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
std::string text = deSerializeString(is);
|
||||
LockingSignNodeMetadata *d = new LockingSignNodeMetadata(text);
|
||||
d->setOwner(deSerializeString(is));
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* LockingSignNodeMetadata::clone()
|
||||
{
|
||||
return new LockingSignNodeMetadata(m_text);
|
||||
}
|
||||
void LockingSignNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<serializeString(m_text);
|
||||
os<<serializeString(m_owner);
|
||||
}
|
||||
std::wstring LockingSignNodeMetadata::infoText()
|
||||
{
|
||||
return narrow_to_wide(std::string("(")+m_owner+")");
|
||||
}
|
||||
bool LockingSignNodeMetadata::receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player)
|
||||
{
|
||||
if (getOwner() != player->getName())
|
||||
return false;
|
||||
m_text = fields["text"];
|
||||
return true;
|
||||
}
|
||||
std::string LockingSignNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
std::string spec("size[5,2.5]");
|
||||
spec += "field[0.75,0;4,1.5;text;;";
|
||||
spec += m_text;
|
||||
spec += "]";
|
||||
spec += "button_exit[1.25,2;3,1;save;";
|
||||
spec += gettext("Save");
|
||||
spec += "]";
|
||||
return spec;
|
||||
}
|
||||
bool LockingSignNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
if (meta->typeId() != CONTENT_SIGN_WALL)
|
||||
return false;
|
||||
SignNodeMetadata *l = (SignNodeMetadata*)meta;
|
||||
m_text = l->getText();
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,249 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_nodemeta.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2014 <lisa@ltmnet.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 3 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, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "inventory.h"
|
||||
#include "content_mapnode.h"
|
||||
#include "player.h"
|
||||
|
||||
|
||||
/*
|
||||
ChestNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
ChestNodeMetadata proto_ChestNodeMetadata;
|
||||
|
||||
ChestNodeMetadata::ChestNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("0", 8*4);
|
||||
}
|
||||
ChestNodeMetadata::~ChestNodeMetadata()
|
||||
{
|
||||
delete m_inventory;
|
||||
}
|
||||
u16 ChestNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_CHEST;
|
||||
}
|
||||
NodeMetadata* ChestNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
ChestNodeMetadata *d = new ChestNodeMetadata();
|
||||
d->m_inventory->deSerialize(is);
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* ChestNodeMetadata::clone()
|
||||
{
|
||||
ChestNodeMetadata *d = new ChestNodeMetadata();
|
||||
*d->m_inventory = *m_inventory;
|
||||
return d;
|
||||
}
|
||||
void ChestNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
m_inventory->serialize(os);
|
||||
}
|
||||
std::wstring ChestNodeMetadata::infoText()
|
||||
{
|
||||
return narrow_to_wide(gettext("Chest"));
|
||||
}
|
||||
bool ChestNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
/*
|
||||
Disable removal if chest contains something
|
||||
*/
|
||||
InventoryList *list = m_inventory->getList("0");
|
||||
if(list == NULL)
|
||||
return false;
|
||||
if(list->getUsedSlots() == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
std::string ChestNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
return
|
||||
"size[8,9]"
|
||||
"list[current_name;0;0,0;8,4;]"
|
||||
"list[current_player;main;0,5;8,4;]";
|
||||
}
|
||||
bool ChestNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
if (meta->typeId() != CONTENT_LOCKABLE_CHEST)
|
||||
return false;
|
||||
LockingChestNodeMetadata *l = (LockingChestNodeMetadata*)meta;
|
||||
*m_inventory = *l->getInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
LockingChestNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
LockingChestNodeMetadata proto_LockingChestNodeMetadata;
|
||||
|
||||
LockingChestNodeMetadata::LockingChestNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("0", 8*4);
|
||||
}
|
||||
LockingChestNodeMetadata::~LockingChestNodeMetadata()
|
||||
{
|
||||
delete m_inventory;
|
||||
}
|
||||
u16 LockingChestNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_LOCKABLE_CHEST;
|
||||
}
|
||||
NodeMetadata* LockingChestNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
LockingChestNodeMetadata *d = new LockingChestNodeMetadata();
|
||||
d->setOwner(deSerializeString(is));
|
||||
d->m_inventory->deSerialize(is);
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* LockingChestNodeMetadata::clone()
|
||||
{
|
||||
LockingChestNodeMetadata *d = new LockingChestNodeMetadata();
|
||||
*d->m_inventory = *m_inventory;
|
||||
return d;
|
||||
}
|
||||
void LockingChestNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<serializeString(m_owner);
|
||||
m_inventory->serialize(os);
|
||||
}
|
||||
std::wstring LockingChestNodeMetadata::infoText()
|
||||
{
|
||||
char buff[256];
|
||||
snprintf(buff, 256, gettext("Locking Chest owned by '%s'"), m_owner.c_str());
|
||||
return narrow_to_wide(buff);
|
||||
}
|
||||
bool LockingChestNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
/*
|
||||
Disable removal if chest contains something
|
||||
*/
|
||||
InventoryList *list = m_inventory->getList("0");
|
||||
if(list == NULL)
|
||||
return false;
|
||||
if(list->getUsedSlots() == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
std::string LockingChestNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
return
|
||||
"size[8,9]"
|
||||
"list[current_name;0;0,0;8,4;]"
|
||||
"list[current_player;main;0,5;8,4;]";
|
||||
}
|
||||
bool LockingChestNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
if (meta->typeId() != CONTENT_CHEST)
|
||||
return false;
|
||||
ChestNodeMetadata *l = (ChestNodeMetadata*)meta;
|
||||
*m_inventory = *l->getInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
SafeNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
SafeNodeMetadata proto_SafeNodeMetadata;
|
||||
|
||||
SafeNodeMetadata::SafeNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("0", 8*4);
|
||||
}
|
||||
SafeNodeMetadata::~SafeNodeMetadata()
|
||||
{
|
||||
delete m_inventory;
|
||||
}
|
||||
u16 SafeNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_SAFE;
|
||||
}
|
||||
NodeMetadata* SafeNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
SafeNodeMetadata *d = new SafeNodeMetadata();
|
||||
d->setOwner(deSerializeString(is));
|
||||
d->m_inventory->deSerialize(is);
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* SafeNodeMetadata::clone()
|
||||
{
|
||||
SafeNodeMetadata *d = new SafeNodeMetadata();
|
||||
*d->m_inventory = *m_inventory;
|
||||
return d;
|
||||
}
|
||||
void SafeNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<serializeString(m_owner);
|
||||
m_inventory->serialize(os);
|
||||
}
|
||||
std::wstring SafeNodeMetadata::infoText()
|
||||
{
|
||||
char buff[256];
|
||||
snprintf(buff, 256, gettext("Safe owned by '%s'"), m_owner.c_str());
|
||||
return narrow_to_wide(buff);
|
||||
}
|
||||
bool SafeNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
/*
|
||||
Disable removal if chest contains something
|
||||
*/
|
||||
InventoryList *list = m_inventory->getList("0");
|
||||
if(list == NULL)
|
||||
return false;
|
||||
if(list->getUsedSlots() == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
std::string SafeNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
return
|
||||
"size[8,9]"
|
||||
"list[current_name;0;0,0;8,4;]"
|
||||
"list[current_player;main;0,5;8,4;]";
|
||||
}
|
||||
bool SafeNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
if (meta->typeId() != CONTENT_CHEST)
|
||||
return false;
|
||||
ChestNodeMetadata *l = (ChestNodeMetadata*)meta;
|
||||
*m_inventory = *l->getInventory();
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,224 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_nodemeta.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2014 <lisa@ltmnet.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 3 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, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "list.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "inventory.h"
|
||||
#include "content_mapnode.h"
|
||||
#include "content_list.h"
|
||||
#include "environment.h"
|
||||
|
||||
/*
|
||||
ParcelNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
ParcelNodeMetadata proto_ParcelNodeMetadata;
|
||||
|
||||
ParcelNodeMetadata::ParcelNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("0", 8*4);
|
||||
}
|
||||
ParcelNodeMetadata::~ParcelNodeMetadata()
|
||||
{
|
||||
delete m_inventory;
|
||||
}
|
||||
u16 ParcelNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_PARCEL;
|
||||
}
|
||||
NodeMetadata* ParcelNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
ParcelNodeMetadata *d = new ParcelNodeMetadata();
|
||||
d->m_inventory->deSerialize(is);
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* ParcelNodeMetadata::clone()
|
||||
{
|
||||
ParcelNodeMetadata *d = new ParcelNodeMetadata();
|
||||
*d->m_inventory = *m_inventory;
|
||||
return d;
|
||||
}
|
||||
void ParcelNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
m_inventory->serialize(os);
|
||||
}
|
||||
std::string ParcelNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
return
|
||||
"size[8,4]"
|
||||
"list[current_name;0;0,0;8,4;]";
|
||||
}
|
||||
|
||||
/*
|
||||
CreativeChestNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
CreativeChestNodeMetadata proto_CreativeChestNodeMetadata;
|
||||
|
||||
CreativeChestNodeMetadata::CreativeChestNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_page = 0;
|
||||
|
||||
m_inventory = new Inventory();
|
||||
m_inventory->addList("0", 8*4);
|
||||
}
|
||||
CreativeChestNodeMetadata::~CreativeChestNodeMetadata()
|
||||
{
|
||||
delete m_inventory;
|
||||
}
|
||||
u16 CreativeChestNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_CREATIVE_CHEST;
|
||||
}
|
||||
NodeMetadata* CreativeChestNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
CreativeChestNodeMetadata *d = new CreativeChestNodeMetadata();
|
||||
d->m_inventory->deSerialize(is);
|
||||
is>>d->m_page;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* CreativeChestNodeMetadata::clone()
|
||||
{
|
||||
contentlist_t *cl;
|
||||
listdata_t *ld;
|
||||
CreativeChestNodeMetadata *d = new CreativeChestNodeMetadata();
|
||||
|
||||
*d->m_inventory = *m_inventory;
|
||||
InventoryList *l = d->m_inventory->getList("0");
|
||||
InventoryItem *t;
|
||||
l->clearItems();
|
||||
|
||||
cl = content_list_get("creative");
|
||||
if (!cl)
|
||||
return d;
|
||||
|
||||
ld = cl->data;
|
||||
while (ld) {
|
||||
t = InventoryItem::create(ld->content,ld->count,0,ld->data);
|
||||
l->addItem(t);
|
||||
ld = ld->next;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
void CreativeChestNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
m_inventory->serialize(os);
|
||||
os<<itos(m_page) << " ";
|
||||
}
|
||||
std::wstring CreativeChestNodeMetadata::infoText()
|
||||
{
|
||||
return narrow_to_wide(gettext("Creative Chest"));
|
||||
}
|
||||
bool CreativeChestNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool CreativeChestNodeMetadata::receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player)
|
||||
{
|
||||
contentlist_t *cl;
|
||||
listdata_t *ld;
|
||||
uint32_t list_size = 0;
|
||||
uint32_t start;
|
||||
uint32_t end;
|
||||
uint32_t i;
|
||||
|
||||
if (fields["prev"] == "" && fields["next"] == "")
|
||||
return false;
|
||||
|
||||
cl = content_list_get("creative");
|
||||
if (!cl)
|
||||
return false;
|
||||
|
||||
list_size = list_count(&cl->data);
|
||||
|
||||
if (fields["prev"] != "") {
|
||||
if (m_page > 0) {
|
||||
m_page--;
|
||||
}else{
|
||||
m_page = list_size/32;
|
||||
}
|
||||
}
|
||||
if (fields["next"] != "")
|
||||
m_page++;
|
||||
if (m_page < 0)
|
||||
m_page = 0;
|
||||
if (m_page > (list_size/32))
|
||||
m_page = 0;
|
||||
InventoryList *l = m_inventory->getList("0");
|
||||
InventoryItem *t;
|
||||
l->clearItems();
|
||||
|
||||
start = m_page*32;
|
||||
end = start+32;
|
||||
|
||||
if (end > list_size)
|
||||
end = list_size;
|
||||
|
||||
ld = cl->data;
|
||||
for (i=0; ld && i<end; i++) {
|
||||
if (i >= start) {
|
||||
t = InventoryItem::create(ld->content,ld->count,0,ld->data);
|
||||
l->addItem(t);
|
||||
}
|
||||
ld = ld->next;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
std::string CreativeChestNodeMetadata::getDrawSpecString(Player *player)
|
||||
{
|
||||
char buff[256];
|
||||
contentlist_t *cl;
|
||||
uint32_t list_size = 0;
|
||||
|
||||
cl = content_list_get("creative");
|
||||
if (cl)
|
||||
list_size = list_count(&cl->data);
|
||||
|
||||
snprintf(buff,256,gettext("Page %d of %d"),(int)(m_page+1),(int)((list_size/32)+1));
|
||||
std::string spec("size[8,10]");
|
||||
spec += "list[current_name;0;0,0.5;8,4;]";
|
||||
spec += "button[0.25,5;2.5,0.75;prev;";
|
||||
spec += gettext("<< Previous Page");;
|
||||
spec += "]";
|
||||
spec += "label[3.5,5;";
|
||||
spec += buff;
|
||||
spec += "]";
|
||||
spec += "button[6,5;2.5,0.75;next;";
|
||||
spec += gettext("Next Page >>");;
|
||||
spec += "]";
|
||||
spec += "list[current_player;main;0,6;8,4;]";
|
||||
|
||||
return spec;
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_nodemeta.cpp
|
||||
* voxelands - 3d voxel world sandbox game
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2013-2017 <lisa@ltmnet.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 3 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, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
||||
* for Voxelands.
|
||||
************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "inventory.h"
|
||||
#include "content_mapnode.h"
|
||||
#include "environment.h"
|
||||
|
||||
/*
|
||||
LockedDoorNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
TNTNodeMetadata proto_TNTNodeMetadata;
|
||||
|
||||
TNTNodeMetadata::TNTNodeMetadata():
|
||||
m_armed(false),
|
||||
m_time(0)
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
}
|
||||
TNTNodeMetadata::~TNTNodeMetadata()
|
||||
{
|
||||
}
|
||||
u16 TNTNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_TNT;
|
||||
}
|
||||
NodeMetadata* TNTNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
TNTNodeMetadata *d = new TNTNodeMetadata();
|
||||
int temp;
|
||||
is>>temp;
|
||||
d->m_time = (float)temp/10;
|
||||
is>>temp;
|
||||
d->m_armed = (bool)temp;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* TNTNodeMetadata::clone()
|
||||
{
|
||||
TNTNodeMetadata *d = new TNTNodeMetadata();
|
||||
return d;
|
||||
}
|
||||
bool TNTNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||
{
|
||||
if (!m_armed)
|
||||
return false;
|
||||
m_time -= dtime;
|
||||
if (m_time < 0.0)
|
||||
m_time = 0.0;
|
||||
return true;
|
||||
}
|
||||
bool TNTNodeMetadata::energise(u8 level, v3s16 powersrc, v3s16 signalsrc, v3s16 pos)
|
||||
{
|
||||
m_armed = true;
|
||||
m_time = 5.0;
|
||||
return true;
|
||||
}
|
||||
u8 TNTNodeMetadata::getEnergy()
|
||||
{
|
||||
if (!m_armed)
|
||||
return 0;
|
||||
return ENERGY_MAX-((u8)m_time);
|
||||
}
|
||||
void TNTNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<itos(m_time*10) << " ";
|
||||
os<<itos(m_armed) << " ";
|
||||
}
|
||||
std::wstring TNTNodeMetadata::infoText()
|
||||
{
|
||||
char buff[256];
|
||||
if (!m_armed)
|
||||
return L"";
|
||||
|
||||
int s = (int)ceil(m_time);
|
||||
if (s < 1)
|
||||
return narrow_to_wide(gettext("Armed Explosive: about to detonate"));
|
||||
|
||||
snprintf(buff, 256, ngettext("Armed Explosive: %d second till detonation","Armed Explosive: %d seconds till detonation",s),s);
|
||||
return narrow_to_wide(buff);
|
||||
}
|
|
@ -1796,7 +1796,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
|
|||
static gui::IGUIFont *tex_font = NULL;
|
||||
#if USE_FREETYPE
|
||||
if (path_get("font","unifont.ttf",1,buff,1024))
|
||||
tex_font = gui::CGUITTFont::createTTFont(guienv, buff,10);
|
||||
tex_font = gui::CGUITTFont::createTTFont(guienv, buff,12);
|
||||
#else
|
||||
if (path_get((char*)"texture",(char*)"fontlucida.png",1,buff,1024))
|
||||
tex_font = guienv->getFont(buff);
|
||||
|
|
Loading…
Reference in New Issue