Crossfire Server, Trunk
Messages.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2020 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 "Messages.h"
14 #include "global.h"
15 
16 template<>
17 GeneralMessage *asset_create(const std::string& name) {
18  auto msg = static_cast<GeneralMessage *>(calloc(1, sizeof(GeneralMessage)));
19  msg->identifier = add_string(name.c_str());
20  return msg;
21 }
22 
23 template<>
25  FREE_AND_CLEAR_STR_IF(item->identifier);
26  FREE_AND_CLEAR_STR_IF(item->message);
27  FREE_AND_CLEAR_STR_IF(item->quest_code);
29  free(item);
30 }
31 
32 Messages::Messages() : m_totalChance(0) {
33 }
34 
36  FREE_AND_COPY_IF(existing->identifier, update->identifier);
37  FREE_AND_COPY_IF(existing->message, update->message);
38  FREE_AND_COPY_IF(existing->quest_code, update->quest_code);
39  FREE_AND_COPY_IF(existing->title, existing->title);
40  m_totalChance -= existing->chance;
41  m_totalChance += update->chance;
42  existing->chance = update->chance;
43  asset_destroy(update);
44 }
45 
47  m_totalChance += asset->chance;
48 }
49 
51  if (!m_totalChance) {
52  return nullptr;
53  }
54 
55  auto msg = m_assets.begin();
56  int weight = (RANDOM() % m_totalChance);
57  while (msg != m_assets.end()) {
58  weight -= msg->second->chance;
59  if (weight < 0)
60  break;
61  msg++;
62  }
63  return msg->second;
64 }
FREE_AND_CLEAR_STR_IF
#define FREE_AND_CLEAR_STR_IF(xyz)
Definition: global.h:200
global.h
GeneralMessage::title
sstring title
Definition: book.h:48
Messages::random
GeneralMessage * random()
Definition: Messages.cpp:50
Messages::Messages
Messages()
Definition: Messages.cpp:32
FREE_AND_COPY_IF
#define FREE_AND_COPY_IF(sv, nv)
Definition: global.h:206
GeneralMessage::message
sstring message
Definition: book.h:49
name
Plugin animator file specs[Config] name
Definition: animfiles.txt:4
GeneralMessage
Definition: book.h:44
GeneralMessage::quest_code
sstring quest_code
Definition: book.h:50
add_string
sstring add_string(const char *str)
Definition: shstr.cpp:124
navar-midane_pickup.msg
list msg
Definition: navar-midane_pickup.py:13
asset_destroy
void asset_destroy(GeneralMessage *item)
Definition: Messages.cpp:24
weight
TIPS on SURVIVING Crossfire is populated with a wealth of different monsters These monsters can have varying immunities and attack types In some of them can be quite a bit smarter than others It will be important for new players to learn the abilities of different monsters and learn just how much it will take to kill them This section discusses how monsters can interact with players Most monsters in the game are out to mindlessly kill and destroy the players These monsters will help boost a player s after he kills them When fighting a large amount of monsters in a single attempt to find a narrower hallway so that you are not being attacked from all sides Charging into a room full of Beholders for instance would not be open the door and fight them one at a time For there are several maps designed for them Find these areas and clear them out All throughout these a player can find signs and books which they can read by stepping onto them and hitting A to apply the book sign These messages will help the player to learn the system One more always keep an eye on your food If your food drops to your character will soon so BE CAREFUL ! NPCs Non Player Character are special monsters which have intelligence Players may be able to interact with these monsters to help solve puzzles and find items of interest To speak with a monster you suspect to be a simply move to an adjacent square to them and push the double ie Enter your and press< Return > You can also use say if you feel like typing a little extra Other NPCs may not speak to but display intelligence with their movement Some monsters can be and may attack the nearest of your enemies Others can be in that they follow you around and help you in your quest to kill enemies and find treasure SPECIAL ITEMS There are many special items which can be found in of these the most important may be the signs all a player must do is apply the handle In the case of the player must move items over the button to hold it down Some of the larger buttons may need very large items to be moved onto before they can be activated Gates and locked but be for you could fall down into a pit full of ghosts or dragons and not be able to get back out Break away sometimes it may be worth a player s time to test the walls of a map for secret doors Fire such as missile weapons and spells you will notice them going up in smoke ! So be careful not to destroy valuable items Spellbooks sometimes a player can learn the other times they cannot There are many different types of books and scrolls out there Improve item have lower weight
Definition: survival-guide.txt:100
asset_create
GeneralMessage * asset_create(const std::string &name)
Definition: Messages.cpp:17
RANDOM
#define RANDOM()
Definition: define.h:644
Messages.h
Messages::m_totalChance
int m_totalChance
Definition: Messages.h:30
Messages::added
virtual void added(GeneralMessage *asset) override
Definition: Messages.cpp:46
item
Definition: item.py:1
AssetsCollection< GeneralMessage >::m_assets
std::map< std::string, GeneralMessage * > m_assets
Definition: AssetsCollection.h:190
GeneralMessage::identifier
sstring identifier
Definition: book.h:47
Messages::replace
virtual void replace(GeneralMessage *existing, GeneralMessage *update) override
Definition: Messages.cpp:35
GeneralMessage::chance
int chance
Definition: book.h:45