-
Notifications
You must be signed in to change notification settings - Fork 0
/
sea_object.hpp
125 lines (120 loc) · 3.92 KB
/
sea_object.hpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once
#include "container.hpp"
#include "sea_object.hpp"
#include "xy.hpp"
typedef struct _LWPTTLDYNAMICSTATEOBJECT LWPTTLDYNAMICSTATEOBJECT;
namespace ss {
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
enum SEA_OBJECT_STATE {
SOS_NOT_SET,
SOS_SAILING,
SOS_LOADING,
SOS_UNLOADING,
SOS_ERROR,
};
class sea_object {
typedef bg::model::point<float, 2, bg::cs::cartesian> point;
typedef bg::model::box<point> box;
typedef std::pair<box, int> value;
public:
explicit sea_object()
: id(0)
, type(0)
, fx(0)
, fy(0)
, fw(0)
, fh(0)
, fvx(0)
, fvy(0)
, state(SOS_NOT_SET)
, remain_loading_time(0)
, cargo(0)
, cargo_origin_seaport_id(-1)
, cargo_origin_xy({ 0,0 }) {
}
sea_object(int id, int type, float fx, float fy, float fw, float fh, const value& rtree_value)
: id(id)
, type(type)
, fx(fx)
, fy(fy)
, fw(fw)
, fh(fh)
, fvx(0)
, fvy(0)
, rtree_value(rtree_value)
, state(SOS_SAILING)
, remain_loading_time(0)
, cargo(0)
, cargo_origin_seaport_id(-1)
, cargo_origin_xy({ 0,0 }) {
}
void fill_sop(sea_object& sop) const {
sop = *this;
}
void set_guid(const std::string& v) {
guid = v;
}
void translate_xy(float dxv, float dyv) {
set_xy(fx + dxv, fy + dyv);
}
void get_xy(float& fx, float& fy) const {
fx = this->fx;
fy = this->fy;
}
void set_xy(float fx, float fy) {
this->fx = fx;
this->fy = fy;
rtree_value.first.min_corner().set<0>(fx);
rtree_value.first.min_corner().set<1>(fy);
rtree_value.first.max_corner().set<0>(fx + fw);
rtree_value.first.max_corner().set<1>(fy + fh);
}
void set_velocity(float fvx, float fvy) {
this->fvx = fvx;
this->fvy = fvy;
}
void set_destination(float fvx, float fvy) {
this->dest_fx = fvx;
this->dest_fy = fvy;
}
void get_velocity(float& fvx, float& fvy) const {
fvx = this->fvx;
fvy = this->fvy;
}
float get_distance_to_destination() const {
return sqrtf((dest_fx - fx) * (dest_fx - fx) + (dest_fy - fy) * (dest_fy - fy));
}
const value& get_rtree_value() const { return rtree_value; }
void set_state(SEA_OBJECT_STATE state) { this->state = state; }
SEA_OBJECT_STATE get_state() const { return state; }
void set_remain_unloading_time(float remain_unloading_time) {
this->remain_unloading_time = remain_unloading_time;
}
void set_remain_loading_time(float remain_loading_time) {
this->remain_loading_time = remain_loading_time;
}
void update(float delta_time);
int get_type() const { return type; }
int get_id() const { return id; }
int add_cargo(int amount, int cargo_origin_seaport_id, const xy32& cargo_origin_xy);
int remove_cargo(int amount, int cargo_destination_seaport_id, const xy32& cargo_destination_xy);
int get_cargo() const { return cargo; }
void fill_packet(LWPTTLDYNAMICSTATEOBJECT& p) const;
private:
int id;
int type;
float fx, fy;
float fw, fh;
float fvx, fvy;
float dest_fx, dest_fy;
std::string guid;
value rtree_value;
SEA_OBJECT_STATE state;
float remain_unloading_time;
float remain_loading_time;
int cargo;
int cargo_origin_seaport_id;
xy32 cargo_origin_xy;
};
}