]> git.lizzy.rs Git - dragonfireclient.git/blob - src/genericobject.cpp
482dbbc78d56eb2c05b287cc6bbd6e1cb9ef1210
[dragonfireclient.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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser 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 <sstream>
22 #include "util/serialize.h"
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         prop.serialize(os);
29         return os.str();
30 }
31
32 ObjectProperties gob_read_set_properties(std::istream &is)
33 {
34         ObjectProperties prop;
35         prop.deSerialize(is);
36         return prop;
37 }
38
39 std::string gob_cmd_update_position(
40         v3f position,
41         v3f velocity,
42         v3f acceleration,
43         f32 yaw,
44         bool do_interpolate,
45         bool is_movement_end,
46         f32 update_interval
47 ){
48         std::ostringstream os(std::ios::binary);
49         // command
50         writeU8(os, GENERIC_CMD_UPDATE_POSITION);
51         // pos
52         writeV3F1000(os, position);
53         // velocity
54         writeV3F1000(os, velocity);
55         // acceleration
56         writeV3F1000(os, acceleration);
57         // yaw
58         writeF1000(os, yaw);
59         // do_interpolate
60         writeU8(os, do_interpolate);
61         // is_end_position (for interpolation)
62         writeU8(os, is_movement_end);
63         // update_interval (for interpolation)
64         writeF1000(os, update_interval);
65         return os.str();
66 }
67
68 std::string gob_cmd_set_texture_mod(const std::string &mod)
69 {
70         std::ostringstream os(std::ios::binary);
71         // command 
72         writeU8(os, GENERIC_CMD_SET_TEXTURE_MOD);
73         // parameters
74         os<<serializeString(mod);
75         return os.str();
76 }
77
78 std::string gob_cmd_set_sprite(
79         v2s16 p,
80         u16 num_frames,
81         f32 framelength,
82         bool select_horiz_by_yawpitch
83 ){
84         std::ostringstream os(std::ios::binary);
85         // command
86         writeU8(os, GENERIC_CMD_SET_SPRITE);
87         // parameters
88         writeV2S16(os, p);
89         writeU16(os, num_frames);
90         writeF1000(os, framelength);
91         writeU8(os, select_horiz_by_yawpitch);
92         return os.str();
93 }
94
95 std::string gob_cmd_set_animations(v2f frames, float frame_speed, float frame_blend)
96 {
97         std::ostringstream os(std::ios::binary);
98         // command 
99         writeU8(os, GENERIC_CMD_SET_ANIMATIONS);
100         // parameters
101         writeV2F1000(os, frames);
102         writeF1000(os, frame_speed);
103         writeF1000(os, frame_blend);
104         return os.str();
105 }
106
107 // Part of the attachment structure, not used yet!
108 std::string gob_cmd_set_attachment() // <- parameters here
109 {
110         std::ostringstream os(std::ios::binary);
111         // command 
112         writeU8(os, GENERIC_CMD_SET_ATTACHMENT);
113         // parameters
114         // Parameters go here
115         return os.str();
116 }
117
118 std::string gob_cmd_set_bone_posrot(std::string bone, v3f position, v3f rotation)
119 {
120         std::ostringstream os(std::ios::binary);
121         // command 
122         writeU8(os, GENERIC_CMD_SET_BONE_POSROT);
123         // parameters
124         os<<serializeString(bone);
125         writeV3F1000(os, position);
126         writeV3F1000(os, rotation);
127         return os.str();
128 }
129
130 std::string gob_cmd_punched(s16 damage, s16 result_hp)
131 {
132         std::ostringstream os(std::ios::binary);
133         // command 
134         writeU8(os, GENERIC_CMD_PUNCHED);
135         // damage
136         writeS16(os, damage);
137         // result_hp
138         writeS16(os, result_hp);
139         return os.str();
140 }
141
142 std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups)
143 {
144         std::ostringstream os(std::ios::binary);
145         writeU8(os, GENERIC_CMD_UPDATE_ARMOR_GROUPS);
146         writeU16(os, armor_groups.size());
147         for(ItemGroupList::const_iterator i = armor_groups.begin();
148                         i != armor_groups.end(); i++){
149                 os<<serializeString(i->first);
150                 writeS16(os, i->second);
151         }
152         return os.str();
153 }
154
155