File: message.h

package info (click to toggle)
widelands 1:19+repack-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 370,608 kB
  • ctags: 20,609
  • sloc: cpp: 108,404; ansic: 18,695; python: 5,155; sh: 487; xml: 460; makefile: 233
file content (152 lines) | stat: -rw-r--r-- 4,400 bytes parent folder | download | duplicates (2)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * Copyright (C) 2002-2010 by the Widelands Development Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */

#ifndef WL_LOGIC_MESSAGE_H
#define WL_LOGIC_MESSAGE_H

#include <boost/signals2.hpp>
#include <string>

#include "graphic/graphic.h"
#include "logic/widelands.h"
#include "logic/widelands_geometry.h"

namespace Widelands {

struct Message {
	enum class Status : uint8_t { kNew, kRead, kArchived };
	enum class Type : uint8_t {
		kNoMessages,
		kAllMessages,
		kGameLogic,
		kGeologists,
		kGeologistsCoal,
		kGeologistsGold,
		kGeologistsStones,
		kGeologistsIron,
		kGeologistsWater,
		kScenario,
		kSeafaring,
		kEconomy,              // economy
		kEconomySiteOccupied,  // economy
		kWarfare,              // everything starting from here is warfare
		kWarfareSiteDefeated,
		kWarfareSiteLost,
		kWarfareUnderAttack
	};

	/**
	 * A new message to be displayed to the player
	 * \param msgtype    The type of message (economy, geologists, etc.)
	 * \param sent_time  The (game) time at which the message is sent
	 * \param init_title The intial message title
	 * \param init_body  The initial message body
	 * \param c          The message coords. The player will be able to position its view there.
	 *                   Defaults to Coords::null()
	 * \param ser        A MapObject serial. If non null, the message will be deleted once
	 *                   the object is removed from the game. Defaults to 0
	 * \param s          The message status. Defaults to Status::New
	 */
	Message(Message::Type msgtype,
	        uint32_t sent_time,
	        const std::string& init_title,
	        const std::string& init_icon_filename,
	        const std::string& init_heading,
	        const std::string& init_body,
	        const Widelands::Coords& c = Coords::null(),
	        Widelands::Serial ser = 0,
	        Status s = Status::kNew)
	   : type_(msgtype),
	     title_(init_title),
	     icon_filename_(init_icon_filename),
	     icon_(g_gr->images().get(init_icon_filename)),
	     heading_(init_heading),
	     body_(init_body),
	     sent_(sent_time),
	     position_(c),
	     serial_(ser),
	     status_(s) {
	}

	Message::Type type() const {
		return type_;
	}
	uint32_t sent() const {
		return sent_;
	}
	const std::string& title() const {
		return title_;
	}
	const std::string& icon_filename() const {
		return icon_filename_;
	}
	const Image* icon() const {
		return icon_;
	}
	const std::string& heading() const {
		return heading_;
	}
	const std::string& body() const {
		return body_;
	}
	Widelands::Coords position() const {
		return position_;
	}
	Widelands::Serial serial() const {
		return serial_;
	}
	Status status() const {
		return status_;
	}
	Status set_status(Status const s) {
		return status_ = s;
	}

	/**
	 * Returns the main type for the message's sub type
	 */
	Message::Type message_type_category() const {
		if (type_ >= Widelands::Message::Type::kWarfare) {
			return Widelands::Message::Type::kWarfare;

		} else if (type_ >= Widelands::Message::Type::kEconomy &&
		           type_ <= Widelands::Message::Type::kEconomySiteOccupied) {
			return Widelands::Message::Type::kEconomy;
		} else if (type_ >= Widelands::Message::Type::kGeologists &&
		           type_ <= Widelands::Message::Type::kGeologistsWater) {
			return Widelands::Message::Type::kGeologists;
		}
		return type_;
	}

private:
	Message::Type type_;
	const std::string title_;
	const std::string icon_filename_;
	const Image* icon_;  // Pointer to icon into picture stack
	const std::string heading_;
	const std::string body_;
	uint32_t sent_;
	Widelands::Coords position_;
	Widelands::Serial serial_;  // serial to map object
	Status status_;
};
}

#endif  // end of include guard: WL_LOGIC_MESSAGE_H