Crossfire Server, Trunk  R20513
CRETreasurePanel.cpp
Go to the documentation of this file.
1 #include <Qt>
2 
3 extern "C" {
4 #include "global.h"
5 #include "treasure.h"
6 }
7 
8 #include "CRETreasurePanel.h"
9 #include "CREUtils.h"
10 
12 {
13  QGridLayout* layout = new QGridLayout(this);
14 
15  myUsing = new QTreeWidget(this);
16  myUsing->setColumnCount(1);
17  myUsing->setHeaderLabel(tr("Used by"));
18  myUsing->setIconSize(QSize(32, 32));
19  layout->addWidget(myUsing, 1, 1, 2, 1);
20 
21  layout->addWidget(new QLabel("Difficulty:"), 1, 2);
22  layout->addWidget(myDifficulty = new QSpinBox(this), 1, 3);
23  myDifficulty->setRange(0, 150);
24  myDifficulty->setValue(150);
25  QPushButton* generate = new QPushButton("generate", this);
26  connect(generate, SIGNAL(clicked(bool)), this, SLOT(onGenerate(bool)));
27  layout->addWidget(generate, 1, 4);
28  layout->addWidget(myGenerated = new QTreeWidget(this), 2, 2, 1, 3);
29  myGenerated->setHeaderLabel(tr("Generation result"));
30  myGenerated->setIconSize(QSize(32, 32));
31 }
32 
34 {
35  myUsing->clear();
36  myTreasure = treas;
37 
38  const archt* arch;
39  QTreeWidgetItem* root = NULL;
40 
41  QString name = myTreasure->name;
42 
43  for (arch = first_archetype; arch; arch = arch->more ? arch->more : arch->next)
44  {
45  if (arch->clone.randomitems && name == arch->clone.randomitems->name)
46  {
47  if (root == NULL)
48  {
49  root = CREUtils::archetypeNode(NULL);
50  myUsing->addTopLevelItem(root);
51  root->setExpanded(true);
52  }
53  CREUtils::archetypeNode(arch, root);
54  }
55  }
56 
57  root = NULL;
58 
59  const treasurelist* list;
60  const treasure* t;
61 
62  for (list = first_treasurelist; list; list = list->next)
63  {
64  for (t = list->items; t; t = t->next)
65  {
66  if (t->name == name)
67  {
68  if (root == NULL)
69  {
70  root = CREUtils::treasureNode(NULL);
71  myUsing->addTopLevelItem(root);
72  root->setExpanded(true);
73  }
74  CREUtils::treasureNode(list, root);
75  }
76  }
77  }
78 
79  myGenerated->clear();
80 }
81 
83 {
84  const int difficulty = myDifficulty->value();
85  myGenerated->clear();
86  object* result = object_new(), *item;
87  create_treasure((treasurelist*)myTreasure, result, 0, difficulty, 0);
88  while ((item = result->inv))
89  {
90  identify(result->inv);
91  myGenerated->addTopLevelItem(CREUtils::objectNode(item, NULL));
92 
93  object_remove(item);
94  object_free2(item, 0);
95  }
96 
97  object_free2(result, 0);
98 }
treasureliststruct represents one logical group of items to be generated together.
Definition: treasure.h:82
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:15
QTreeWidget * myGenerated
struct treasureliststruct * randomitems
Items to be generated.
Definition: object.h:385
object clone
An object from which to do object_copy()
Definition: object.h:470
struct treasureliststruct * next
Next treasure-item in linked list.
Definition: treasure.h:89
treasure is one element in a linked list, which together consist of a complete treasure-list.
Definition: treasure.h:63
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
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
This calls the appropriate treasure creation function.
Definition: treasure.c:490
object * object_new(void)
Grabs an object from the list of unused objects, makes sure it is initialised, and returns it...
Definition: object.c:1037
Defines and variables used by the artifact generation routines.
static char root[500]
Path to store generated files.
Definition: mapper.c:365
QSpinBox * myDifficulty
QTreeWidget * myUsing
struct archt * more
Next part of a linked object.
Definition: object.h:469
const treasurelist * myTreasure
EXTERN treasurelist * first_treasurelist
First treasure.
Definition: global.h:120
struct treasurestruct * items
Items in this list, linked.
Definition: treasure.h:90
const char * name
Usually monster-name/combination.
Definition: treasure.h:83
static QTreeWidgetItem * objectNode(const object *op, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:29
void onGenerate(bool pressed)
virtual void setItem(const treasurelist *treasure)
void object_free2(object *ob, int flags)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
Definition: object.c:1391
struct archt * next
Next archetype in a linked list.
Definition: object.h:467
object * identify(object *op)
Identifies an item.
Definition: item.c:1437
struct obj * inv
Pointer to the first object in the inventory.
Definition: object.h:290
static QTreeWidgetItem * treasureNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:83
struct treasurestruct * next
Next treasure-item in a linked list.
Definition: treasure.h:66
const char * name
If non null, name of list to use instead.
Definition: treasure.h:65
EXTERN archetype * first_archetype
First archetype.
Definition: global.h:122
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to...
Definition: object.c:1654
Definition: main.c:88