29 #define log_attribute log_debug
45 : key(k), id(i), x(x0), y(y0)
51 return pkey1.
key == pkey2.
key && pkey1.
id == pkey2.
id && pkey1.
x == pkey2.
x
52 && pkey1.
y == pkey2.
y;
57 return qHash(pkey.
id, seed) ^ pkey.
x ^ pkey.
y ^ pkey.
key;
73 for (
auto *at : qAsConst(*attribute_hash)) {
74 delete[]
static_cast<char *
>(at);
76 attribute_hash->clear();
100 const size_t entries = hash->size();
102 std::vector<int> value_lengths;
103 value_lengths.resize(entries);
112 total_length = 4 + 1 + 4 + 4;
114 total_length += entries * (4 + 4 + 4 + 2 + 2);
117 for (
auto *pvalue : qAsConst(*hash)) {
124 total_length += value_lengths[i];
131 data.resize(total_length);
147 attributeHash::const_iterator it = hash->constBegin();
148 while (it != hash->constEnd()) {
164 "serialize_hash() total_length = %lu, actual = %lu",
165 (
long unsigned) total_length,
172 "serialized %lu entries in %lu bytes",
173 (
long unsigned) entries, (
long unsigned) total_length);
184 const QByteArray &data)
186 int entries, i, dummy;
195 qDebug(
"attribute.cpp unserialize_hash() preamble, uint32 %lu != 0",
196 static_cast<long unsigned>(dummy));
201 qDebug(
"attribute.cpp unserialize_hash() preamble, "
202 "uint8 %lu != 2 version",
203 static_cast<long unsigned>(dummy));
208 if (dummy != data.size()) {
209 qDebug(
"attribute.cpp unserialize_hash() preamble, "
210 "uint32 %lu != %lu data_length",
211 static_cast<long unsigned>(dummy),
212 static_cast<long unsigned>(data.size()));
217 "uint32 %lu entries, %lu data_length",
218 (
long unsigned) entries, (
long unsigned) data.size());
220 for (i = 0; i < entries; i++) {
227 qDebug(
"attribute.cpp unserialize_hash() "
228 "uint32 value_length dio_input_too_short");
232 "uint32 %lu value_length",
233 (
long unsigned) value_length);
240 qDebug(
"attribute.cpp unserialize_hash() "
241 "uint32 key dio_input_too_short");
244 pvalue =
new char[value_length + 4];
249 qDebug(
"attribute.cpp unserialize_hash() "
250 "memory dio_input_too_short");
254 if (hash->contains(key)) {
260 ::operator
delete[](pvalue);
265 hash->insert(key, pvalue);
273 "ignored %lu trailing octets",
292 if (0 == attribute_hash->size()) {
317 qCritical(
_(
"There has been a CMA error. "
318 "Your citizen governor settings may be broken."));
321 qInfo(
_(
"Old attributes detected and removed."));
333 const void *
const data)
337 log_attribute(
"attribute_set(key = %d, id = %d, x = %d, y = %d, "
338 "data_length = %lu, data = %p)",
339 key,
id,
x,
y, (
long unsigned) data_length, data);
343 if (0 != data_length) {
344 void *pvalue =
new char[data_length + 4];
351 attribute_hash->insert(akey, pvalue);
353 attribute_hash->remove(akey);
374 log_attribute(
"attribute_get(key = %d, id = %d, x = %d, y = %d, "
375 "max_data_length = %lu, data = %p)",
376 key,
id, x, y, (
long unsigned) max_data_length, data);
380 if (!attribute_hash->contains(akey)) {
385 auto *pvalue = attribute_hash->value(akey);
390 if (length <= max_data_length) {
402 const void *
const data)
411 size_t max_data_length,
void *data)
413 return attribute_get(what, city_id, -1, -1, max_data_length, data);
void attribute_set(int key, int id, int x, int y, size_t data_length, const void *const data)
Low-level function to set an attribute.
uint qHash(const attr_key &pkey, uint seed)
static enum attribute_serial unserialize_hash(attributeHash *hash, const QByteArray &data)
This data was serialized (above), sent as an opaque data packet to the server, stored in a savegame,...
void attribute_init()
Initializes the attribute module.
QHash< attr_key, void * > attributeHash
size_t attribute_get(int key, int id, int x, int y, size_t max_data_length, void *data)
Low-level function to get an attribute.
size_t attr_city_get(enum attr_city what, int city_id, size_t max_data_length, void *data)
Get city related attribute.
static enum attribute_serial serialize_hash(attributeHash *hash, QByteArray &data)
Serialize an attribute hash for network/storage.
void attribute_restore()
Recreate the attribute set from the player's attribute_block.
void attribute_flush()
Send current state to the server.
void attribute_free()
Frees the attribute module.
bool operator==(const attr_key &pkey1, const attr_key &pkey2)
void attr_city_set(enum attr_city what, int city_id, size_t data_length, const void *const data)
Set city related attribute.
struct player * client_player()
Either controlling or observing.
bool client_is_observer()
Returns whether client is observer.
void dio_output_init(struct raw_data_out *dout, void *destination, size_t dest_size)
Initializes the output to the given output buffer and the given buffer size.
size_t dio_input_remaining(struct data_in *din)
Return the number of unread bytes.
void dio_put_uint8_raw(struct raw_data_out *dout, int value)
Insert value using 8 bits.
void dio_put_sint16_raw(struct raw_data_out *dout, int value)
Insert value using 16 bits.
bool dio_get_uint32_raw(struct data_in *din, int *dest)
Receive uint32 value to dest.
bool dio_get_sint16_raw(struct data_in *din, int *dest)
Take value from 16 bits.
void dio_put_uint32_raw(struct raw_data_out *dout, int value)
Insert value using 32 bits.
bool dio_get_memory_raw(struct data_in *din, void *dest, size_t dest_size)
Take memory block directly.
void dio_put_memory_raw(struct raw_data_out *dout, const void *value, size_t size)
Insert block directly from memory.
bool dio_get_uint8_raw(struct data_in *din, int *dest)
Receive uint8 value to dest.
size_t dio_output_used(struct raw_data_out *dout)
Return the maximum number of bytes used.
void dio_input_init(struct data_in *din, const void *src, size_t src_size)
Initializes the input to the given input buffer and the given number of valid input bytes.
#define fc_assert_msg(condition, message,...)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
void send_attribute_block(const struct player *pplayer, struct connection *pconn)
Split the attribute block into chunks and send them over pconn.
Q_GLOBAL_STATIC(QVector< QString >, future_name_translation)
#define ADD_TO_POINTER(p, n)
QByteArray attribute_block