-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathship.cc
More file actions
93 lines (60 loc) · 2.5 KB
/
ship.cc
File metadata and controls
93 lines (60 loc) · 2.5 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Time-stamp: <2016-03-01 05:22:37 daniel>
//
// ship.cc: Member function bodies for class 'ship_t'
//
// Required header files
//-----------------------------------------------------------------------------
#include <ostream> // std::ostream
#include "chance.hh" // chance::number::upto
#include "ship.hh" // parsec::ship_t
// NS short hand
//-----------------------------------------------------------------------------
using namespace std; // standard library
using namespace parsec; // project NS
// Static value holding current count of all ships
//-----------------------------------------------------------------------------
uint64_t ship_t::id_counter = 0x1;
// Empty constructor
//-----------------------------------------------------------------------------
ship_t::ship_t( ) : id_( 0x0 ), techlevel_( 0x0 ) {
}; // end constructor
// Constructor
//-----------------------------------------------------------------------------
ship_t::ship_t( int tl )
: id_( ship_t::id_counter++ ), techlevel_( tl ) {
}; // end constructor
// Copy constructor
//-----------------------------------------------------------------------------
ship_t::ship_t( const ship_t& org )
: id_( org.id_ ), techlevel_( org.techlevel_ ) {
}; // end copy constructor
// Destructor
//-----------------------------------------------------------------------------
ship_t::~ship_t() {
}; // end destructor
// Return this ship as an ID
//-----------------------------------------------------------------------------
ship_t::operator int() const { return id_; };
// Treat this object as a function
//-----------------------------------------------------------------------------
int ship_t::operator()() const {
int upper = 0x6 + ( techlevel_ - 10 );
return chance::number::upto( upper ) + 1;
}; // end operator()
// Conditional operators
//-----------------------------------------------------------------------------
bool ship_t::operator==( const ship_t& target ) const {
return id_ == target.id();
}; // end operator==
// Conditional operators
//-----------------------------------------------------------------------------
bool ship_t::operator!=( const ship_t& target ) const {
return id_ != target.id();
}; // end operator!=
// Dump the ship to outstream
//-----------------------------------------------------------------------------
ostream& parsec::operator<<( ostream& out, const ship_t& ship ) {
out << "Ship: " << ship.id()
<< " at tech level " << ship.techlevel_ << endl;
return out;
}; // end operator<<