replace creative_mode = true/false with game_mode = creative/adventure/survival and have each mode set some defaults

This commit is contained in:
darkrose 2014-09-20 22:29:21 +10:00
parent c7cc80c748
commit 000b6b4f2e
11 changed files with 281 additions and 168 deletions

View File

@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "settings.h"
#include "defaultsettings.h"
void set_default_settings(Settings *settings)
{
@ -109,15 +110,13 @@ void set_default_settings(Settings *settings)
settings->setDefault("max_users", "20");
settings->setDefault("strict_protocol_version_checking", "false");
settings->setDefault("disallow_empty_passwords","false");
settings->setDefault("creative_mode", "false");
settings->setDefault("enable_damage", "true");
settings->setDefault("max_mob_level", "aggressive");
settings->setDefault("fixed_map_seed", "");
settings->setDefault("give_initial_stuff", "true");
settings->setDefault("default_password", "");
settings->setDefault("default_privs", "build, shout");
settings->setDefault("borderstone_radius","5");
settings->setDefault("enable_footprints","true");
settings->setDefault("game_mode","adventure");
set_adventure_defaults(settings);
// only enable http on the server for now
// adventurous players can enable it on the client
@ -148,3 +147,43 @@ void set_default_settings(Settings *settings)
settings->setDefault("enable_tnt", "true");
}
void set_creative_defaults(Settings *settings)
{
settings->setDefault("infinite_inventory", "true");
settings->setDefault("droppable_inventory", "false");
settings->setDefault("enable_damage", "false");
settings->setDefault("max_mob_level", "passive");
settings->setDefault("initial_inventory", "false");
settings->setDefault("tool_wear","false");
}
void set_adventure_defaults(Settings *settings)
{
settings->setDefault("infinite_inventory", "false");
settings->setDefault("droppable_inventory", "true");
settings->setDefault("enable_damage", "true");
settings->setDefault("max_mob_level", "aggressive");
settings->setDefault("initial_inventory", "true");
settings->setDefault("tool_wear","true");
}
void set_survival_defaults(Settings *settings)
{
settings->setDefault("infinite_inventory", "false");
settings->setDefault("droppable_inventory", "true");
settings->setDefault("enable_damage", "true");
settings->setDefault("max_mob_level", "aggressive");
settings->setDefault("initial_inventory", "false");
settings->setDefault("tool_wear","true");
}
void GameSettings::setGameDefaults(std::string mode)
{
if (mode == "creative") {
set_creative_defaults(this);
}else if (mode == "survival") {
set_survival_defaults(this);
}else{
set_adventure_defaults(this);
}
}

View File

@ -23,6 +23,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class Settings;
void set_default_settings(Settings *settings);
void set_creative_defaults(Settings *settings);
void set_adventure_defaults(Settings *settings);
void set_survival_defaults(Settings *settings);
#endif

View File

@ -754,7 +754,6 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
Inventory *inv = m_invmgr->getInventory(&s.inventoryloc);
assert(inv);
InventoryList *list = inv->getList(s.listname);
printf("here 'tis '%s' '%lX'\n",s.listname.c_str(),list);
if (list && list->getItem(s.i) != NULL) {
m_selected_item = new ItemSpec(s);
}

View File

