~ubuntu-branches/ubuntu/precise/widelands/precise-backports

« back to all changes in this revision

Viewing changes to src/widelands_map_player_position_data_packet.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Quinson
  • Date: 2005-02-14 10:41:12 UTC
  • Revision ID: james.westby@ubuntu.com-20050214104112-6v08iux9fptxpva9
Tags: upstream-build9
Import upstream version build9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2002-4 by the Widelands Development Team
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 */
 
19
 
 
20
#include "widelands_map_player_position_data_packet.h"
 
21
#include "filesystem.h"
 
22
#include "editor_game_base.h"
 
23
#include "map.h"
 
24
#include "widelands_map_data_packet_ids.h"
 
25
#include "error.h"
 
26
 
 
27
 
 
28
#define CURRENT_PACKET_VERSION 1
 
29
 
 
30
/*
 
31
 * Destructor
 
32
 */
 
33
Widelands_Map_Player_Position_Data_Packet::~Widelands_Map_Player_Position_Data_Packet(void) {
 
34
}
 
35
 
 
36
/*
 
37
 * Read Function
 
38
 */
 
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();
 
42
 
 
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
 
47
      // -1, -1
 
48
      Map* map=egbase->get_map();
 
49
 
 
50
      int i;
 
51
      for(i=1; i<=map->get_nrplayers(); i++) {
 
52
         Coords c;
 
53
         c.x=fr->Signed16();
 
54
         c.y=fr->Signed16();
 
55
         map->set_starting_pos(i,c);
 
56
      }
 
57
      return;
 
58
   }
 
59
   assert(0); // never here
 
60
}
 
61
 
 
62
 
 
63
/*
 
64
 * Write Function
 
65
 */
 
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);
 
69
 
 
70
   // Now packet version
 
71
   fw->Unsigned16(CURRENT_PACKET_VERSION);
 
72
 
 
73
   // Now, all positions in order, first x, then y
 
74
   Map* map=egbase->get_map();
 
75
   int i=0;
 
76
   for(i=1; i<=map->get_nrplayers(); i++) {
 
77
      Coords c=map->get_starting_pos(i);
 
78
      fw->Signed16(c.x);
 
79
      fw->Signed16(c.y);
 
80
   }
 
81
}