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