Crossfire Server, Trunk
Faces.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2020 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include "Faces.h"
14 #include "string.h"
15 
16 template<>
17 Face *asset_create(const std::string& name) {
18  Face *face = (Face *)calloc(1, sizeof(Face));
19  face->name = add_string(name.c_str());
20  return face;
21 }
22 
23 template<>
25  free_string(item->name);
26  free(item);
27 }
28 
29 Faces::Faces() : m_checksum(0) {
33 }
34 
35 void Faces::replace(Face *existing, Face *update) {
36  existing->visibility = update->visibility;
37  existing->magicmap = update->magicmap;
38  if (update->smoothface) {
39  existing->smoothface = update->smoothface;
40  }
41  asset_destroy(update);
42 }
43 
44 const Face *Faces::findById(uint16_t id) {
45  auto face = std::find_if(m_assets.begin(), m_assets.end(), [&id] (auto& face) {
46  return face.second->number == id;
47  });
48  return face == m_assets.end() ? NULL : face->second;
49 }
50 
51 void Faces::added(Face *face) {
52  face->number = m_assets.size() - 1;
53 
55  m_checksum += face->number & 0xff;
56  m_checksum &= 0xffffffff;
57 
59  m_checksum += (face->number >> 8) & 0xff;
60  m_checksum &= 0xffffffff;
61  for (size_t l = 0; l < strlen(face->name); l++) {
63  m_checksum += face->name[l];
64  m_checksum &= 0xffffffff;
65  }
66 }
Face::name
sstring name
Definition: face.h:19
Face
Definition: face.h:14
Face::smoothface
Face * smoothface
Definition: face.h:18
banquet.l
l
Definition: banquet.py:164
Faces::added
virtual void added(Face *face) override
Definition: Faces.cpp:51
SMOOTH_FACE_NAME
#define SMOOTH_FACE_NAME
Definition: define.h:557
Faces::findById
const Face * findById(uint16_t id)
Definition: Faces.cpp:44
EMPTY_FACE_NAME
#define EMPTY_FACE_NAME
Definition: define.h:556
Faces::Faces
Faces()
Definition: Faces.cpp:29
blank_face
const Face * blank_face
Definition: image.cpp:36
ROTATE_RIGHT
#define ROTATE_RIGHT(c)
Definition: global.h:160
BLANK_FACE_NAME
#define BLANK_FACE_NAME
Definition: define.h:555
Faces::replace
virtual void replace(Face *existing, Face *update) override
Definition: Faces.cpp:35
Face::number
uint16_t number
Definition: face.h:15
add_string
sstring add_string(const char *str)
Definition: shstr.cpp:124
asset_destroy
void asset_destroy(Face *item)
Definition: Faces.cpp:24
AssetsCollection< Face >::get
Face * get(const std::string &name)
Definition: AssetsCollection.h:89
free_string
void free_string(sstring str)
Definition: shstr.cpp:280
empty_face
const Face * empty_face
Definition: image.cpp:36
asset_create
Face * asset_create(const std::string &name)
Definition: Faces.cpp:17
Face::visibility
uint8_t visibility
Definition: face.h:16
item
Definition: item.py:1
Faces.h
Face::magicmap
uint8_t magicmap
Definition: face.h:17
AssetsCollection< Face >::m_assets
std::unordered_map< std::string, Face * > m_assets
Definition: AssetsCollection.h:190
smooth_face
const Face * smooth_face
Definition: image.cpp:36
Faces::m_checksum
int m_checksum
Definition: Faces.h:28
give.name
name
Definition: give.py:27