forked from Mirrorlandia_minetest/minetest
Modernize various files (part 2)
* range-based for loops * emplace_back instead of push_back * code style * C++ headers instead of C headers * Default operators * empty stl function
This commit is contained in:
parent
55ab4264dc
commit
1d086aee7c
@ -46,5 +46,5 @@ video::ITexture *guiScalingImageButton(video::IVideoDriver *driver, video::IText
|
|||||||
*/
|
*/
|
||||||
void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
|
void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
|
||||||
const core::rect<s32> &destrect, const core::rect<s32> &srcrect,
|
const core::rect<s32> &destrect, const core::rect<s32> &srcrect,
|
||||||
const core::rect<s32> *cliprect = 0, video::SColor *const colors = 0,
|
const core::rect<s32> *cliprect = 0, const video::SColor *const colors = 0,
|
||||||
bool usealpha = false);
|
bool usealpha = false);
|
||||||
|
@ -76,7 +76,7 @@ struct HTTPFetchResult
|
|||||||
unsigned long caller = HTTPFETCH_DISCARD;
|
unsigned long caller = HTTPFETCH_DISCARD;
|
||||||
unsigned long request_id = 0;
|
unsigned long request_id = 0;
|
||||||
|
|
||||||
HTTPFetchResult() {}
|
HTTPFetchResult() = default;
|
||||||
|
|
||||||
HTTPFetchResult(const HTTPFetchRequest &fetch_request)
|
HTTPFetchResult(const HTTPFetchRequest &fetch_request)
|
||||||
: caller(fetch_request.caller), request_id(fetch_request.request_id)
|
: caller(fetch_request.caller), request_id(fetch_request.request_id)
|
||||||
|
16
src/hud.cpp
16
src/hud.cpp
@ -55,8 +55,8 @@ Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
|
|||||||
m_hotbar_imagesize *= m_hud_scaling;
|
m_hotbar_imagesize *= m_hud_scaling;
|
||||||
m_padding = m_hotbar_imagesize / 12;
|
m_padding = m_hotbar_imagesize / 12;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 4; i++)
|
for (auto &hbar_color : hbar_colors)
|
||||||
hbar_colors[i] = video::SColor(255, 255, 255, 255);
|
hbar_color = video::SColor(255, 255, 255, 255);
|
||||||
|
|
||||||
tsrc = client->getTextureSource();
|
tsrc = client->getTextureSource();
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
|
|||||||
// Store hotbar_image in member variable, used by drawItem()
|
// Store hotbar_image in member variable, used by drawItem()
|
||||||
if (hotbar_image != player->hotbar_image) {
|
if (hotbar_image != player->hotbar_image) {
|
||||||
hotbar_image = player->hotbar_image;
|
hotbar_image = player->hotbar_image;
|
||||||
if (hotbar_image != "")
|
if (!hotbar_image.empty())
|
||||||
use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image);
|
use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image);
|
||||||
else
|
else
|
||||||
use_hotbar_image = false;
|
use_hotbar_image = false;
|
||||||
@ -229,7 +229,7 @@ void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
|
|||||||
// Store hotbar_selected_image in member variable, used by drawItem()
|
// Store hotbar_selected_image in member variable, used by drawItem()
|
||||||
if (hotbar_selected_image != player->hotbar_selected_image) {
|
if (hotbar_selected_image != player->hotbar_selected_image) {
|
||||||
hotbar_selected_image = player->hotbar_selected_image;
|
hotbar_selected_image = player->hotbar_selected_image;
|
||||||
if (hotbar_selected_image != "")
|
if (!hotbar_selected_image.empty())
|
||||||
use_hotbar_selected_image = tsrc->isKnownSourceImage(hotbar_selected_image);
|
use_hotbar_selected_image = tsrc->isKnownSourceImage(hotbar_selected_image);
|
||||||
else
|
else
|
||||||
use_hotbar_selected_image = false;
|
use_hotbar_selected_image = false;
|
||||||
@ -572,7 +572,7 @@ void Hud::updateSelectionMesh(const v3s16 &camera_offset)
|
|||||||
m_selection_mesh = NULL;
|
m_selection_mesh = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_selection_boxes.size()) {
|
if (m_selection_boxes.empty()) {
|
||||||
// No pointed object
|
// No pointed object
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -597,10 +597,8 @@ void Hud::updateSelectionMesh(const v3s16 &camera_offset)
|
|||||||
aabb3f halo_box(100.0, 100.0, 100.0, -100.0, -100.0, -100.0);
|
aabb3f halo_box(100.0, 100.0, 100.0, -100.0, -100.0, -100.0);
|
||||||
m_halo_boxes.clear();
|
m_halo_boxes.clear();
|
||||||
|
|
||||||
for (std::vector<aabb3f>::iterator
|
for (const auto &selection_box : m_selection_boxes) {
|
||||||
i = m_selection_boxes.begin();
|
halo_box.addInternalBox(selection_box);
|
||||||
i != m_selection_boxes.end(); ++i) {
|
|
||||||
halo_box.addInternalBox(*i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_halo_boxes.push_back(halo_box);
|
m_halo_boxes.push_back(halo_box);
|
||||||
|
@ -18,7 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "imagefilters.h"
|
#include "imagefilters.h"
|
||||||
#include "util/numeric.h"
|
#include "util/numeric.h"
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
|
|
||||||
/* Fill in RGB values for transparent pixels, to correct for odd colors
|
/* Fill in RGB values for transparent pixels, to correct for odd colors
|
||||||
* appearing at borders when blending. This is because many PNG optimizers
|
* appearing at borders when blending. This is because many PNG optimizers
|
||||||
|
@ -630,8 +630,7 @@ bool intlGUIEditBox::processKey(const SEvent& event)
|
|||||||
if ( !this->IsEnabled )
|
if ( !this->IsEnabled )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (Text.size())
|
if (!Text.empty()) {
|
||||||
{
|
|
||||||
core::stringw s;
|
core::stringw s;
|
||||||
|
|
||||||
if (MarkBegin != MarkEnd)
|
if (MarkBegin != MarkEnd)
|
||||||
@ -670,8 +669,7 @@ bool intlGUIEditBox::processKey(const SEvent& event)
|
|||||||
if ( !this->IsEnabled )
|
if ( !this->IsEnabled )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (Text.size() != 0)
|
if (!Text.empty()) {
|
||||||
{
|
|
||||||
core::stringw s;
|
core::stringw s;
|
||||||
|
|
||||||
if (MarkBegin != MarkEnd)
|
if (MarkBegin != MarkEnd)
|
||||||
@ -820,8 +818,7 @@ void intlGUIEditBox::draw()
|
|||||||
const bool prevOver = OverrideColorEnabled;
|
const bool prevOver = OverrideColorEnabled;
|
||||||
const video::SColor prevColor = OverrideColor;
|
const video::SColor prevColor = OverrideColor;
|
||||||
|
|
||||||
if (Text.size())
|
if (!Text.empty()) {
|
||||||
{
|
|
||||||
if (!IsEnabled && !OverrideColorEnabled)
|
if (!IsEnabled && !OverrideColorEnabled)
|
||||||
{
|
{
|
||||||
OverrideColorEnabled = true;
|
OverrideColorEnabled = true;
|
||||||
@ -908,7 +905,7 @@ void intlGUIEditBox::draw()
|
|||||||
// draw marked text
|
// draw marked text
|
||||||
s = txtLine->subString(lineStartPos, lineEndPos - lineStartPos);
|
s = txtLine->subString(lineStartPos, lineEndPos - lineStartPos);
|
||||||
|
|
||||||
if (s.size())
|
if (!s.empty())
|
||||||
font->draw(s.c_str(), CurrentTextRect,
|
font->draw(s.c_str(), CurrentTextRect,
|
||||||
OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
|
OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
|
||||||
false, true, &localClipRect);
|
false, true, &localClipRect);
|
||||||
@ -1057,12 +1054,11 @@ bool intlGUIEditBox::processMouse(const SEvent& event)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!AbsoluteClippingRect.isPointInside(
|
if (!AbsoluteClippingRect.isPointInside(
|
||||||
core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y)))
|
core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y))) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// move cursor
|
// move cursor
|
||||||
CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y);
|
CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y);
|
||||||
|
|
||||||
@ -1075,7 +1071,6 @@ bool intlGUIEditBox::processMouse(const SEvent& event)
|
|||||||
calculateScrollPos();
|
calculateScrollPos();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1185,8 +1180,7 @@ void intlGUIEditBox::breakText()
|
|||||||
|
|
||||||
if (c == L' ' || c == 0 || i == (size-1))
|
if (c == L' ' || c == 0 || i == (size-1))
|
||||||
{
|
{
|
||||||
if (word.size())
|
if (!word.empty()) {
|
||||||
{
|
|
||||||
// here comes the next whitespace, look if
|
// here comes the next whitespace, look if
|
||||||
// we can break the last word to the next line.
|
// we can break the last word to the next line.
|
||||||
s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
|
s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
|
||||||
@ -1488,7 +1482,7 @@ void intlGUIEditBox::deserializeAttributes(io::IAttributes* in, io::SAttributeRe
|
|||||||
setAutoScroll(in->getAttributeAsBool("AutoScroll"));
|
setAutoScroll(in->getAttributeAsBool("AutoScroll"));
|
||||||
core::stringw ch = in->getAttributeAsStringW("PasswordChar");
|
core::stringw ch = in->getAttributeAsStringW("PasswordChar");
|
||||||
|
|
||||||
if (!ch.size())
|
if (ch.empty())
|
||||||
setPasswordBox(in->getAttributeAsBool("PasswordBox"));
|
setPasswordBox(in->getAttributeAsBool("PasswordBox"));
|
||||||
else
|
else
|
||||||
setPasswordBox(in->getAttributeAsBool("PasswordBox"), ch[0]);
|
setPasswordBox(in->getAttributeAsBool("PasswordBox"), ch[0]);
|
||||||
|
@ -35,11 +35,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
static content_t content_translate_from_19_to_internal(content_t c_from)
|
static content_t content_translate_from_19_to_internal(content_t c_from)
|
||||||
{
|
{
|
||||||
for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
|
for (const auto &tt : trans_table_19) {
|
||||||
{
|
if(tt[1] == c_from) {
|
||||||
if(trans_table_19[i][1] == c_from)
|
return tt[0];
|
||||||
{
|
|
||||||
return trans_table_19[i][0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c_from;
|
return c_from;
|
||||||
@ -116,7 +114,7 @@ void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef)
|
|||||||
NameIdMapping legacy_nimap;
|
NameIdMapping legacy_nimap;
|
||||||
content_mapnode_get_name_id_mapping(&legacy_nimap);
|
content_mapnode_get_name_id_mapping(&legacy_nimap);
|
||||||
legacy_nimap.getName(material, name);
|
legacy_nimap.getName(material, name);
|
||||||
if(name == "")
|
if(name.empty())
|
||||||
name = "unknown_block";
|
name = "unknown_block";
|
||||||
if (itemdef)
|
if (itemdef)
|
||||||
name = itemdef->getAlias(name);
|
name = itemdef->getAlias(name);
|
||||||
@ -136,7 +134,7 @@ void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef)
|
|||||||
NameIdMapping legacy_nimap;
|
NameIdMapping legacy_nimap;
|
||||||
content_mapnode_get_name_id_mapping(&legacy_nimap);
|
content_mapnode_get_name_id_mapping(&legacy_nimap);
|
||||||
legacy_nimap.getName(material, name);
|
legacy_nimap.getName(material, name);
|
||||||
if(name == "")
|
if(name.empty())
|
||||||
name = "unknown_block";
|
name = "unknown_block";
|
||||||
if (itemdef)
|
if (itemdef)
|
||||||
name = itemdef->getAlias(name);
|
name = itemdef->getAlias(name);
|
||||||
@ -207,12 +205,11 @@ void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef)
|
|||||||
// Read the count
|
// Read the count
|
||||||
std::string count_str;
|
std::string count_str;
|
||||||
std::getline(is, count_str, ' ');
|
std::getline(is, count_str, ' ');
|
||||||
if(count_str.empty())
|
if (count_str.empty()) {
|
||||||
{
|
|
||||||
count = 1;
|
count = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
count = stoi(count_str);
|
count = stoi(count_str);
|
||||||
|
|
||||||
// Read the wear
|
// Read the wear
|
||||||
@ -220,7 +217,7 @@ void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef)
|
|||||||
std::getline(is, wear_str, ' ');
|
std::getline(is, wear_str, ' ');
|
||||||
if(wear_str.empty())
|
if(wear_str.empty())
|
||||||
break;
|
break;
|
||||||
else
|
|
||||||
wear = stoi(wear_str);
|
wear = stoi(wear_str);
|
||||||
|
|
||||||
// Read metadata
|
// Read metadata
|
||||||
@ -388,17 +385,12 @@ InventoryList::InventoryList(const std::string &name, u32 size, IItemDefManager
|
|||||||
clearItems();
|
clearItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryList::~InventoryList()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void InventoryList::clearItems()
|
void InventoryList::clearItems()
|
||||||
{
|
{
|
||||||
m_items.clear();
|
m_items.clear();
|
||||||
|
|
||||||
for(u32 i=0; i<m_size; i++)
|
for (u32 i=0; i < m_size; i++) {
|
||||||
{
|
m_items.emplace_back();
|
||||||
m_items.push_back(ItemStack());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//setDirty(true);
|
//setDirty(true);
|
||||||
@ -427,15 +419,10 @@ void InventoryList::serialize(std::ostream &os) const
|
|||||||
|
|
||||||
os<<"Width "<<m_width<<"\n";
|
os<<"Width "<<m_width<<"\n";
|
||||||
|
|
||||||
for(u32 i=0; i<m_items.size(); i++)
|
for (const auto &item : m_items) {
|
||||||
{
|
if (item.empty()) {
|
||||||
const ItemStack &item = m_items[i];
|
|
||||||
if(item.empty())
|
|
||||||
{
|
|
||||||
os<<"Empty";
|
os<<"Empty";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
os<<"Item ";
|
os<<"Item ";
|
||||||
item.serialize(os);
|
item.serialize(os);
|
||||||
}
|
}
|
||||||
@ -464,17 +451,16 @@ void InventoryList::deSerialize(std::istream &is)
|
|||||||
std::string name;
|
std::string name;
|
||||||
std::getline(iss, name, ' ');
|
std::getline(iss, name, ' ');
|
||||||
|
|
||||||
if(name == "EndInventoryList")
|
if (name == "EndInventoryList") {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a temporary backwards compatibility fix
|
// This is a temporary backwards compatibility fix
|
||||||
else if(name == "end")
|
if (name == "end") {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(name == "Width")
|
|
||||||
{
|
if (name == "Width") {
|
||||||
iss >> m_width;
|
iss >> m_width;
|
||||||
if (iss.fail())
|
if (iss.fail())
|
||||||
throw SerializationError("incorrect width property");
|
throw SerializationError("incorrect width property");
|
||||||
@ -551,9 +537,8 @@ u32 InventoryList::getWidth() const
|
|||||||
u32 InventoryList::getUsedSlots() const
|
u32 InventoryList::getUsedSlots() const
|
||||||
{
|
{
|
||||||
u32 num = 0;
|
u32 num = 0;
|
||||||
for(u32 i=0; i<m_items.size(); i++)
|
for (const auto &m_item : m_items) {
|
||||||
{
|
if (!m_item.empty())
|
||||||
if(!m_items[i].empty())
|
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
return num;
|
return num;
|
||||||
@ -672,19 +657,16 @@ bool InventoryList::roomForItem(const ItemStack &item_) const
|
|||||||
bool InventoryList::containsItem(const ItemStack &item, bool match_meta) const
|
bool InventoryList::containsItem(const ItemStack &item, bool match_meta) const
|
||||||
{
|
{
|
||||||
u32 count = item.count;
|
u32 count = item.count;
|
||||||
if(count == 0)
|
if (count == 0)
|
||||||
return true;
|
return true;
|
||||||
for(std::vector<ItemStack>::const_reverse_iterator
|
|
||||||
i = m_items.rbegin();
|
for (auto i = m_items.rbegin(); i != m_items.rend(); ++i) {
|
||||||
i != m_items.rend(); ++i)
|
if (count == 0)
|
||||||
{
|
|
||||||
if(count == 0)
|
|
||||||
break;
|
break;
|
||||||
if (i->name == item.name
|
if (i->name == item.name && (!match_meta || (i->metadata == item.metadata))) {
|
||||||
&& (!match_meta || (i->metadata == item.metadata))) {
|
|
||||||
if (i->count >= count)
|
if (i->count >= count)
|
||||||
return true;
|
return true;
|
||||||
else
|
|
||||||
count -= i->count;
|
count -= i->count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -694,15 +676,11 @@ bool InventoryList::containsItem(const ItemStack &item, bool match_meta) const
|
|||||||
ItemStack InventoryList::removeItem(const ItemStack &item)
|
ItemStack InventoryList::removeItem(const ItemStack &item)
|
||||||
{
|
{
|
||||||
ItemStack removed;
|
ItemStack removed;
|
||||||
for(std::vector<ItemStack>::reverse_iterator
|
for (auto i = m_items.rbegin(); i != m_items.rend(); ++i) {
|
||||||
i = m_items.rbegin();
|
if (i->name == item.name) {
|
||||||
i != m_items.rend(); ++i)
|
|
||||||
{
|
|
||||||
if(i->name == item.name)
|
|
||||||
{
|
|
||||||
u32 still_to_remove = item.count - removed.count;
|
u32 still_to_remove = item.count - removed.count;
|
||||||
removed.addItem(i->takeItem(still_to_remove), m_itemdef);
|
removed.addItem(i->takeItem(still_to_remove), m_itemdef);
|
||||||
if(removed.count == item.count)
|
if (removed.count == item.count)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -815,9 +793,8 @@ Inventory::~Inventory()
|
|||||||
void Inventory::clear()
|
void Inventory::clear()
|
||||||
{
|
{
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
for(u32 i=0; i<m_lists.size(); i++)
|
for (auto &m_list : m_lists) {
|
||||||
{
|
delete m_list;
|
||||||
delete m_lists[i];
|
|
||||||
}
|
}
|
||||||
m_lists.clear();
|
m_lists.clear();
|
||||||
}
|
}
|
||||||
@ -825,11 +802,8 @@ void Inventory::clear()
|
|||||||
void Inventory::clearContents()
|
void Inventory::clearContents()
|
||||||
{
|
{
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
for(u32 i=0; i<m_lists.size(); i++)
|
for (InventoryList *list : m_lists) {
|
||||||
{
|
for (u32 j=0; j<list->getSize(); j++) {
|
||||||
InventoryList *list = m_lists[i];
|
|
||||||
for(u32 j=0; j<list->getSize(); j++)
|
|
||||||
{
|
|
||||||
list->deleteItem(j);
|
list->deleteItem(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -855,9 +829,8 @@ Inventory & Inventory::operator = (const Inventory &other)
|
|||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
clear();
|
clear();
|
||||||
m_itemdef = other.m_itemdef;
|
m_itemdef = other.m_itemdef;
|
||||||
for(u32 i=0; i<other.m_lists.size(); i++)
|
for (InventoryList *list : other.m_lists) {
|
||||||
{
|
m_lists.push_back(new InventoryList(*list));
|
||||||
m_lists.push_back(new InventoryList(*other.m_lists[i]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@ -878,9 +851,7 @@ bool Inventory::operator == (const Inventory &other) const
|
|||||||
|
|
||||||
void Inventory::serialize(std::ostream &os) const
|
void Inventory::serialize(std::ostream &os) const
|
||||||
{
|
{
|
||||||
for(u32 i=0; i<m_lists.size(); i++)
|
for (InventoryList *list : m_lists) {
|
||||||
{
|
|
||||||
InventoryList *list = m_lists[i];
|
|
||||||
os<<"List "<<list->getName()<<" "<<list->getSize()<<"\n";
|
os<<"List "<<list->getName()<<" "<<list->getSize()<<"\n";
|
||||||
list->serialize(os);
|
list->serialize(os);
|
||||||
}
|
}
|
||||||
@ -902,17 +873,16 @@ void Inventory::deSerialize(std::istream &is)
|
|||||||
std::string name;
|
std::string name;
|
||||||
std::getline(iss, name, ' ');
|
std::getline(iss, name, ' ');
|
||||||
|
|
||||||
if(name == "EndInventory")
|
if (name == "EndInventory") {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a temporary backwards compatibility fix
|
// This is a temporary backwards compatibility fix
|
||||||
else if(name == "end")
|
if (name == "end") {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(name == "List")
|
|
||||||
{
|
if (name == "List") {
|
||||||
std::string listname;
|
std::string listname;
|
||||||
u32 listsize;
|
u32 listsize;
|
||||||
|
|
||||||
@ -944,15 +914,14 @@ InventoryList * Inventory::addList(const std::string &name, u32 size)
|
|||||||
}
|
}
|
||||||
return m_lists[i];
|
return m_lists[i];
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
//don't create list with invalid name
|
//don't create list with invalid name
|
||||||
if (name.find(" ") != std::string::npos) return NULL;
|
if (name.find(' ') != std::string::npos) return NULL;
|
||||||
|
|
||||||
InventoryList *list = new InventoryList(name, size, m_itemdef);
|
InventoryList *list = new InventoryList(name, size, m_itemdef);
|
||||||
m_lists.push_back(list);
|
m_lists.push_back(list);
|
||||||
return list;
|
return list;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryList * Inventory::getList(const std::string &name)
|
InventoryList * Inventory::getList(const std::string &name)
|
||||||
@ -966,9 +935,7 @@ InventoryList * Inventory::getList(const std::string &name)
|
|||||||
std::vector<const InventoryList*> Inventory::getLists()
|
std::vector<const InventoryList*> Inventory::getLists()
|
||||||
{
|
{
|
||||||
std::vector<const InventoryList*> lists;
|
std::vector<const InventoryList*> lists;
|
||||||
for(u32 i=0; i<m_lists.size(); i++)
|
for (auto list : m_lists) {
|
||||||
{
|
|
||||||
InventoryList *list = m_lists[i];
|
|
||||||
lists.push_back(list);
|
lists.push_back(list);
|
||||||
}
|
}
|
||||||
return lists;
|
return lists;
|
||||||
|
@ -172,7 +172,7 @@ class InventoryList
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InventoryList(const std::string &name, u32 size, IItemDefManager *itemdef);
|
InventoryList(const std::string &name, u32 size, IItemDefManager *itemdef);
|
||||||
~InventoryList();
|
~InventoryList() = default;
|
||||||
void clearItems();
|
void clearItems();
|
||||||
void setSize(u32 newsize);
|
void setSize(u32 newsize);
|
||||||
void setWidth(u32 newWidth);
|
void setWidth(u32 newWidth);
|
||||||
|
@ -774,17 +774,15 @@ void ICraftAction::apply(InventoryManager *mgr,
|
|||||||
|
|
||||||
// Add the new replacements to the list
|
// Add the new replacements to the list
|
||||||
IItemDefManager *itemdef = gamedef->getItemDefManager();
|
IItemDefManager *itemdef = gamedef->getItemDefManager();
|
||||||
for (std::vector<ItemStack>::iterator it = temp.begin();
|
for (auto &itemstack : temp) {
|
||||||
it != temp.end(); ++it) {
|
for (auto &output_replacement : output_replacements) {
|
||||||
for (std::vector<ItemStack>::iterator jt = output_replacements.begin();
|
if (itemstack.name == output_replacement.name) {
|
||||||
jt != output_replacements.end(); ++jt) {
|
itemstack = output_replacement.addItem(itemstack, itemdef);
|
||||||
if (it->name == jt->name) {
|
if (itemstack.empty())
|
||||||
*it = jt->addItem(*it, itemdef);
|
|
||||||
if (it->empty())
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output_replacements.push_back(*it);
|
output_replacements.push_back(itemstack);
|
||||||
}
|
}
|
||||||
|
|
||||||
actionstream << player->getDescription()
|
actionstream << player->getDescription()
|
||||||
@ -795,7 +793,8 @@ void ICraftAction::apply(InventoryManager *mgr,
|
|||||||
// Decrement counter
|
// Decrement counter
|
||||||
if (count_remaining == 1)
|
if (count_remaining == 1)
|
||||||
break;
|
break;
|
||||||
else if (count_remaining > 1)
|
|
||||||
|
if (count_remaining > 1)
|
||||||
count_remaining--;
|
count_remaining--;
|
||||||
|
|
||||||
// Get next crafting result
|
// Get next crafting result
|
||||||
@ -806,24 +805,23 @@ void ICraftAction::apply(InventoryManager *mgr,
|
|||||||
|
|
||||||
// Put the replacements in the inventory or drop them on the floor, if
|
// Put the replacements in the inventory or drop them on the floor, if
|
||||||
// the invenotry is full
|
// the invenotry is full
|
||||||
for (std::vector<ItemStack>::iterator it = output_replacements.begin();
|
for (auto &output_replacement : output_replacements) {
|
||||||
it != output_replacements.end(); ++it) {
|
|
||||||
if (list_main)
|
if (list_main)
|
||||||
*it = list_main->addItem(*it);
|
output_replacement = list_main->addItem(output_replacement);
|
||||||
if (it->empty())
|
if (output_replacement.empty())
|
||||||
continue;
|
continue;
|
||||||
u16 count = it->count;
|
u16 count = output_replacement.count;
|
||||||
do {
|
do {
|
||||||
PLAYER_TO_SA(player)->item_OnDrop(*it, player,
|
PLAYER_TO_SA(player)->item_OnDrop(output_replacement, player,
|
||||||
player->getBasePosition());
|
player->getBasePosition());
|
||||||
if (count >= it->count) {
|
if (count >= output_replacement.count) {
|
||||||
errorstream << "Couldn't drop replacement stack " <<
|
errorstream << "Couldn't drop replacement stack " <<
|
||||||
it->getItemString() << " because drop loop didn't "
|
output_replacement.getItemString() << " because drop loop didn't "
|
||||||
"decrease count." << std::endl;
|
"decrease count." << std::endl;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (!it->empty());
|
} while (!output_replacement.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
infostream<<"ICraftAction::apply(): crafted "
|
infostream<<"ICraftAction::apply(): crafted "
|
||||||
|
@ -54,7 +54,7 @@ struct InventoryLocation
|
|||||||
type = PLAYER;
|
type = PLAYER;
|
||||||
name = name_;
|
name = name_;
|
||||||
}
|
}
|
||||||
void setNodeMeta(v3s16 p_)
|
void setNodeMeta(const v3s16 &p_)
|
||||||
{
|
{
|
||||||
type = NODEMETA;
|
type = NODEMETA;
|
||||||
p = p_;
|
p = p_;
|
||||||
@ -105,8 +105,8 @@ struct InventoryAction;
|
|||||||
class InventoryManager
|
class InventoryManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InventoryManager(){}
|
InventoryManager() = default;
|
||||||
virtual ~InventoryManager(){}
|
virtual ~InventoryManager() = default;
|
||||||
|
|
||||||
// Get an inventory (server and client)
|
// Get an inventory (server and client)
|
||||||
virtual Inventory* getInventory(const InventoryLocation &loc){return NULL;}
|
virtual Inventory* getInventory(const InventoryLocation &loc){return NULL;}
|
||||||
@ -131,7 +131,7 @@ struct InventoryAction
|
|||||||
virtual void apply(InventoryManager *mgr, ServerActiveObject *player,
|
virtual void apply(InventoryManager *mgr, ServerActiveObject *player,
|
||||||
IGameDef *gamedef) = 0;
|
IGameDef *gamedef) = 0;
|
||||||
virtual void clientApply(InventoryManager *mgr, IGameDef *gamedef) = 0;
|
virtual void clientApply(InventoryManager *mgr, IGameDef *gamedef) = 0;
|
||||||
virtual ~InventoryAction() {};
|
virtual ~InventoryAction() = default;;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IMoveAction : public InventoryAction
|
struct IMoveAction : public InventoryAction
|
||||||
@ -151,7 +151,7 @@ struct IMoveAction : public InventoryAction
|
|||||||
bool caused_by_move_somewhere = false;
|
bool caused_by_move_somewhere = false;
|
||||||
u32 move_count = 0;
|
u32 move_count = 0;
|
||||||
|
|
||||||
IMoveAction() {}
|
IMoveAction() = default;
|
||||||
|
|
||||||
IMoveAction(std::istream &is, bool somewhere);
|
IMoveAction(std::istream &is, bool somewhere);
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ struct IDropAction : public InventoryAction
|
|||||||
std::string from_list;
|
std::string from_list;
|
||||||
s16 from_i = -1;
|
s16 from_i = -1;
|
||||||
|
|
||||||
IDropAction() {}
|
IDropAction() = default;
|
||||||
|
|
||||||
IDropAction(std::istream &is);
|
IDropAction(std::istream &is);
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ struct ICraftAction : public InventoryAction
|
|||||||
u16 count = 0;
|
u16 count = 0;
|
||||||
InventoryLocation craft_inv;
|
InventoryLocation craft_inv;
|
||||||
|
|
||||||
ICraftAction() {}
|
ICraftAction() = default;
|
||||||
|
|
||||||
ICraftAction(std::istream &is);
|
ICraftAction(std::istream &is);
|
||||||
|
|
||||||
|
@ -13,11 +13,9 @@ void ItemStackMetadata::serialize(std::ostream &os) const
|
|||||||
{
|
{
|
||||||
std::ostringstream os2;
|
std::ostringstream os2;
|
||||||
os2 << DESERIALIZE_START;
|
os2 << DESERIALIZE_START;
|
||||||
for (StringMap::const_iterator
|
for (const auto &stringvar : m_stringvars) {
|
||||||
it = m_stringvars.begin();
|
os2 << stringvar.first << DESERIALIZE_KV_DELIM
|
||||||
it != m_stringvars.end(); ++it) {
|
<< stringvar.second << DESERIALIZE_PAIR_DELIM;
|
||||||
os2 << it->first << DESERIALIZE_KV_DELIM
|
|
||||||
<< it->second << DESERIALIZE_PAIR_DELIM;
|
|
||||||
}
|
}
|
||||||
os << serializeJsonStringIfNeeded(os2.str());
|
os << serializeJsonStringIfNeeded(os2.str());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user