3 Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #include "genericobject.h"
24 std::string gob_cmd_set_properties(const ObjectProperties &prop)
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]);
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);
46 ObjectProperties gob_read_set_properties(std::istream &is)
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));
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);
68 std::string gob_cmd_update_position(
77 std::ostringstream os(std::ios::binary);
79 writeU8(os, GENERIC_CMD_UPDATE_POSITION);
81 writeV3F1000(os, position);
83 writeV3F1000(os, velocity);
85 writeV3F1000(os, acceleration);
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);
97 std::string gob_cmd_set_texture_mod(const std::string &mod)
99 std::ostringstream os(std::ios::binary);
101 writeU8(os, GENERIC_CMD_SET_TEXTURE_MOD);
103 os<<serializeString(mod);
107 std::string gob_cmd_set_sprite(
111 bool select_horiz_by_yawpitch
113 std::ostringstream os(std::ios::binary);
115 writeU8(os, GENERIC_CMD_SET_SPRITE);
118 writeU16(os, num_frames);
119 writeF1000(os, framelength);
120 writeU8(os, select_horiz_by_yawpitch);
124 std::string gob_cmd_punched(s16 damage, s16 result_hp)
126 std::ostringstream os(std::ios::binary);
128 writeU8(os, GENERIC_CMD_PUNCHED);
130 writeS16(os, damage);
132 writeS16(os, result_hp);
136 std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups)
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);