2020-09-14 00:00:00 +00:00
|
|
|
#include "./player.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include <msgpack.h>
|
|
|
|
|
|
|
|
#include "util/mpkutil/get.h"
|
|
|
|
#include "util/mpkutil/pack.h"
|
|
|
|
|
|
|
|
#include "core/locommon/input.h"
|
|
|
|
#include "core/locommon/position.h"
|
2020-10-09 00:00:00 +00:00
|
|
|
#include "core/locommon/screen.h"
|
2020-09-14 00:00:00 +00:00
|
|
|
#include "core/locommon/ticker.h"
|
|
|
|
#include "core/loentity/entity.h"
|
|
|
|
#include "core/loentity/store.h"
|
|
|
|
|
|
|
|
#include "./camera.h"
|
|
|
|
#include "./combat.h"
|
|
|
|
#include "./controller.h"
|
|
|
|
#include "./event.h"
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
/* generated serializer */
|
|
|
|
#include "core/loplayer/crial/player.h"
|
2020-09-14 00:00:00 +00:00
|
|
|
|
|
|
|
void loplayer_initialize(
|
|
|
|
loplayer_t* player,
|
2020-10-09 00:00:00 +00:00
|
|
|
const locommon_screen_t* screen,
|
2020-09-14 00:00:00 +00:00
|
|
|
const locommon_ticker_t* ticker,
|
2020-10-09 00:00:00 +00:00
|
|
|
loentity_store_t* entities) {
|
2020-09-14 00:00:00 +00:00
|
|
|
assert(player != NULL);
|
|
|
|
assert(ticker != NULL);
|
|
|
|
assert(entities != NULL);
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
*player = (typeof(*player)) {0};
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
loplayer_stance_set_initialize(&player->stances);
|
|
|
|
loplayer_stance_set_add(&player->stances, LOPLAYER_STANCE_MISSIONARY);
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
loplayer_combat_initialize(&player->combat, ticker, entities);
|
|
|
|
loplayer_controller_initialize(&player->controller, ticker);
|
|
|
|
loplayer_camera_initialize(&player->camera, screen, ticker);
|
|
|
|
loplayer_event_initialize(&player->event, ticker);
|
|
|
|
loplayer_popup_initialize(&player->popup);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loplayer_deinitialize(loplayer_t* player) {
|
|
|
|
assert(player != NULL);
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
loplayer_popup_deinitialize(&player->popup);
|
|
|
|
loplayer_event_deinitialize(&player->event);
|
2020-09-14 00:00:00 +00:00
|
|
|
loplayer_camera_deinitialize(&player->camera);
|
|
|
|
loplayer_controller_deinitialize(&player->controller);
|
2020-10-09 00:00:00 +00:00
|
|
|
loplayer_combat_deinitialize(&player->combat);
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
loplayer_stance_set_deinitialize(&player->stances);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loplayer_update(
|
|
|
|
loplayer_t* player,
|
|
|
|
const locommon_input_t* input,
|
|
|
|
const locommon_position_t* cursor) {
|
|
|
|
assert(player != NULL);
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
loplayer_controller_handle_input(&player->controller, input, cursor);
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
loplayer_combat_drop_dead_attack(&player->combat);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loplayer_pack(const loplayer_t* player, msgpack_packer* packer) {
|
|
|
|
assert(player != NULL);
|
|
|
|
assert(packer != NULL);
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
msgpack_pack_map(packer, CRIAL_PROPERTY_COUNT_+1);
|
|
|
|
CRIAL_SERIALIZER_;
|
2020-09-14 00:00:00 +00:00
|
|
|
|
|
|
|
mpkutil_pack_str(packer, "entity");
|
2020-10-09 00:00:00 +00:00
|
|
|
loentity_pack((const loentity_t*) player->entity, packer);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool loplayer_unpack(loplayer_t* player, const msgpack_object* obj) {
|
|
|
|
assert(player != NULL);
|
|
|
|
|
|
|
|
const msgpack_object_map* root = mpkutil_get_map(obj);
|
2020-10-09 00:00:00 +00:00
|
|
|
if (root == NULL) return false;
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
CRIAL_DESERIALIZER_;
|
2020-09-14 00:00:00 +00:00
|
|
|
return true;
|
|
|
|
}
|