-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathLocation.cpp
More file actions
65 lines (52 loc) · 2.01 KB
/
Copy pathLocation.cpp
File metadata and controls
65 lines (52 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//==============================================================================
//
// Location.cpp
//
// Diplomacy AI Client - Part of the DAIDE project (www.daide.org.uk).
//
// (C) David Norman 2002 david@ellought.demon.co.uk
// (C) Greg Utas 2019-2025 greg@pentennea.com
//
// This software may be reused for non-commercial purposes without charge,
// and without notifying the authors. Use of any part of this software for
// commercial purposes without permission from the authors is prohibited.
//
#include "Location.h"
#include <ostream>
#include "TokenMessage.h"
using std::ostream;
//------------------------------------------------------------------------------
namespace Diplomacy
{
Location::Location() : province(NIL_PROVINCE), coast(INVALID_TOKEN) { }
//------------------------------------------------------------------------------
Location::Location(ProvinceId p, const Token& c) : province(p), coast(c) { }
//------------------------------------------------------------------------------
Location::Location(const TokenMessage& where, const Token& unit_type) :
province(where.front().province_id()),
coast(where.is_single_token() ? unit_type : where.at(1))
{
}
//------------------------------------------------------------------------------
Location::Location(const TokenMessage& unit) :
province(unit.get_parm(2).front().province_id()),
coast(unit.get_parm(1).front())
{
}
//------------------------------------------------------------------------------
bool Location::operator<(const Location& that) const
{
if(this->province < that.province) return true;
if(that.province < this->province) return false;
if(this->coast < that.coast) return true;
if(that.coast < this->coast) return false;
return (this < &that);
}
//------------------------------------------------------------------------------
ostream& operator<<(ostream& stream, const Location& loc)
{
stream << province_token(loc.province);
if(loc.coast.category() == CATEGORY_COAST) stream << loc.coast;
return stream;
}
}