Crossfire Server, Trunk
GeneralMessageWrapper.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 "GeneralMessageWrapper.h"
14 #include "ResourcesManager.h"
15 
17  auto face = dynamic_cast<const FaceWrapper *> (asset);
18  if (face) {
19  return myWrappedItem->face == face->wrappedItem() ? Uses : DoesntUse;
20  }
21  auto quest = dynamic_cast<const QuestWrapper *>(asset);
22  if (quest && myWrappedItem->quest_code) {
23  std::string name(myWrappedItem->quest_code);
24  size_t len = strlen(quest->wrappedItem()->quest_code);
25  return (name.length() > len && name[len] == ' ' && name.substr(0, len) == quest->wrappedItem()->quest_code) ? Uses : DoesntUse;
26  }
27  return DoesntUse;
28 }
29 
32  AssetWrapper::wasModified(asset, type, extra);
33 }
34 
35 void GeneralMessageWrapper::setTitle(const QString &title) {
36  if (myWrappedItem->title != title) {
37  FREE_AND_COPY_IF(myWrappedItem->title, title.toLocal8Bit().data());
39  }
40 }
41 
42 void GeneralMessageWrapper::setQuest(const QString &quest) {
43  if (myWrappedItem->quest_code != quest) {
44  FREE_AND_COPY_IF(myWrappedItem->quest_code, quest.toLocal8Bit().data());
46  }
47 }
48 
50  if (chance != myWrappedItem->chance) {
53  }
54 }
55 
57  if (myWrappedItem->face != face) {
60  }
61 }
62 
64  auto msg(message);
65  if (!msg.isEmpty() && msg[msg.size() - 1] != '\n') {
66  msg += "\n";
67  }
68  if (myWrappedItem->message != msg) {
69  FREE_AND_COPY_IF(myWrappedItem->message, msg.toLocal8Bit().data());
71  }
72 }
AssetTWrapper< GeneralMessage >::myWrappedItem
GeneralMessage * myWrappedItem
Definition: AssetWrapper.h:104
Face
Definition: face.h:14
GeneralMessageWrapper.h
GeneralMessageWrapper::setMessage
void setMessage(const QString &message)
Definition: GeneralMessageWrapper.cpp:63
AssetWrapper::AssetUpdated
@ AssetUpdated
Definition: AssetWrapper.h:33
GeneralMessageWrapper::message
QString message
Definition: GeneralMessageWrapper.h:34
QuestWrapper
Definition: QuestWrapper.h:66
AssetWrapper::PossibleUse
PossibleUse
Definition: AssetWrapper.h:32
GeneralMessage::title
sstring title
Definition: book.h:48
FREE_AND_COPY_IF
#define FREE_AND_COPY_IF(sv, nv)
Definition: global.h:206
quest
Definition: quest.py:1
FaceWrapper
Definition: FaceWrapper.h:24
GeneralMessage::chance
int chance
Definition: book.h:45
AssetWrapper
Definition: AssetWrapper.h:25
navar-midane_pickup.msg
list msg
Definition: navar-midane_pickup.py:13
AssetWrapper::ChangeType
ChangeType
Definition: AssetWrapper.h:33
title
Definition: readable.cpp:108
AssetWrapper::Uses
@ Uses
Definition: AssetWrapper.h:32
ResourcesManager.h
GeneralMessageWrapper::myResources
ResourcesManager * myResources
Definition: GeneralMessageWrapper.h:60
GeneralMessage::message
sstring message
Definition: book.h:49
diamondslots.message
string message
Definition: diamondslots.py:57
GeneralMessageWrapper::setFace
void setFace(const Face *face)
Definition: GeneralMessageWrapper.cpp:56
AssetWrapper::wasModified
virtual void wasModified(AssetWrapper *asset, ChangeType type, int extra)
Definition: AssetWrapper.h:78
GeneralMessageWrapper::setChance
void setChance(int chance)
Definition: GeneralMessageWrapper.cpp:49
GeneralMessageWrapper::chance
int chance
Definition: GeneralMessageWrapper.h:32
ResourcesManager::generalMessageModified
void generalMessageModified(GeneralMessage *message)
Definition: ResourcesManager.cpp:257
GeneralMessageWrapper::face
const Face face
Definition: GeneralMessageWrapper.h:33
AssetWrapper::markModified
void markModified(ChangeType change, int extra=0)
Definition: AssetWrapper.h:55
GeneralMessageWrapper::setQuest
void setQuest(const QString &quest)
Definition: GeneralMessageWrapper.cpp:42
AssetWrapper::DoesntUse
@ DoesntUse
Definition: AssetWrapper.h:32
GeneralMessageWrapper::uses
virtual PossibleUse uses(const AssetWrapper *asset, std::string &) const override
Definition: GeneralMessageWrapper.cpp:16
GeneralMessage::face
const Face * face
Definition: book.h:51
GeneralMessageWrapper::setTitle
void setTitle(const QString &title)
Definition: GeneralMessageWrapper.cpp:35
GeneralMessageWrapper::wasModified
virtual void wasModified(AssetWrapper *asset, ChangeType type, int extra) override
Definition: GeneralMessageWrapper.cpp:30
GeneralMessage::quest_code
sstring quest_code
Definition: book.h:50
is_valid_types_gen.type
list type
Definition: is_valid_types_gen.py:25
give.name
name
Definition: give.py:27