@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <string>
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIComboBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
@ -78,8 +79,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
std::wstring text_name;
std::wstring text_address;
std::wstring text_port;
bool creative_mode;
bool enable_damage;
std::wstring game_mode;
bool fancy_trees;
bool smooth_lighting;
bool clouds_3d;
@ -188,18 +188,25 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
// Server options
{
gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
else
creative_mode = m_data->creative_mode;
}
{
gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
else
enable_damage = m_data->enable_damage;
gui::IGUIElement *e = getElementFromId(GUI_ID_GAME_MODE_COMBO);
if (e != NULL && e->getType() == gui::EGUIET_COMBO_BOX) {
gui::IGUIComboBox *c = (gui::IGUIComboBox*)e;
switch (c->getItemData(c->getSelected())) {
case GUI_ID_GAME_MODE_CREATIVE:
game_mode = L"creative";
break;
case GUI_ID_GAME_MODE_ADVENTURE:
game_mode = L"adventure";
break;
case GUI_ID_GAME_MODE_SURVIVAL:
game_mode = L"survival";
break;
default:
game_mode = L"adventure";
}
}else{
game_mode = m_data->game_mode;
}
}
/*
@ -431,24 +438,29 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
// Server parameters
{
core::rect<s32> rect(0, 0, 200, 30);
rect += topleft_content + v2s32(135, 60);
Environment->addCheckBox(creative_mode, rect, this, GUI_ID_CREATIVE_CB, wgettext("Creative Mode"));
}
{
core::rect<s32> rect(0, 0, 200, 30);
rect += topleft_content + v2s32(135, 90);
Environment->addCheckBox(enable_damage, rect, this, GUI_ID_DAMAGE_CB, wgettext("Enable Damage"));
rect += topleft_content + v2s32(100, 60);
gui::IGUIComboBox *c = Environment->addComboBox(rect, this, GUI_ID_GAME_MODE_COMBO);
u32 cm = c->addItem(wgettext("Creative Mode"),GUI_ID_GAME_MODE_CREATIVE);
u32 am = c->addItem(wgettext("Adventure Mode"),GUI_ID_GAME_MODE_ADVENTURE);
u32 sm = c->addItem(wgettext("Survival Mode"),GUI_ID_GAME_MODE_SURVIVAL);
if (game_mode == L"creative") {
c->setSelected(cm);
}else if (game_mode == L"adventure") {
c->setSelected(am);
}else if (game_mode == L"survival") {
c->setSelected(sm);
}
}
// Map delete button
{
core::rect<s32> rect(0, 0, 130, 30);
rect += topleft_content + v2s32(135, 130);
rect += topleft_content + v2s32(135, 100);
Environment->addButton(rect, this, GUI_ID_DELETE_MAP_BUTTON, wgettext("Delete map"));
}
// Start game button
{
core::rect<s32> rect(0, 0, 180, 30);
rect += topleft_content + v2s32(110, 200);
rect += topleft_content + v2s32(110, 170);
Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON, wgettext("Start Game"));
}
}else if(m_data->selected_tab == TAB_CREDITS) {
@ -553,14 +565,23 @@ void GUIMainMenu::acceptInput()
m_data->port = e->getText();
}
{
gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
m_data->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
}
{
gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
m_data->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
gui::IGUIElement *e = getElementFromId(GUI_ID_GAME_MODE_COMBO);
if (e != NULL && e->getType() == gui::EGUIET_COMBO_BOX) {
gui::IGUIComboBox *c = (gui::IGUIComboBox*)e;
switch (c->getItemData(c->getSelected())) {
case GUI_ID_GAME_MODE_CREATIVE:
m_data->game_mode = L"creative";
break;
case GUI_ID_GAME_MODE_ADVENTURE:
m_data->game_mode = L"adventure";
break;
case GUI_ID_GAME_MODE_SURVIVAL:
m_data->game_mode = L"survival";
break;
default:
m_data->game_mode = L"adventure";
}
}
}
{
gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB);
@ -633,30 +654,25 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
return true;
}
}
if(event.EventType==EET_GUI_EVENT)
{
if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
&& isVisible())
{
if(!canTakeFocus(event.GUIEvent.Element))
{
if (event.EventType==EET_GUI_EVENT) {
if (event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) {
if (!canTakeFocus(event.GUIEvent.Element)) {
dstream<<"GUIMainMenu: Not allowing focus change."
<<std::endl;
// Returning true disables focus change
return true;
}
}
if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
{
switch(event.GUIEvent.Caller->getID())
{
if (event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED) {
switch (event.GUIEvent.Caller->getID()) {
case GUI_ID_JOIN_GAME_BUTTON: // Start game
acceptInput();
if (m_data->selected_tab == TAB_SINGLEPLAYER)
m_data->address = std::wstring(L"");
quitMenu();
return true;
case GUI_ID_CHANGE_KEYS_BUTTON: {
case GUI_ID_CHANGE_KEYS_BUTTON:
{
GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr);
kmenu->drop();
return true;
@ -705,11 +721,20 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
return true;
}
}
if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
{
switch(event.GUIEvent.Caller->getID())
{
case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264:
if (event.GUIEvent.EventType == gui::EGET_COMBO_BOX_CHANGED) {
switch (event.GUIEvent.Caller->getID()) {
case GUI_ID_GAME_MODE_COMBO:
acceptInput();
m_accepted = false;
return true;
}
}
if (event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER) {
switch (event.GUIEvent.Caller->getID()) {
case GUI_ID_ADDRESS_INPUT:
case GUI_ID_PORT_INPUT:
case GUI_ID_NAME_INPUT:
case 264:
acceptInput();
quitMenu();
return true;

View File

@ -42,8 +42,10 @@ enum {
GUI_ID_ANISOTROPIC_CB,
GUI_ID_PARTICLES_CB,
GUI_ID_FULLSCREEN_CB,
GUI_ID_DAMAGE_CB,
GUI_ID_CREATIVE_CB,
GUI_ID_GAME_MODE_COMBO,
GUI_ID_GAME_MODE_CREATIVE,
GUI_ID_GAME_MODE_ADVENTURE,
GUI_ID_GAME_MODE_SURVIVAL,
GUI_ID_JOIN_GAME_BUTTON,
GUI_ID_CHANGE_KEYS_BUTTON,
GUI_ID_DELETE_MAP_BUTTON,
@ -72,8 +74,7 @@ struct MainMenuData
particles(true),
fullscreen(false),
// Server opts
creative_mode(false),
enable_damage(false),
game_mode(L"adventure"),
// Actions
delete_map(false)
{}
@ -99,8 +100,7 @@ struct MainMenuData
bool particles;
bool fullscreen;
// Server options
bool creative_mode;
bool enable_damage;
std::wstring game_mode;
// If map deletion is requested, this is set to true
bool delete_map;
};

View File

@ -81,8 +81,8 @@ ITextureSource *g_texturesource = NULL;
Settings.
These are loaded from the config file.
*/
Settings main_settings;
Settings *g_settings = &main_settings;
GameSettings main_settings;
GameSettings *g_settings = &main_settings;
// Global profiler
Profiler main_profiler;
@ -1197,8 +1197,7 @@ int main(int argc, char *argv[])
menudata.bilinear_filter = g_settings->getBool("bilinear_filter");
menudata.trilinear_filter = g_settings->getBool("trilinear_filter");
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, menudata.mip_map);
menudata.creative_mode = g_settings->getBool("creative_mode");
menudata.enable_damage = g_settings->getBool("enable_damage");
menudata.game_mode = narrow_to_wide(g_settings->get("game_mode"));
GUIMainMenu *menu =
new GUIMainMenu(guienv, guiroot, -1,
@ -1277,8 +1276,7 @@ int main(int argc, char *argv[])
g_settings->set("trilinear_filter", itos(menudata.trilinear_filter));
g_settings->set("fullscreen", itos(menudata.fullscreen));
g_settings->set("enable_particles", itos(menudata.particles));
g_settings->set("creative_mode", itos(menudata.creative_mode));
g_settings->set("enable_damage", itos(menudata.enable_damage));
g_settings->set("game_mode", wide_to_narrow(menudata.game_mode));
// NOTE: These are now checked server side; no need to do it
// here, so let's not do it here.

View File

@ -21,8 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MAIN_HEADER
// Settings
class Settings;
extern Settings *g_settings;
class GameSettings;
extern GameSettings *g_settings;
// This makes and maps textures
class ITextureSource;

View File

@ -2304,7 +2304,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if (ilist != NULL) {
actionstream<<player->getName()<<" picked up "
<<item->getName()<<std::endl;
if (g_settings->getBool("creative_mode") == false) {
if (g_settings->getBool("infinite_inventory") == false) {
// Skip if inventory has no free space
if (ilist->roomForItem(item) == false) {
infostream<<"Player inventory has no free space"<<std::endl;
@ -2352,7 +2352,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if (ilist != NULL) {
actionstream<<player->getName()<<" picked up "
<<item->getName()<<std::endl;
if (g_settings->getBool("creative_mode") == false) {
if (g_settings->getBool("infinite_inventory") == false) {
// Skip if inventory has no free space
if (ilist->roomForItem(item) == false) {
infostream<<"Player inventory has no free space"<<std::endl;
@ -2367,7 +2367,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
}
if (titem) {
if (titem && g_settings->getBool("tool_wear")) {
bool weared_out = titem->addWear(wear);
if(weared_out)
mlist->deleteItem(item_i);
@ -2633,12 +2633,14 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
}
ToolItem *titem = (ToolItem*)wield;
bool weared_out = titem->addWear(1000);
if (weared_out) {
InventoryList *mlist = player->inventory.getList("main");
mlist->deleteItem(item_i);
if (g_settings->getBool("tool_wear")) {
bool weared_out = titem->addWear(1000);
if (weared_out) {
InventoryList *mlist = player->inventory.getList("main");
mlist->deleteItem(item_i);
}
SendInventory(player->peer_id);
}
SendInventory(player->peer_id);
}
}else if (content_features(n).energy_type != CET_NONE && (!wield || wield->getContent() != CONTENT_TOOLITEM_CROWBAR)) {
if (wield && wield->getContent() == CONTENT_TOOLITEM_FIRESTARTER) {
@ -2666,12 +2668,14 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
meta->energise(ENERGY_MAX,pp,pp,p_under);
}
ToolItem *titem = (ToolItem*)wield;
bool weared_out = titem->addWear(1000);
if (weared_out) {
InventoryList *mlist = player->inventory.getList("main");
mlist->deleteItem(item_i);
if (g_settings->getBool("tool_wear")) {
bool weared_out = titem->addWear(1000);
if (weared_out) {
InventoryList *mlist = player->inventory.getList("main");
mlist->deleteItem(item_i);
}
SendInventory(player->peer_id);
}
SendInventory(player->peer_id);
}else if (content_features(n).energy_type == CET_SWITCH) {
NodeMetadata *meta = m_env.getMap().getNodeMetadata(p_under);
if (meta) {
@ -2781,12 +2785,14 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
sendAddNode(p_under, n, 0, &far_players, 30);
// wear out the crowbar
ToolItem *titem = (ToolItem*)wield;
bool weared_out = titem->addWear(200);
if (weared_out) {
InventoryList *mlist = player->inventory.getList("main");
mlist->deleteItem(item_i);
if (g_settings->getBool("tool_wear")) {
bool weared_out = titem->addWear(200);
if (weared_out) {
InventoryList *mlist = player->inventory.getList("main");
mlist->deleteItem(item_i);
}
SendInventory(player->peer_id);
}
SendInventory(player->peer_id);
// the slow add to map
{
MapEditEventIgnorer ign(&m_ignore_map_edit_events);
@ -3202,17 +3208,14 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
Update and send inventory
*/
if(g_settings->getBool("creative_mode") == false)
{
if (g_settings->getBool("infinite_inventory") == false) {
/*
Wear out tool
*/
InventoryList *mlist = player->inventory.getList("main");
if(mlist != NULL)
{
if (mlist != NULL && g_settings->getBool("tool_wear")) {
InventoryItem *item = mlist->getItem(item_i);
if(item && (std::string)item->getName() == "ToolItem")
{
if (item && (std::string)item->getName() == "ToolItem") {
ToolItem *titem = (ToolItem*)item;
// Get digging properties for material and tool
DiggingProperties prop = getDiggingProperties(material, titem->getContent());
@ -3808,8 +3811,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
Handle inventory
*/
InventoryList *ilist = player->inventory.getList("main");
if(g_settings->getBool("creative_mode") == false && ilist)
{
if(g_settings->getBool("infinite_inventory") == false && ilist) {
// Remove from inventory and send inventory
if(mitem->getCount() == 1)
ilist->deleteItem(item_i);
@ -3904,7 +3906,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|| item->getContent() == CONTENT_TOOLITEM_TINBUCKET_WATER
) {
if (ilist != NULL) {
if (g_settings->getBool("creative_mode") == false) {
if (g_settings->getBool("infinite_inventory") == false) {
std::string dug_s = std::string("ToolItem ");
if (item->getContent() == CONTENT_TOOLITEM_WBUCKET_WATER) {
dug_s += "WBucket 1";
@ -3952,7 +3954,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}else if (item->getContent() == CONTENT_TOOLITEM_STEELBUCKET_LAVA) {
if (ilist != NULL) {
if (g_settings->getBool("enable_lavabuckets")) {
if (g_settings->getBool("creative_mode") == false) {
if (g_settings->getBool("infinite_inventory") == false) {
std::string dug_s = std::string("ToolItem SteelBucket 1");
std::istringstream is(dug_s, std::ios::binary);
InventoryItem *item = InventoryItem::deSerialize(is);
@ -3998,13 +4000,18 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
}
}else if (item->getContent() == CONTENT_CRAFTITEM_MESEDUST) {
if ((getPlayerPrivs(player) & PRIV_BUILD) == 0) {
infostream<<"Not allowing player to drop item: "
"no build privs"<<std::endl;
return;
}
MapNode n = m_env.getMap().getNodeNoEx(p_over);
if (n.getContent() != CONTENT_AIR)
return;
n.setContent(CONTENT_CIRCUIT_MESEWIRE);
core::list<u16> far_players;
sendAddNode(p_over, n, 0, &far_players, 30);
if (g_settings->getBool("creative_mode") == false) {
if (g_settings->getBool("infinite_inventory") == false) {
// Delete the right amount of items from the slot
u16 dropcount = item->getDropCount();
// Delete item if all gone
@ -4053,14 +4060,12 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
If in creative mode, item dropping is disabled unless
player has build privileges
*/
if(g_settings->getBool("creative_mode") &&
(getPlayerPrivs(player) & PRIV_BUILD) == 0)
{
if ((getPlayerPrivs(player) & PRIV_BUILD) == 0) {
infostream<<"Not allowing player to drop item: "
"creative mode and no build privs"<<std::endl;
"no build privs"<<std::endl;
return;
}
if (g_settings->getBool("creative_mode") == false) {
if (g_settings->getBool("infinite_inventory") == false) {
// Delete the right amount of items from the slot
u16 dropcount = item->getDropCount();
@ -4091,8 +4096,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
/*
Place other item (not a block)
*/
else
{
else{
v3s16 blockpos = getNodeBlockPos(p_over);
/*
@ -4100,8 +4104,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
can properly be added to the static list too
*/
MapBlock *block = m_env.getMap().getBlockNoCreateNoEx(blockpos);
if(block==NULL)
{
if (block==NULL) {
infostream<<"Error while placing object: "
"block not found"<<std::endl;
return;
@ -4111,9 +4114,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
If in creative mode, item dropping is disabled unless
player has build privileges
*/
if(g_settings->getBool("creative_mode") &&
(getPlayerPrivs(player) & PRIV_BUILD) == 0)
{
if (g_settings->getBool("droppable_inventory") == false || (getPlayerPrivs(player) & PRIV_BUILD) == 0) {
infostream<<"Not allowing player to drop item: "
"creative mode and no build privs"<<std::endl;
return;
@ -4132,14 +4133,11 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
*/
ServerActiveObject *obj = item->createSAO(&m_env, 0, pos);
if(obj == NULL)
{
if (obj == NULL) {
infostream<<"WARNING: item resulted in NULL object, "
<<"not placing onto map"
<<std::endl;
}
else
{
}else{
actionstream<<player->getName()<<" places "<<item->getName()
<<" at "<<PP(p_over)<<std::endl;
@ -4148,14 +4146,12 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
infostream<<"Placed object"<<std::endl;
if(g_settings->getBool("creative_mode") == false)
{
if (g_settings->getBool("infinite_inventory") == false) {
// Delete the right amount of items from the slot
u16 dropcount = item->getDropCount();
// Delete item if all gone
if(item->getCount() <= dropcount)
{
if (item->getCount() <= dropcount) {
if(item->getCount() < dropcount)
infostream<<"WARNING: Server: dropped more items"
<<" than the slot contains"<<std::endl;
@ -4166,8 +4162,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
ilist->deleteItem(item_i);
}
// Else decrement it
else
else{
item->remove(dropcount);
}
// Send inventory
UpdateCrafting(peer_id);
@ -4214,13 +4211,6 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
else if(command == TOSERVER_INVENTORY_ACTION)
{
/*// Ignore inventory changes if in creative mode
if(g_settings->getBool("creative_mode") == true)
{
infostream<<"TOSERVER_INVENTORY_ACTION: ignoring in creative mode"
<<std::endl;
return;
}*/
// Strip command and create a stream
std::string datastring((char*)&data[2], datasize-2);
infostream<<"TOSERVER_INVENTORY_ACTION: data="<<datastring<<std::endl;
@ -4237,7 +4227,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
Handle craftresult specially if not in creative mode
*/
bool disable_action = false;
if (a->getType() == IACTION_MOVE && g_settings->getBool("creative_mode") == false) {
if (a->getType() == IACTION_MOVE && g_settings->getBool("infinite_inventory") == false) {
IMoveAction *ma = (IMoveAction*)a;
if(ma->to_inv == "current_player" && ma->from_inv == "current_player") {
InventoryList *rlist = player->inventory.getList("craftresult");
@ -4358,15 +4348,19 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
) {
InventoryList *list = player->inventory.getList("discard");
InventoryItem *item = list->getItem(0);
v3f pos = player->getPosition();
pos.Y += BS;
v3f dir = v3f(0,0,BS);
dir.rotateXZBy(player->getYaw());
pos += dir;
ServerActiveObject *obj = item->createSAO(&m_env,0,pos);
m_env.addActiveObject(obj);
list->deleteItem(0);
SendInventory(player->peer_id);
if (g_settings->getBool("droppable_inventory")) {
v3f pos = player->getPosition();
pos.Y += BS;
v3f dir = v3f(0,0,BS);
dir.rotateXZBy(player->getYaw());
pos += dir;
ServerActiveObject *obj = item->createSAO(&m_env,0,pos);
m_env.addActiveObject(obj);
}
if (g_settings->getBool("infinite_inventory") == false) {
list->deleteItem(0);
SendInventory(player->peer_id);
}
}
}
// Eat the action
@ -5409,8 +5403,7 @@ void Server::UpdateCrafting(u16 peer_id)
/*
Calculate crafting stuff
*/
if(g_settings->getBool("creative_mode") == false)
{
if (g_settings->getBool("infinite_inventory") == false) {
InventoryList *clist = player->inventory.getList("craft");
InventoryList *rlist = player->inventory.getList("craftresult");
@ -5435,7 +5428,7 @@ void Server::UpdateCrafting(u16 peer_id)
rlist->addItem(result);
}
} // if creative_mode == false
}
}
RemoteClient* Server::getClient(u16 peer_id)
@ -5583,8 +5576,7 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
player->peer_id = peer_id;
// Reset inventory to creative if in creative mode
if(g_settings->getBool("creative_mode"))
{
if (g_settings->getBool("infinite_inventory")) {
// Warning: double code below
// Backup actual inventory
player->inventory_backup = new Inventory();
@ -5641,17 +5633,14 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
Add stuff to inventory
*/
if(g_settings->getBool("creative_mode"))
{
if (g_settings->getBool("infinite_inventory")) {
// Warning: double code above
// Backup actual inventory
player->inventory_backup = new Inventory();
*(player->inventory_backup) = player->inventory;
// Set creative inventory
crafting::giveCreative(player);
}
else if(g_settings->getBool("give_initial_stuff"))
{
}else if(g_settings->getBool("initial_inventory")) {
crafting::giveInitial(player);
}

View File

@ -83,8 +83,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Settings.
These are loaded from the config file.
*/
Settings main_settings;
Settings *g_settings = &main_settings;
GameSettings main_settings;
GameSettings *g_settings = &main_settings;
// Global profiler
Profiler main_profiler;

View File

@ -656,5 +656,31 @@ private:
JMutex m_mutex;
};
class GameSettings : public Settings
{
public:
GameSettings()
{
Settings();
}
// you'll find this in defaultsettings.cpp
void setGameDefaults(std::string mode);
void set(std::string name, std::string value)
{
Settings::set(name,value);
if (name == "game_mode")
setGameDefaults(value);
}
void set(std::string name, const char *value)
{
Settings::set(name,value);
if (name == "game_mode")
setGameDefaults(value);
}
};
#endif

View File

@ -1,21 +1,14 @@
# This file is read by default from:
# ../minetest.conf
# ../../minetest.conf
# ../voxelands.conf
# ../../voxelands.conf
# Any other path can be chosen by passing the path as a parameter
# to the program, eg. "minetest.exe --config ../minetest.conf.example"
# to the program, eg. "voxelands.exe --config ../voxelands.conf.example"
#
# By default, all the settings are commented and not functional.
# Uncomment settings by removing the preceding #.
#
# Further documentation:
# http://celeron.55.lt/~celeron55/minetest/wiki/doku.php
#
# NOTE: This file might not be up-to-date, refer to the
# defaultsettings.cpp file for an up-to-date list:
# https://bitbucket.org/celeron55/minetest/src/tip/src/defaultsettings.cpp
#
# A vim command to convert most of defaultsettings.cpp to conf file format:
# :'<,'>s/\tg_settings\.setDefault("\([^"]*\)", "\([^"]*\)");.*/#\1 = \2/g
# http://wiki.voxelands.com/doku.php?id=settings
#
# Client and server
@ -131,25 +124,66 @@
# Server stuff
#
# The game mode, creative/adventure/survival
# this will preset the below settings to some defaults for the mode
# but those defaults can be overridden here
#game_mode = adventure
# Enable players getting damage and dying
# creative
#enable_damage = false
# adventure
#enable_damage = true
# survival
#enable_damage = true
# The maximum 'level' of mobs to spawn: passive, aggressive, destructive
# roughly: passive = rats, aggressive = oerkki, destructive = DM
# creative
#max_mob_level = passive
# adventure
#max_mob_level = aggressive
# survival
#max_mob_level = aggressive
# Gives some stuff to players at the beginning
# creative - setting is unused if infinite_inventory = true
#initial_inventory = false
# adventure
#initial_inventory = true
# survival
#initial_inventory = false
# The creative style inventory
# - dug items aren't added, placed items aren't removed
# creative
#infinite_inventory = true
# adventure
#infinite_inventory = false
# survival
#infinite_inventory = false
# Whether items can be dropped on the ground
# creative
#droppable_inventory = false
# adventure
#droppable_inventory = true
# survival
#droppable_inventory = true
# Whether tools wear out from use
# creative
#tool_wear = false
# adventure
#tool_wear = true
# survival
#tool_wear = true
# Map directory (everything in the world is stored here)
#map-dir = /custom/map
# Message of the Day
#motd = Welcome to this awesome Minetest server!
#motd = Welcome to this awesome Voxelands server!
# Maximum number of players connected simultaneously
#max_users = 20
# Set to true to prevent old clients connecting
#strict_protocol_version_checking = false
# Set to true to enable creative mode (unlimited inventory)
#creative_mode = false
# Enable players getting damage and dying
#enable_damage = false
# The maximum 'level' of mobs to spawn: passive, aggressive, destructive
# roughly: passive = rats, aggressive = oerkki, destructive = DM
#max_mob_level = aggressive
# A chosen map seed for a new map, leave empty for random
#fixed_map_seed =
# Gives some stuff to players at the beginning
#give_initial_stuff = true
# New users need to input this password
#default_password =
# Don't let players join with an empty password