Crossfire Server, Trunk  R20513
CREUtils.cpp
Go to the documentation of this file.
1 #include <QtGui>
2 #include "CREUtils.h"
3 #include "CREPixmap.h"
4 #include "CREMapInformation.h"
5 #include "Quest.h"
6 #include "MessageFile.h"
7 
8 extern "C" {
9 #include "global.h"
10 #include "recipe.h"
11 #include "libproto.h"
12 #include "ScriptFile.h"
13 }
14 
15 QTreeWidgetItem* CREUtils::archetypeNode(QTreeWidgetItem* parent)
16 {
17  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Archetypes")));
18  return item;
19 }
20 
21 QTreeWidgetItem* CREUtils::archetypeNode(const archt* arch, QTreeWidgetItem* parent)
22 {
23  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(arch->name));
24  //item->setData(0, Qt::UserRole, arch->getId());
25  item->setIcon(0, CREPixmap::getIcon(arch->clone.face->number));
26  return item;
27 }
28 
29 QTreeWidgetItem* CREUtils::objectNode(const object* op, QTreeWidgetItem* parent)
30 {
31  char name[500];
32  query_name(op, name, sizeof(name));
33  QString n;
34  if (op->nrof > 1)
35  n.append(QString::number(op->nrof)).append(" ");
36  n.append(name);
37  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(n));
38  item->setIcon(0, CREPixmap::getIcon(op->face->number));
39  return item;
40 }
41 
42 QTreeWidgetItem* CREUtils::artifactNode(QTreeWidgetItem* parent)
43 {
44  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Artifacts")));
45  return item;
46 }
47 
48 QTreeWidgetItem* CREUtils::artifactNode(const artifact* arti, QTreeWidgetItem* parent)
49 {
50  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(arti->item->name));
51  if (arti->item->face != NULL && arti->item->face != blank_face)
52  item->setIcon(0, CREPixmap::getIcon(arti->item->face->number));
53  else
54  {
55  int face = 0;
56  for (linked_char* allowed = arti->allowed; allowed; allowed = allowed->next)
57  {
58  if (allowed->name[0] == '!')
59  continue;
60  const archt* specific = try_find_archetype(allowed->name);
61  if (!specific)
62  specific = find_archetype_by_object_name(allowed->name);
63  if (specific && specific->clone.face != NULL)
64  {
65  face = specific->clone.face->number;
66  break;
67  }
68  }
69 
70  if (face == 0)
71  {
72  const archt* generic = get_archetype_by_type_subtype(arti->item->type, -1);
73  if (generic != NULL && generic->clone.face != NULL)
74  face = generic->clone.face->number;
75  }
76 
77  if (face)
78  item->setIcon(0, CREPixmap::getIcon(face));
79  }
80  return item;
81 }
82 
83 QTreeWidgetItem* CREUtils::treasureNode(QTreeWidgetItem* parent)
84 {
85  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Treasures")));
86  return item;
87 }
88 
89 QTreeWidgetItem* CREUtils::treasureNode(const treasurelist* list, QTreeWidgetItem* parent)
90 {
91  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(list->name));
92  if (list->total_chance == 0)
93  item->setIcon(0, CREPixmap::getTreasureIcon());
94  else
95  item->setIcon(0, CREPixmap::getTreasureOneIcon());
96  return item;
97 }
98 
99 QTreeWidgetItem* CREUtils::treasureNode(const treasure* treasure, const treasurelist* list, QTreeWidgetItem* parent)
100 {
101  QTreeWidgetItem* item;
102  if (treasure->item)
103  {
104  item = CREUtils::archetypeNode(treasure->item, parent);
105  if (treasure->next_yes)
106  {
107  QTreeWidgetItem* node = new QTreeWidgetItem(item, QStringList(QTreeWidget::tr("Yes")));
108  node->setIcon(0, CREPixmap::getTreasureYesIcon());
109  CREUtils::treasureNode(treasure->next_yes, list, node);
110  }
111  if (treasure->next_no)
112  {
113  QTreeWidgetItem* node = new QTreeWidgetItem(item, QStringList(QTreeWidget::tr("No")));
114  node->setIcon(0, CREPixmap::getTreasureNoIcon());
115  CREUtils::treasureNode(treasure->next_no, list, node);
116  }
117  }
118  else
119  {
120  if (treasure->name && strcmp(treasure->name, "NONE") == 0)
121  item = new QTreeWidgetItem(parent, QStringList(QString(QTreeWidget::tr("Nothing"))));
122  else
123  {
124  treasurelist* other = find_treasurelist(treasure->name);
125  item = CREUtils::treasureNode(other, parent);
126  }
127  }
128 
129  if (list->total_chance != 0)
130  {
131  item->setText(0, QTreeWidget::tr("%1 (%2%, %3 chances on %4)").arg(item->text(0)).arg(qRound(100 * treasure->chance / list->total_chance)).arg(treasure->chance).arg(list->total_chance));
132  }
133  else
134  {
135  item->setText(0, QTreeWidget::tr("%1 (%2%)").arg(item->text(0)).arg(treasure->chance));
136  }
137 
138  return item;
139 }
140 
141 QTreeWidgetItem* CREUtils::formulaeNode(const recipe* recipe, QTreeWidgetItem* parent)
142 {
143  QString title;
144  const archt* base = NULL;
145 
146  if (recipe->arch_names == 0)
147  {
148  title = QString("%1 (no archetype?)").arg(recipe->title);
149  }
150  else
151  {
152  base = find_archetype(recipe->arch_name[0]);
153  if (strcmp(recipe->title, "NONE") == 0)
154  {
155  title = base->clone.name;
156  }
157  else
158  {
159  title = QString("%1 of %2").arg(base->clone.name, recipe->title);
160  }
161  }
162  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(title));
163  if (base != NULL && base->clone.face != 0)
164  item->setIcon(0, CREPixmap::getIcon(base->clone.face->number));
165 
166  return item;
167 }
168 
169 QTreeWidgetItem* CREUtils::faceNode(QTreeWidgetItem* parent)
170 {
171  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Faces")));
172  return item;
173 }
174 
175 QTreeWidgetItem* CREUtils::faceNode(const New_Face* face, QTreeWidgetItem* parent)
176 {
177  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(face->name));
178  item->setIcon(0, CREPixmap::getIcon(face->number));
179  return item;
180 }
181 
182 QTreeWidgetItem* CREUtils::animationNode(QTreeWidgetItem* parent)
183 {
184  return new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Animations")));
185 }
186 
187 QTreeWidgetItem* CREUtils::animationNode(const Animations* anim, QTreeWidgetItem* parent)
188 {
189  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(anim->name));
190  if (anim->num_animations > 0)
191  item->setIcon(0, CREPixmap::getIcon((anim->faces[0] != NULL) ? anim->faces[0]->number : 0));
192  else
193  LOG(llevDebug, "empty animation: %s\n", anim->name);
194  return item;
195 }
196 
197 QTreeWidgetItem* CREUtils::regionNode(const QString& name, int count, QTreeWidgetItem *parent)
198 {
199  return new QTreeWidgetItem(parent, QStringList(QObject::tr("%1 - %2 maps").arg(name).arg(count)));
200 }
201 
202 QTreeWidgetItem* CREUtils::mapNode(QTreeWidgetItem *parent)
203 {
204  return new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Maps")));
205 }
206 
207 QTreeWidgetItem* CREUtils::mapNode(const CREMapInformation* map, QTreeWidgetItem *parent)
208 {
209  return new QTreeWidgetItem(parent, QStringList(QObject::tr("%1 [%2]").arg(map->name(), map->path())));
210 }
211 
212 QTreeWidgetItem* CREUtils::questsNode()
213 {
214  return new QTreeWidgetItem(QStringList(QTreeWidget::tr("Quests")));
215 }
216 
217 QTreeWidgetItem* CREUtils::questNode(const Quest* quest, QTreeWidgetItem* parent)
218 {
219  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(quest->code()));
220  if (quest->faceNumber() != 0)
221  item->setIcon(0, CREPixmap::getIcon(quest->faceNumber()));
222  return item;
223 }
224 
225 QTreeWidgetItem* CREUtils::messagesNode()
226 {
227  return new QTreeWidgetItem(QStringList(QTreeWidget::tr("NPC dialogs")));
228 }
229 
230 QTreeWidgetItem* CREUtils::messageNode(const MessageFile* message, QTreeWidgetItem* parent)
231 {
232  return new QTreeWidgetItem(parent, QStringList(message->path()));
233 }
234 
235 QTreeWidgetItem* CREUtils::scriptsNode()
236 {
237  return new QTreeWidgetItem(QStringList(QTreeWidget::tr("Scripts")));
238 }
239 QTreeWidgetItem* CREUtils::scriptNode(const ScriptFile* script, QTreeWidgetItem* parent)
240 {
241  return new QTreeWidgetItem(parent, QStringList(script->path()));
242 }
archetype * find_archetype(const char *name)
Finds, using the hashtable, which archetype matches the given name.
Definition: arch.c:695
treasureliststruct represents one logical group of items to be generated together.
Definition: treasure.h:82
static QTreeWidgetItem * animationNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:182
static QIcon getTreasureIcon()
Definition: CREPixmap.cpp:45
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:15
static QTreeWidgetItem * artifactNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:42
Definition: Quest.h:32
const char * name
Name of the animation sequence.
Definition: face.h:27
const QString & code() const
Definition: Quest.cpp:63
treasurelist * find_treasurelist(const char *name)
Searches for the given treasurelist in the globally linked list of treasurelists which has been built...
Definition: treasure.c:292
static QTreeWidgetItem * questsNode()
Definition: CREUtils.cpp:212
int faceNumber() const
Definition: Quest.cpp:102
object clone
An object from which to do object_copy()
Definition: object.h:470
Information about a script file.
Definition: ScriptFile.h:31
treasure is one element in a linked list, which together consist of a complete treasure-list.
Definition: treasure.h:63
static QIcon getTreasureYesIcon()
Definition: CREPixmap.cpp:57
static QTreeWidgetItem * formulaeNode(const recipe *recipe, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:141
Global type definitions and header inclusions.
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:465
static QTreeWidgetItem * faceNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:169
struct archt * item
Which item this link can be.
Definition: treasure.h:64
struct titlestruct title
Information on one title.
static QIcon getTreasureNoIcon()
Definition: CREPixmap.cpp:63
uint16_t number
This is the image id.
Definition: face.h:15
static QTreeWidgetItem * questNode(const Quest *quest, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:217
int16_t total_chance
If non-zero, only 1 item on this list should be generated.
Definition: treasure.h:84
const char * name
Face name, as used by archetypes and such.
Definition: face.h:20
sstring title
Distinguishing name of product.
Definition: recipe.h:11
char ** arch_name
Possible archetypes of the final product made.
Definition: recipe.h:13
static QTreeWidgetItem * scriptNode(const ScriptFile *script, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:239
struct linked_char * next
Definition: global.h:88
const char * name
The name of the object, obviously...
Definition: object.h:311
linked_char * allowed
List of archetypes the artifact can affect.
Definition: artifact.h:19
static QTreeWidgetItem * scriptsNode()
Definition: CREUtils.cpp:235
archetype * find_archetype_by_object_name(const char *name)
This function retrieves an archetype given the name that appears during the game (for example...
Definition: arch.c:57
This represents one animation.
Definition: face.h:26
uint8_t num_animations
How many different faces to animate, size of the faces array.
Definition: face.h:28
uint32_t nrof
How many of the objects.
Definition: object.h:333
const QString & path() const
Definition: ScriptFile.cpp:36
struct treasurestruct * next_no
If this item was not generated, then continue here.
Definition: treasure.h:68
Alchemy recipe structures.
archetype * try_find_archetype(const char *name)
Finds, using the hashtable, which archetype matches the given name.
Definition: arch.c:666
This is one artifact, ie one special item.
Definition: artifact.h:14
const New_Face ** faces
The actual faces for the animation.
Definition: face.h:31
uint8_t chance
Percent chance for this item.
Definition: treasure.h:70
const char * name
Usually monster-name/combination.
Definition: treasure.h:83
struct treasurestruct * next_yes
If this item was generated, use this link instead of ->next.
Definition: treasure.h:67
static QIcon getIcon(int faceNumber)
Definition: CREPixmap.cpp:27
New_Face * blank_face
Following can just as easily be pointers, but it is easier to keep them like this.
Definition: image.c:39
static QTreeWidgetItem * objectNode(const object *op, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:29
static QTreeWidgetItem * messagesNode()
Definition: CREUtils.cpp:225
archetype * get_archetype_by_type_subtype(int type, int subtype)
Retrieves an archetype by type and subtype.
Definition: arch.c:136
size_t arch_names
Size of the arch_name[] array.
Definition: recipe.h:12
Only for debugging purposes.
Definition: logger.h:13
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
static QTreeWidgetItem * regionNode(const QString &name, int count, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:197
New face structure - this enforces the notion that data is face by face only - you can not change the...
Definition: face.h:14
static QTreeWidgetItem * messageNode(const MessageFile *message, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:230
static QTreeWidgetItem * treasureNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:83
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.c:51
const QString & path() const
void query_name(const object *op, char *buf, size_t size)
Describes an item.
Definition: item.c:625
object * item
Special values of the artifact.
Definition: artifact.h:15
const New_Face * face
Face with colors.
Definition: object.h:332
const char * name
If non null, name of list to use instead.
Definition: treasure.h:65
const char * name
More definite name, like "generate_kobold".
Definition: object.h:466
One alchemy recipe.
Definition: recipe.h:10
static QTreeWidgetItem * mapNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:202
static QIcon getTreasureOneIcon()
Definition: CREPixmap.cpp:51