Crossfire Server, Trunk  R21524
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 < get_faces_count(); f++)
62  {
63  const Face *face = get_face_by_index(f);
64  myFaces[face->name] = face;
65  }
66 
67  // There is the "bug" animation to consider
68  for (int anim = 0; anim <= num_animations; anim++)
69  {
70  myAnimations[animations[anim].name] = &animations[anim];
71  }
72 }
73 
74 QStringList ResourcesManager::archetypes() const
75 {
76  QStringList keys = myArchetypes.keys();
77  qSort(keys);
78  return keys;
79 }
80 
81 const archetype* ResourcesManager::archetype(const QString& name) const
82 {
83  return myArchetypes[name];
84 }
85 
87 {
88  QStringList keys = myTreasures.keys();
89  qSort(keys);
90  return keys;
91 }
92 
93 const treasurelist* ResourcesManager::treasureList(const QString& name)
94 {
95  return myTreasures[name];
96 }
97 
99 {
100  return myRecipes.size();
101 }
102 
103 QStringList ResourcesManager::recipes(int count) const
104 {
105  if (count < 1 || count > myRecipes.size())
106  return QStringList();
107 
108  QStringList keys = myRecipes[count - 1].keys();
109  qSort(keys);
110  return keys;
111 }
112 
113 const recipe* ResourcesManager::recipe(int ingredients, const QString& name) const
114 {
115  if (ingredients < 1 || ingredients > myRecipes.size())
116  return NULL;
117 
118  return myRecipes[ingredients - 1][name];
119 }
120 
121 
122 QStringList ResourcesManager::faces() const
123 {
124  QStringList keys = myFaces.keys();
125  qSort(keys);
126  return keys;
127 }
128 
129 const Face* ResourcesManager::face(const QString& name) const
130 {
131  return myFaces[name];
132 }
133 
135 {
136  QStringList keys = myAnimations.keys();
137  qSort(keys);
138  return keys;
139 }
140 
141 const animations_struct* ResourcesManager::animation(const QString& name) const
142 {
143  return myAnimations[name];
144 }
QList< QHash< QString, recipestruct * > > myRecipes
QHash< QString, animations_struct * > myAnimations
QHash< QString, archt * > myArchetypes
QStringList recipes(int count) const
QHash< QString, const Face * > myFaces
EXTERN int num_animations
Definition: global.h:162
const char * name
Definition: face.h:26
const treasurelist * treasureList(const QString &name)
Definition: face.h:14
const animations_struct * animation(const QString &name) const
const Face * get_face_by_index(int index)
Definition: image.c:642
struct treasureliststruct * next
Definition: treasure.h:89
const char * name
Definition: face.h:19
void init_globals(void)
Definition: init.c:257
void init_library(void)
Definition: init.c:186
Definition: object.h:467
QStringList archetypes() const
QStringList allAnimations() const
void init_formulae(void)
Definition: recipe.c:143
const recipestruct * recipe(int ingredients, const QString &name) const
QStringList faces() const
void load_treasures(void)
Definition: treasure.c:219
EXTERN Animations * animations
Definition: global.h:161
const archt * archetype(const QString &name) const
EXTERN treasurelist * first_treasurelist
Definition: global.h:118
void read_client_images(void)
Definition: image.c:454
unsigned int get_faces_count()
Definition: image.c:633
virtual ~ResourcesManager()
struct archt * next
Definition: object.h:469
struct recipestruct * next
Definition: recipe.h:24
const Face * face(const QString &name) const
int recipeMaxIngredients() const
QHash< QString, treasurelist * > myTreasures
EXTERN archetype * first_archetype
Definition: global.h:120
void init_artifacts(void)
Definition: artifact.c:529
struct recipestruct * items
Definition: recipe.h:40
recipelist * get_formulalist(int i)
Definition: recipe.c:96
QStringList treasureLists() const