Crossfire Server, Trunk  1.75.0
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<>
24 void asset_destroy(Face *item) {
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 
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
Face name, as used by archetypes and such.
Definition: face.h:19
Face
New face structure - this enforces the notion that data is face by face only - you can not change the...
Definition: face.h:14
Face::smoothface
Face * smoothface
Smoothed face for this, NULL for none.
Definition: face.h:18
Faces::added
virtual void added(Face *face) override
An asset was either referenced (but undefined) or defined.
Definition: Faces.cpp:51
SMOOTH_FACE_NAME
#define SMOOTH_FACE_NAME
Definition: define.h:551
Faces::findById
const Face * findById(uint16_t id)
Definition: Faces.cpp:44
EMPTY_FACE_NAME
#define EMPTY_FACE_NAME
Definition: define.h:550
Faces::Faces
Faces()
Definition: Faces.cpp:29
blank_face
const Face * blank_face
Following can just as easily be pointers, but it is easier to keep them like this.
Definition: image.cpp:36
name
Plugin animator file specs[Config] name
Definition: animfiles.txt:4
ROTATE_RIGHT
#define ROTATE_RIGHT(c)
Definition: global.h:162
BLANK_FACE_NAME
#define BLANK_FACE_NAME
Definition: define.h:549
Faces::replace
virtual void replace(Face *existing, Face *update) override
Replace an asset by an updated version.
Definition: Faces.cpp:35
add_string
sstring add_string(const char *str)
This will add 'str' to the hash table.
Definition: shstr.cpp:124
treasurelist::name
sstring name
Usually monster-name/combination.
Definition: treasure.h:86
asset_destroy
void asset_destroy(Face *item)
Definition: Faces.cpp:24
AssetsCollection< Face >::get
Face * get(const std::string &name)
Get a named asset.
Definition: AssetsCollection.h:89
free_string
void free_string(sstring str)
This will reduce the refcount, and if it has reached 0, str will be freed.
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
How visible is the face compared to other faces, highest wins.
Definition: face.h:16
Faces.h
Face::magicmap
uint8_t magicmap
Color to show this in magic map.
Definition: face.h:17
AssetsCollection< Face >::m_assets
std::unordered_map< std::string, Face * > m_assets
Known 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
face
in that case they will be relative to whatever the PWD of the crossfire server process is You probably shouldn though Notes on Specific and settings file datadir Usually usr share crossfire Contains data that the server does not need to modify while such as the etc A default install will pack the and treasurelist definitions into a single or trs file and the graphics into a face(metadata) and .tar(bitmaps) file