1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "object_properties.h"
#include "irrlichttypes_bloated.h"
#include "exce/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "content_nodemeta.h"
#include "nodemetadata.h"
#include "nodetimer.h"
#include "inventory.h"
#include "log.h"
#include "serialization.h"
#include "util/serialize.h"
#include "util/string.h"
visual_size(1,1),
spritediv(1,1),
initial_sprite_basepos(0,0),
is_visible(true),
makes_footstep_sound(false),
automatic_rotate(0),
stepheight(0),
automatic_face_movement_dir(false),
automatic_face_movement_dir_offset(0.0)
{
textures.push_back("unknown_object.png");
colors.push_back(video::SColor(255,255,255,255));
}
std::string ObjectProperties::dump()
{
std::ostringstream os(std::ios::binary);
os<<"hp_max="<<hp_max;
os<<", physical="<<physical;
os<<", collideWithObjects="<<collideWithObjects;
os<<", weight="<<weightstd::string name = deSerializeString(is);
std::string var = deSerializeLongString(is);
meta->setString(name, var);
}
return false;
}
else if(id == NODEMETA_SIGN) // SignNodeMetadata
{
meta->setString("text", deSerializeString(is));
//meta->setString("infotext","\"${text}\"");
meta->setString("infotext",
std::string("\"") + meta->getString("text") + "\"");
meta->setString("formspec","field[text;;${text}]");
return false;
}
else if(id == NODEMETA_CHEST) // ChestNodeMetadata
{
meta->getInventory()->deSerialize(is);
// Rename inventory list "0" to "main"
Inventory *inv = meta->getInventory();
if(!inv->getList("main") && inv->getList("0")){
inv->getList("0")->setName("main");
}
assert(inv->getList("main") && !inv->getList("0"));
meta->setString("formspec","size[8,9]"
"list[current_name;main;0,0;8,4;]"
"list[current_player;main;0,5;8,4;]");
return false;
}
else if(id == NODEMETA_LOCKABLE_CHEST) // LockingChestNodeMetadata
{
meta->setString("owner", deSerializeString(is));
meta->getInventory()->deSerialize(is);
// Rename inventory list "0" to "main"
Inventory *inv = meta->getInventory();
if(!inv->getList("main") && inv->getList("0")){
inv->getList("0")->setName("main");
}
assert(inv->getList("main") && !inv->getList("0"));
meta->setString("formspec","size[8,9]"
"list[current_name;main;0,0;8,4;]"
"list[current_player;main;0,5;8,4;]");
return false;
}
else if(id == NODEMETA_FURNACE) // FurnaceNodeMetadata
{
meta->getInventory()->deSerialize(is);
int temp = 0;
is>>temp;
meta->setString("fuel_totaltime", ftos((float)temp/10));
temp = 0;
is>>temp;
meta->setString("fuel_time", ftos((float)temp/10));
temp = 0;
is>>temp;
//meta->setString("src_totaltime", ftos((float)temp/10));
temp = 0;
is>>tempvoid ObjectProperties::deSerialize(std::istream &is)
{
int version = readU8(is);
if(version == 1)
{
try{
hp_max = readS16(is);
physical = readU8(is);
weight = readF1000(is);
collisionbox.MinEdge = readV3F1000(is);
collisionbox.MaxEdge = readV3F1000(is);
visual = deSerializeString(is);
visual_size = readV2F1000(is);
textures.clear();
u32 texture_count = readU16(is);
for(u32 i=0;<
std::istringstream tmp_is(data, std::ios::binary);
return content_nodemeta_deserialize_legacy_body(tmp_is, id, meta);
}
void content_nodemeta_deserialize_legacy(std::istream &is,
NodeMetadataList *meta, NodeTimerList *timers,
IItemDefManager *item_def_mgr)
{
meta->clear();
timers->clear();
u16 version = readU16(is);
if(version > 1)
{
infostream<<FUNCTION_NAME<<": version "<<version<<" not supported"
<<std::endl;
throw SerializationError(FUNCTION_NAME);
}
u16 count = readU16(is);
for(u16 i=0; i<count; i++)
{
u16 p16 = readU16(is);
v3s16 p(0,0,0);
p.Z += p16 / MAP_BLOCKSIZE / MAP_BLOCKSIZE;
p16 -= p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE;
p.Y += p16 / MAP_BLOCKSIZE;
p16 -= p.Y * MAP_BLOCKSIZE;
p.X += p16;
if(meta->get(p) != NULL)
{
warningstream<<FUNCTION_NAME<<": "
<<"already set data at position"
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<"): Ignoring."
<<std::endl;
continue;
}
NodeMetadata *data = new NodeMetadata(item_def_mgr);
bool need_timer = content_nodemeta_deserialize_legacy_meta(is, data);
meta->set(p, data);
if(need_timer)
timers->set(p, NodeTimer(1., 0.));
}
}
void content_nodemeta_serialize_legacy(std::ostream &os, NodeMetadataList *meta)
{
// Sorry, I was too lazy to implement this. --kahrl
writeU16(os, 1); // version
writeU16(os, 0); // count
}
// END
|