Crossfire Server, Trunk
ArchetypesWrapper.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 "
ArchetypesWrapper.h
"
14
#include "../ResourcesManager.h"
15
16
#include "
assets/AssetOriginAndCreationDialog.h
"
17
18
constexpr
int
csvFieldCount
= 20;
19
const
char
*
csvFields
[
csvFieldCount
] = {
20
"arch_name"
,
21
"hp"
,
22
"maxhp"
,
23
"con"
,
24
"regen"
,
25
"ac"
,
26
"wc"
,
27
"weight"
,
28
"experience"
,
29
"level"
,
30
"suggested_level"
,
31
"damage"
,
32
"speed"
,
33
"dps"
,
34
"sp"
,
35
"maxsp"
,
36
"pow"
,
37
"wis"
,
38
"str"
,
39
"intl"
,
40
};
41
42
void
ArchetypesWrapper::fillMenu
(QMenu *menu) {
43
connect
(menu->addAction(tr(
"Add archetype"
)), &QAction::triggered, [
this
] () {
addArchetype
(); });
44
}
45
46
void
ArchetypesWrapper::addArchetype
() {
47
auto
origins =
myResources
->
archetypeFiles
();
48
auto
keys
=
getManager
()->
archetypes
()->
keys
();
49
50
AssetOriginAndCreationDialog
aqd(
AssetOriginAndCreationDialog::Archetype
,
AssetOriginAndCreationDialog::CreateAsset
,
""
, origins,
keys
);
51
if
(aqd.exec() != QDialog::Accepted) {
52
return
;
53
}
54
55
auto
arch
=
get_archetype_struct
();
56
CLEAR_FLAG
(&
arch
->clone,
FLAG_REMOVED
);
57
arch
->name =
add_string
(aqd.
code
().toStdString().c_str());
58
arch
->clone.name =
add_string
(
arch
->name);
59
getManager
()->
archetypes
()->
define
(
arch
->name,
arch
);
60
myResources
->
assetDefined
(
arch
, aqd.
file
().toStdString());
61
myResources
->
archetypeModified
(
arch
);
62
markModified
(
BeforeChildAdd
,
myAssets
.size());
63
myAssets
.push_back(
myResources
->
wrap
(
arch
,
this
));
64
markModified
(
AfterChildAdd
,
myAssets
.size());
65
}
66
67
void
ArchetypesWrapper::fillCsvHeader
(QString&
contents
)
const
68
{
69
for
(
int
f = 0; f <
csvFieldCount
; f++)
70
contents
.append(f == 0 ?
""
:
";"
).append(
csvFields
[f]);
71
for
(
int
r
= 0;
r
<
NROFATTACKS
;
r
++)
72
contents
.append(
";"
).append(
resist_plus
[
r
]);
73
contents
.append(
"\n"
);
74
}
75
76
void
ArchetypesWrapper::exportAsCSV
(
const
AssetWrapper
*
item
, QString&
contents
)
const
77
{
78
auto
arch
=
const_cast<
ArchetypeWrapper
*
>
(
dynamic_cast<
const
ArchetypeWrapper
*
>
(
item
));
79
auto
object
=
static_cast<
ObjectWrapper
*
>
(
arch
->clone());
80
for
(
int
f = 0; f <
csvFieldCount
; f++)
81
contents
.append(f == 0 ?
""
:
";"
).append(
object
->property(
csvFields
[f]).toString());
82
for
(
int
r
= 0;
r
<
NROFATTACKS
;
r
++)
83
contents
.append(
";"
).append(QString::number(
object
->getObject()->
resist
[
r
]));
84
contents
.append(
"\n"
);
85
}
ArchetypesWrapper::fillMenu
virtual void fillMenu(QMenu *menu) override
Definition:
ArchetypesWrapper.cpp:42
object
Definition:
object.h:282
ArchetypesWrapper::fillCsvHeader
virtual void fillCsvHeader(QString &contents) const
Definition:
ArchetypesWrapper.cpp:67
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition:
archininventory.py:16
AssetWrapper::AfterChildAdd
@ AfterChildAdd
Definition:
AssetWrapper.h:33
get_archetype_struct
archetype * get_archetype_struct(void)
Definition:
arch.cpp:195
ResourcesManager::wrap
ArchetypeWrapper * wrap(archetype *arch, AssetWrapper *parent)
Definition:
ResourcesManager.h:132
ResourcesManager::assetDefined
virtual void assetDefined(const archetype *arch, const std::string &filename) override
Definition:
ResourcesManager.h:101
hall_of_fame.keys
keys
Definition:
hall_of_fame.py:43
ArchetypesWrapper::exportAsCSV
virtual void exportAsCSV(const AssetWrapper *item, QString &contents) const override
Definition:
ArchetypesWrapper.cpp:76
NROFATTACKS
#define NROFATTACKS
Definition:
attack.h:17
getManager
AssetsManager * getManager()
Definition:
assets.cpp:305
AssetsCollection::keys
std::vector< Key > keys() const
Definition:
AssetsCollection.h:183
object::resist
int16_t resist[NROFATTACKS]
Definition:
object.h:351
ArchetypesWrapper.h
csvFieldCount
constexpr int csvFieldCount
Definition:
ArchetypesWrapper.cpp:18
AssetOriginAndCreationDialog::CreateAsset
@ CreateAsset
Definition:
AssetOriginAndCreationDialog.h:25
AssetWrapper::BeforeChildAdd
@ BeforeChildAdd
Definition:
AssetWrapper.h:33
ObjectWrapper
Definition:
ObjectWrapper.h:36
ResourcesManager::archetypeFiles
std::vector< std::string > archetypeFiles() const
Definition:
ResourcesManager.h:111
AssetsCollection::define
T * define(const Key &name, T *asset)
Definition:
AssetsCollection.h:120
AssetWrapper
Definition:
AssetWrapper.h:25
AssetOriginAndCreationDialog.h
add_string
sstring add_string(const char *str)
Definition:
shstr.cpp:124
AssetOriginAndCreationDialog
Definition:
AssetOriginAndCreationDialog.h:21
AssetsManager::archetypes
Archetypes * archetypes()
Definition:
AssetsManager.h:44
resist_plus
const char *const resist_plus[NROFATTACKS]
Definition:
init.cpp:49
ResourcesManager::archetypeModified
void archetypeModified(archetype *arch)
Definition:
ResourcesManager.cpp:214
FLAG_REMOVED
#define FLAG_REMOVED
Definition:
define.h:232
csvFields
const char * csvFields[csvFieldCount]
Definition:
ArchetypesWrapper.cpp:19
item
Definition:
item.py:1
ArchetypeWrapper
Definition:
ArchetypeWrapper.h:25
AssetOriginAndCreationDialog::Archetype
@ Archetype
Definition:
AssetOriginAndCreationDialog.h:24
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition:
define.h:225
AssetWrapper::markModified
void markModified(ChangeType change, int extra=0)
Definition:
AssetWrapper.h:55
givecontents.contents
bool contents
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition:
givecontents.py:19
AssetsCollectionWrapper< archetype >::myAssets
QVector< AssetWrapper * > myAssets
Definition:
AssetsCollectionWrapper.h:41
say.item
dictionary item
Definition:
say.py:149
connect
Definition:
connect.py:1
AssetOriginAndCreationDialog::code
QString code() const
Definition:
AssetOriginAndCreationDialog.h:37
ring_occidental_mages.r
r
Definition:
ring_occidental_mages.py:6
ArchetypesWrapper::addArchetype
void addArchetype()
Definition:
ArchetypesWrapper.cpp:46
AssetOriginAndCreationDialog::file
QString file() const
Definition:
AssetOriginAndCreationDialog.h:38
ArchetypesWrapper::myResources
ResourcesManager * myResources
Definition:
ArchetypesWrapper.h:46
crossfire-crossfire-server
utils
cre
archetypes
ArchetypesWrapper.cpp
Generated by
1.8.17