Crossfire Server, Trunk
RecipeWrapper.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 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 "RecipeWrapper.h"
14 #include "ResourcesManager.h"
15 #include "CREPixmap.h"
16 #include "../archetypes/ArchetypeWrapper.h"
17 #include "CREUtils.h"
18 
20  : AssetTWrapper(parent, "Recipe", rp) {
21 }
22 
23 QString RecipeWrapper::title() const
24 {
25  return myWrappedItem->title;
26 }
27 
28 int RecipeWrapper::chance() const
29 {
30  return myWrappedItem->chance;
31 }
32 
33 int RecipeWrapper::difficulty() const
34 {
35  return myWrappedItem->diff;
36 }
37 
38 int RecipeWrapper::experience() const
39 {
40  return myWrappedItem->exp;
41 }
42 
43 QStringList RecipeWrapper::archs() const
44 {
45  QStringList archs;
46  for (size_t i = 0; i < myWrappedItem->arch_names; i++)
47  {
48  archs.append(myWrappedItem->arch_name[i]);
49  }
50  return archs;
51 }
52 
53 QStringList RecipeWrapper::ingredients() const
54 {
55  QStringList ingredients;
56  for (linked_char* ing = myWrappedItem->ingred; ing; ing = ing->next)
57  {
58  ingredients.append(ing->name);
59  }
60  return ingredients;
61 }
62 
63 bool RecipeWrapper::transmute() const
64 {
65  return myWrappedItem->transmute != 0;
66 }
67 
68 int RecipeWrapper::minLevel() const
69 {
70  return myWrappedItem->min_level;
71 }
72 
73 QString RecipeWrapper::keycode() const
74 {
75  return myWrappedItem->keycode;
76 }
77 
78 QString RecipeWrapper::displayName() const {
79  if (myWrappedItem->arch_names == 0) {
80  return QString("%1 (no archetype?)").arg(myWrappedItem->title);
81  }
82  auto base = find_archetype(myWrappedItem->arch_name[0]);
83  if (!base) {
84  return QString("%1 (no archetype?)").arg(myWrappedItem->title);
85  }
86 
87  if (strcmp(myWrappedItem->title, "NONE") == 0) {
88  if (base->clone.title) {
89  return QString("%1 %2").arg(base->clone.name, base->clone.title);
90  }
91  return base->clone.name;
92  }
93  return QString("%1 of %2").arg(base->clone.name, myWrappedItem->title);
94 }
95 
97  const Face *face;
98  {
99  auto locker = CREUtils::lockCrossfireData();
101  }
102 
103  const archetype* base = NULL;
104  if (myWrappedItem->arch_names > 0) {
106  }
107  if (!face && base != NULL) {
108  return CREPixmap::getIcon(base->clone.face);
109  }
110  return CREPixmap::getIcon(face);
111 }
112 
113 AssetWrapper::PossibleUse RecipeWrapper::uses(const AssetWrapper *asset, std::string &hint) const {
114  auto arch = dynamic_cast<const ArchetypeWrapper *>(asset);
115  if (arch) {
116  for (size_t i = 0; i < wrappedItem()->arch_names; i++) {
117  if (strcmp(wrappedItem()->arch_name[i], arch->wrappedItem()->name) == 0) {
118  hint = "alchemy product";
119  return Uses;
120  }
121  }
122  return DoesntUse;
123  }
124  return DoesntUse;
125 }
AssetTWrapper< const recipe >::myWrappedItem
const recipe * myWrappedItem
Definition: AssetWrapper.h:104
Face
Definition: face.h:14
RecipeWrapper::minLevel
int minLevel
Definition: RecipeWrapper.h:35
RecipeWrapper::displayName
virtual QString displayName() const override
Definition: RecipeWrapper.cpp:78
recipe::arch_names
size_t arch_names
Definition: recipe.h:12
ResourcesManager
Definition: ResourcesManager.h:80
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
CREUtils.h
AssetWrapper::PossibleUse
PossibleUse
Definition: AssetWrapper.h:32
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:65
RecipeWrapper.h
recipe::arch_name
char ** arch_name
Definition: recipe.h:13
recipe::transmute
int transmute
Definition: recipe.h:19
recipe::exp
int exp
Definition: recipe.h:17
linked_char
Definition: global.h:96
RecipeWrapper::title
QString title
Definition: RecipeWrapper.h:28
RecipeWrapper::RecipeWrapper
RecipeWrapper(AssetWrapper *parent, const recipe *rp, ResourcesManager *resources)
Definition: RecipeWrapper.cpp:19
RecipeWrapper::displayIcon
virtual QIcon displayIcon() const override
Definition: RecipeWrapper.cpp:96
archetype::clone
object clone
Definition: object.h:487
AssetWrapper
Definition: AssetWrapper.h:25
object::face
const Face * face
Definition: object.h:341
CREUtils::lockCrossfireData
static std::unique_ptr< QMutexLocker > lockCrossfireData()
Definition: CREUtils.cpp:59
linked_char::next
struct linked_char * next
Definition: global.h:98
RecipeWrapper::uses
virtual PossibleUse uses(const AssetWrapper *asset, std::string &hint) const override
Definition: RecipeWrapper.cpp:113
archetype
Definition: object.h:483
AssetWrapper::Uses
@ Uses
Definition: AssetWrapper.h:32
AssetTWrapper< const recipe >::wrappedItem
const recipe * wrappedItem() const
Definition: AssetWrapper.h:101
ResourcesManager.h
RecipeWrapper::transmute
bool transmute
Definition: RecipeWrapper.h:34
recipe
Definition: recipe.h:10
recipe::chance
int chance
Definition: recipe.h:14
ArchetypeWrapper
Definition: ArchetypeWrapper.h:25
RecipeWrapper::keycode
QString keycode
Definition: RecipeWrapper.h:36
find_archetype
archetype * find_archetype(const char *name)
Definition: assets.cpp:266
recipe::diff
int diff
Definition: recipe.h:16
recipe::keycode
sstring keycode
Definition: recipe.h:25
recipe::min_level
int min_level
Definition: recipe.h:30
recipe::ingred
linked_char * ingred
Definition: recipe.h:22
RecipeWrapper::difficulty
int difficulty
Definition: RecipeWrapper.h:30
AssetWrapper::DoesntUse
@ DoesntUse
Definition: AssetWrapper.h:32
RecipeWrapper::archs
QStringList archs
Definition: RecipeWrapper.h:32
RecipeWrapper::chance
int chance
Definition: RecipeWrapper.h:29
CREPixmap.h
RecipeWrapper::ingredients
QStringList ingredients
Definition: RecipeWrapper.h:33
RecipeWrapper::experience
int experience
Definition: RecipeWrapper.h:31
recipe_get_face
const Face * recipe_get_face(const recipe *rp)
Definition: recipe.cpp:920
recipe::title
sstring title
Definition: recipe.h:11
AssetTWrapper
Definition: AssetWrapper.h:94