2
* Copyright (C) 2002-4 by the Widelands Development Team
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#include "widelands_map_player_position_data_packet.h"
21
#include "filesystem.h"
22
#include "editor_game_base.h"
24
#include "widelands_map_data_packet_ids.h"
28
#define CURRENT_PACKET_VERSION 1
33
Widelands_Map_Player_Position_Data_Packet::~Widelands_Map_Player_Position_Data_Packet(void) {
39
void Widelands_Map_Player_Position_Data_Packet::Read(FileRead* fr, Editor_Game_Base* egbase, bool skip, Widelands_Map_Map_Object_Loader*) throw(wexception) {
40
// read packet version
41
int packet_version=fr->Unsigned16();
43
if(packet_version==CURRENT_PACKET_VERSION) {
44
// Read all the positions
45
// This could bring trouble if one player position
46
// is not set (this is possible in the editor), is also
48
Map* map=egbase->get_map();
51
for(i=1; i<=map->get_nrplayers(); i++) {
55
map->set_starting_pos(i,c);
59
assert(0); // never here
66
void Widelands_Map_Player_Position_Data_Packet::Write(FileWrite* fw, Editor_Game_Base* egbase, Widelands_Map_Map_Object_Saver*) throw(wexception) {
67
// first of all the magic bytes
68
fw->Unsigned16(PACKET_PLAYER_POSITION);
71
fw->Unsigned16(CURRENT_PACKET_VERSION);
73
// Now, all positions in order, first x, then y
74
Map* map=egbase->get_map();
76
for(i=1; i<=map->get_nrplayers(); i++) {
77
Coords c=map->get_starting_pos(i);