]> git.lizzy.rs Git - minetest.git/blob - src/genericobject.cpp
Tune cave generation
[minetest.git] / src / genericobject.cpp
1 /*
2 Minetest-c55
3 Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "genericobject.h"
21 #include "utility.h"
22 #include <sstream>
23
24 std::string gob_cmd_set_properties(const ObjectProperties &prop)
25 {
26         std::ostringstream os(std::ios::binary);
27         writeU8(os, GENERIC_CMD_SET_PROPERTIES);
28         writeS16(os, prop.hp_max);
29         writeU8(os, prop.physical);
30         writeF1000(os, prop.weight);
31         writeV3F1000(os, prop.collisionbox.MinEdge);
32         writeV3F1000(os, prop.collisionbox.MaxEdge);
33         os<<serializeString(prop.visual);
34         writeV2F1000(os, prop.visual_size);
35         writeU16(os, prop.textures.size());
36         for(u32 i=0; i<prop.textures.size(); i++){
37                 os<<serializeString(prop.textures[i]);
38         }
39         writeV2S16(os, prop.spritediv);
40         writeV2S16(os, prop.initial_sprite_basepos);
41         writeU8(os, prop.is_visible);
42         writeU8(os, prop.makes_footstep_sound);
43         return os.str();
44 }
45
46 ObjectProperties gob_read_set_properties(std::istream &is)
47 {
48         ObjectProperties prop;
49         prop.hp_max = readS16(is);
50         prop.physical = readU8(is);
51         prop.weight = readF1000(is);
52         prop.collisionbox.MinEdge = readV3F1000(is);
53         prop.collisionbox.MaxEdge = readV3F1000(is);
54         prop.visual = deSerializeString(is);
55         prop.visual_size = readV2F1000(is);
56         prop.textures.clear();
57         u32 texture_count = readU16(is);
58         for(u32 i=0; i<texture_count; i++){
59                 prop.textures.push_back(deSerializeString(is));
60         }
61         prop.spritediv = readV2S16(is);
62         prop.initial_sprite_basepos = readV2S16(is);
63         prop.is_visible = readU8(is);
64         prop.makes_footstep_sound = readU8(is);
65         return prop;
66 }
67
68 std::string gob_cmd_update_position(
69         v3f position,
70         v3f velocity,
71         v3f acceleration,
72         f32 yaw,
73         bool do_interpolate,
74         bool is_movement_end,
75         f32 update_interval
76 ){
77         std::ostringstream os(std::ios::binary);
78         // command
79         writeU8(os, GENERIC_CMD_UPDATE_POSITION);
80         // pos
81         writeV3F1000(os, position);
82         // velocity
83         writeV3F1000(os, velocity);
84         // acceleration
85         writeV3F1000(os, acceleration);
86         // yaw
87         writeF1000(os, yaw);
88         // do_interpolate
89         writeU8(os, do_interpolate);
90         // is_end_position (for interpolation)
91         writeU8(os, is_movement_end);
92         // update_interval (for interpolation)
93         writeF1000(os, update_interval);
94         return os.str();
95 }
96
97 std::string gob_cmd_set_texture_mod(const std::string &mod)
98 {
99         std::ostringstream os(std::ios::binary);
100         // command 
101         writeU8(os, GENERIC_CMD_SET_TEXTURE_MOD);
102         // parameters
103         os<<serializeString(mod);
104         return os.str();
105 }
106
107 std::string gob_cmd_set_sprite(
108         v2s16 p,
109         u16 num_frames,
110         f32 framelength,
111         bool select_horiz_by_yawpitch
112 ){
113         std::ostringstream os(std::ios::binary);
114         // command
115         writeU8(os, GENERIC_CMD_SET_SPRITE);
116         // parameters
117         writeV2S16(os, p);
118         writeU16(os, num_frames);
119         writeF1000(os, framelength);
120         writeU8(os, select_horiz_by_yawpitch);
121         return os.str();
122 }
123
124 std::string gob_cmd_punched(s16 damage, s16 result_hp)
125 {
126         std::ostringstream os(std::ios::binary);
127         // command 
128         writeU8(os, GENERIC_CMD_PUNCHED);
129         // damage
130         writeS16(os, damage);
131         // result_hp
132         writeS16(os, result_hp);
133         return os.str();
134 }
135
136 std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups)
137 {
138         std::ostringstream os(std::ios::binary);
139         writeU8(os, GENERIC_CMD_UPDATE_ARMOR_GROUPS);
140         writeU16(os, armor_groups.size());
141         for(ItemGroupList::const_iterator i = armor_groups.begin();
142                         i != armor_groups.end(); i++){
143                 os<<serializeString(i->first);
144                 writeS16(os, i->second);
145         }
146         return os.str();
147 }
148
149