Crossfire Server, Trunk  R20513
ResourcesManager.cpp
Go to the documentation of this file.
1 #include <QString>
2 #include <qlist.h>
3 #include <qhash.h>
4 #include <QStringList>
5 #include "ResourcesManager.h"
6 #include <locale.h>
7 
8 extern "C" {
9 #include "global.h"
10 #include "libproto.h"
11 #include "recipe.h"
12 #include "image.h"
13 }
14 
16 {
17 }
18 
20 {
21 }
22 
24 {
25  setlocale(LC_NUMERIC, "C");
26 
27  init_globals();
28  init_library();
31  init_formulae();
33 
34  for (archt* arch = first_archetype; arch; arch = arch->next)
35  {
36  myArchetypes[arch->name] = arch;
37  }
38 
39  for (treasurelist* list = first_treasurelist; list; list = list->next)
40  {
41  myTreasures[list->name] = list;
42  }
43 
44  QString key;
45 
46  for (int ing = 1; ; ing++)
47  {
48  recipelist* list = get_formulalist(ing);
49  if (!list)
50  break;
51 
52  QHash<QString, recipestruct*> recipes;
53  for (recipestruct* rec = list->items; rec; rec = rec->next)
54  {
55  key = QString("%1_%2").arg(rec->arch_name[0], rec->title);
56  recipes[key] = rec;
57  }
58  myRecipes.append(recipes);
59  }
60 
61  for (unsigned int f = 0; f < nrofpixmaps; f++)
62  {
63  myFaces[new_faces[f].name] = &new_faces[f];
64  }
65 
66  // There is the "bug" animation to consider
67  for (int anim = 0; anim <= num_animations; anim++)
68  {
69  myAnimations[animations[anim].name] = &animations[anim];
70  }
71 }
72 
73 QStringList ResourcesManager::archetypes() const
74 {
75  QStringList keys = myArchetypes.keys();
76  qSort(keys);
77  return keys;
78 }
79 
80 const archetype* ResourcesManager::archetype(const QString& name) const
81 {
82  return myArchetypes[name];
83 }
84 
86 {
87  QStringList keys = myTreasures.keys();
88  qSort(keys);
89  return keys;
90 }
91 
92 const treasurelist* ResourcesManager::treasureList(const QString& name)
93 {
94  return myTreasures[name];
95 }
96 
98 {
99  return myRecipes.size();
100 }
101 
102 QStringList ResourcesManager::recipes(int count) const
103 {
104  if (count < 1 || count > myRecipes.size())
105  return QStringList();
106 
107  QStringList keys = myRecipes[count - 1].keys();
108  qSort(keys);
109  return keys;
110 }
111 
112 const recipe* ResourcesManager::recipe(int ingredients, const QString& name) const
113 {
114  if (ingredients < 1 || ingredients > myRecipes.size())
115  return NULL;
116 
117  return myRecipes[ingredients - 1][name];
118 }
119 
120 
121 QStringList ResourcesManager::faces() const
122 {
123  QStringList keys = myFaces.keys();
124  qSort(keys);
125  return keys;
126 }
127 
128 const New_Face* ResourcesManager::face(const QString& name) const
129 {
130  return myFaces[name];
131 }
132 
134 {
135  QStringList keys = myAnimations.keys();
136  qSort(keys);
137  return keys;
138 }
139 
140 const animations_struct* ResourcesManager::animation(const QString& name) const
141 {
142  return myAnimations[name];
143 }
QList< QHash< QString, recipestruct * > > myRecipes
QStringList archetypes() const
List of recipes with a certain number of ingredients.
Definition: recipe.h:37
QHash< QString, animations_struct * > myAnimations
QHash< QString, archt * > myArchetypes
treasureliststruct represents one logical group of items to be generated together.
Definition: treasure.h:82
const New_Face * face(const QString &name) const
New_Face * new_faces
Contains face information, with names, numbers, magicmap color and such.
Definition: image.c:33
EXTERN int num_animations
Definition: global.h:166
const char * name
Name of the animation sequence.
Definition: face.h:27
const treasurelist * treasureList(const QString &name)
const animations_struct * animation(const QString &name) const
QStringList recipes(int count) const
struct treasureliststruct * next
Next treasure-item in linked list.
Definition: treasure.h:89
void init_globals(void)
Initialises all global variables.
Definition: init.c:272
int recipeMaxIngredients() const
void init_library(void)
It is vital that init_library() is called by any functions using this library.
Definition: init.c:201
Global type definitions and header inclusions.
QStringList allAnimations() const
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:465
unsigned int nrofpixmaps
Number of bitmaps loaded from the "bmaps" file.
Definition: image.c:45
void init_formulae(void)
Builds up the lists of formula from the file in the libdir.
Definition: recipe.c:161
const char * name
Face name, as used by archetypes and such.
Definition: face.h:20
const archt * archetype(const QString &name) const
Image-related structures.
void load_treasures(void)
Opens LIBDIR/treasure and reads all treasure-declarations from it.
Definition: treasure.c:221
This represents one animation.
Definition: face.h:26
EXTERN Animations * animations
Definition: global.h:165
EXTERN treasurelist * first_treasurelist
First treasure.
Definition: global.h:120
Alchemy recipe structures.
void read_client_images(void)
Loads all the image types into memory.
Definition: image.c:448
QStringList treasureLists() const
QHash< QString, New_Face * > myFaces
virtual ~ResourcesManager()
struct archt * next
Next archetype in a linked list.
Definition: object.h:467
struct recipestruct * next
Next recipe with the same number of ingredients.
Definition: recipe.h:24
QStringList faces() const
New face structure - this enforces the notion that data is face by face only - you can not change the...
Definition: face.h:14
QHash< QString, treasurelist * > myTreasures
EXTERN archetype * first_archetype
First archetype.
Definition: global.h:122
void init_artifacts(void)
Builds up the lists of artifacts from the file in the libdir.
Definition: artifact.c:513
struct recipestruct * items
Pointer to first recipe in this list.
Definition: recipe.h:40
recipelist * get_formulalist(int i)
Gets a formula list by ingredients count.
Definition: recipe.c:114
const recipestruct * recipe(int ingredients, const QString &name) const
One alchemy recipe.
Definition: recipe.h:10