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 Faces::Faces() : m_checksum(0) {
20 }
21 
22 Face *Faces::create(const std::string& name) {
23  Face *face = (Face *)calloc(1, sizeof(Face));
24  face->name = add_string(name.c_str());
25  face->number = m_assets.size();
26  return face;
27 }
28 
30  free_string(item->name);
31  free(item);
32 }
33 
34 void Faces::replace(Face *existing, Face *update) {
35  existing->visibility = update->visibility;
36  existing->magicmap = update->magicmap;
37  if (update->smoothface) {
38  existing->smoothface = update->smoothface;
39  }
40  destroy(update);
41 }
42 
43 const Face *Faces::findById(uint16_t id) {
44  auto face = std::find_if(m_assets.begin(), m_assets.end(), [&id] (auto& face) {
45  return face.second->number == id;
46  });
47  return face == m_assets.end() ? NULL : face->second;
48 }
49 
50 void Faces::added(Face *face) {
51  face->number = m_assets.size() - 1;
52 
54  m_checksum += face->number & 0xff;
55  m_checksum &= 0xffffffff;
56 
58  m_checksum += (face->number >> 8) & 0xff;
59  m_checksum &= 0xffffffff;
60  for (size_t l = 0; l < strlen(face->name); l++) {
62  m_checksum += face->name[l];
63  m_checksum &= 0xffffffff;
64  }
65 }
Face::name
sstring name
Definition: face.h:19
Face
Definition: face.h:14
banquet.l
l
Definition: banquet.py:164
add_string
sstring add_string(const char *str)
Definition: shstr.c:124
SMOOTH_FACE_NAME
#define SMOOTH_FACE_NAME
Definition: define.h:557
Faces::findById
const Face * findById(uint16_t id)
Definition: Faces.cpp:43
EMPTY_FACE_NAME
#define EMPTY_FACE_NAME
Definition: define.h:556
Faces::destroy
virtual void destroy(Face *item)
Definition: Faces.cpp:29
blank_face
const Face * blank_face
Definition: image.c:35
Faces::Faces
Faces()
Definition: Faces.cpp:16
ROTATE_RIGHT
#define ROTATE_RIGHT(c)
Definition: global.h:158
free_string
void free_string(sstring str)
Definition: shstr.c:280
BLANK_FACE_NAME
#define BLANK_FACE_NAME
Definition: define.h:555
Faces::replace
virtual void replace(Face *existing, Face *update)
Definition: Faces.cpp:34
AssetsCollection< Face >::m_assets
std::map< std::string, Face * > m_assets
Definition: AssetsCollection.h:157
Faces::added
virtual void added(Face *face)
Definition: Faces.cpp:50
Face::number
uint16_t number
Definition: face.h:15
Faces::create
virtual Face * create(const std::string &name)
Definition: Faces.cpp:22
empty_face
const Face * empty_face
Definition: image.c:35
Face::smoothface
struct Face * smoothface
Definition: face.h:18
AssetsCollection< Face >::get
Face * get(const std::string &name)
Definition: AssetsCollection.h:66
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
Faces::m_checksum
int m_checksum
Definition: Faces.h:30
smooth_face
const Face * smooth_face
Definition: image.c:35
give.name
name
Definition: give.py:27