Crossfire Server, Trunk
ArtifactListWrapper.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 "ArtifactListWrapper.h"
14 #include "ResourcesManager.h"
15 #include "CREPixmap.h"
16 #include "faces/FaceWrapper.h"
17 
19  : AssetTWrapper(parent, "ArtifactList", list), myResourcesManager(resourcesManager) {
20 }
21 
23  int count = 0;
24  auto item = myWrappedItem->items;
25  while (item) {
26  count++;
27  item = item->next;
28  }
29  return count;
30 }
31 
33  auto item = myWrappedItem->items;
34  while (index > 0) {
35  index--;
36  item = item->next;
37  }
38  return myResourcesManager->wrap(item, this);
39 }
40 
42  auto item = myWrappedItem->items;
43  int index = 0;
44  while (item) {
45  if (myResourcesManager->wrap(item, this) == child) {
46  return index;
47  }
48  item = item->next;
49  index++;
50  }
51  return -1;
52 }
53 
55  if (dynamic_cast<const FaceWrapper *>(asset) || dynamic_cast<const AnimationWrapper *>(asset)) {
56  return ChildrenMayUse;
57  }
58  return DoesntUse;
59 }
60 
62  if (childIndex(asset) != -1 && type == AssetUpdated) {
64  auto item = myWrappedItem->items;
65  while (item) {
66  myWrappedItem->total_chance += item->chance;
67  item = item->next;
68  }
70  return;
71  }
72  AssetWrapper::wasModified(asset, type, extra);
73 }
AssetTWrapper< artifactlist >::myWrappedItem
artifactlist * myWrappedItem
Definition: AssetWrapper.h:103
ArtifactListWrapper.h
AssetWrapper::AssetUpdated
@ AssetUpdated
Definition: AssetWrapper.h:32
artifactliststruct::total_chance
uint16_t total_chance
Definition: artifact.h:28
ResourcesManager
Definition: ResourcesManager.h:80
AnimationWrapper
Definition: AnimationWrapper.h:24
AssetWrapper::PossibleUse
PossibleUse
Definition: AssetWrapper.h:31
guildoracle.list
list
Definition: guildoracle.py:87
ResourcesManager::wrap
ArchetypeWrapper * wrap(archt *arch, AssetWrapper *parent)
Definition: ResourcesManager.h:126
ArtifactListWrapper::myResourcesManager
ResourcesManager * myResourcesManager
Definition: ArtifactListWrapper.h:44
artifactliststruct::items
struct artifactstruct * items
Definition: artifact.h:30
AssetWrapper::ChildrenMayUse
@ ChildrenMayUse
Definition: AssetWrapper.h:31
FaceWrapper
Definition: FaceWrapper.h:24
AssetWrapper
Definition: AssetWrapper.h:25
ArtifactListWrapper::childrenCount
virtual int childrenCount() const override
Definition: ArtifactListWrapper.cpp:22
ArtifactListWrapper::wasModified
virtual void wasModified(AssetWrapper *asset, ChangeType type, int extra) override
Definition: ArtifactListWrapper.cpp:61
AssetWrapper::ChangeType
ChangeType
Definition: AssetWrapper.h:32
artifactliststruct
Definition: artifact.h:26
disinfect.count
int count
Definition: disinfect.py:7
FaceWrapper.h
ArtifactListWrapper::ArtifactListWrapper
ArtifactListWrapper(AssetWrapper *parent, artifactlist *list, ResourcesManager *resourcesManager)
Definition: ArtifactListWrapper.cpp:18
ResourcesManager.h
item
Definition: item.py:1
ArtifactListWrapper::child
virtual AssetWrapper * child(int) override
Definition: ArtifactListWrapper.cpp:32
AssetWrapper::wasModified
virtual void wasModified(AssetWrapper *asset, ChangeType type, int extra)
Definition: AssetWrapper.h:77
npc_dialog.index
int index
Definition: npc_dialog.py:102
AssetWrapper::markModified
void markModified(ChangeType change, int extra=0)
Definition: AssetWrapper.h:54
ArtifactListWrapper::uses
virtual PossibleUse uses(const AssetWrapper *asset, std::string &) const override
Definition: ArtifactListWrapper.cpp:54
ArtifactListWrapper::childIndex
virtual int childIndex(AssetWrapper *) override
Definition: ArtifactListWrapper.cpp:41
AssetWrapper::DoesntUse
@ DoesntUse
Definition: AssetWrapper.h:31
CREPixmap.h
is_valid_types_gen.type
list type
Definition: is_valid_types_gen.py:25
AssetTWrapper
Definition: AssetWrapper.h:93