OSDN Git Service

Merge pull request #3569 from sikabane-works/release/3.0.0.88-alpha
[hengbandforosx/hengbandosx.git] / src / wizard / wizard-messages.cpp
1 #include "wizard/wizard-messages.h"
2 #include "game-option/cheat-options.h"
3 #include "game-option/cheat-types.h"
4 #include "io/write-diary.h"
5 #include "system/angband-exceptions.h"
6 #include "view/display-messages.h"
7 #include <array>
8 #include <sstream>
9 #include <string>
10
11 void msg_print_wizard(PlayerType *player_ptr, int cheat_type, std::string_view msg)
12 {
13     constexpr auto max_type = 4;
14     if ((cheat_type < 0) || (cheat_type >= max_type)) {
15         THROW_EXCEPTION(std::logic_error, "Invalid cheat type is specified!");
16     }
17
18     if (!cheat_room && cheat_type == CHEAT_DUNGEON) {
19         return;
20     }
21
22     if (!cheat_peek && cheat_type == CHEAT_OBJECT) {
23         return;
24     }
25
26     if (!cheat_hear && cheat_type == CHEAT_MONSTER) {
27         return;
28     }
29
30     if (!cheat_xtra && cheat_type == CHEAT_MISC) {
31         return;
32     }
33
34     static const std::array<std::string, max_type> cheat_mes = { { "ITEM:", "MONS:", "DUNG:", "MISC:" } };
35     std::stringstream ss;
36     ss << "WIZ-" << cheat_mes[cheat_type] << msg;
37     const auto mes = ss.str();
38     msg_print(mes);
39     if (cheat_diary_output) {
40         exe_write_diary(player_ptr, DiaryKind::WIZARD_LOG, 0, mes);
41     }
42 }
43
44 /*
45  * Display a formatted message, using "vstrnfmt()" and "msg_print()".
46  */
47 void msg_format_wizard(PlayerType *player_ptr, int cheat_type, const char *fmt, ...)
48 {
49     if (!cheat_room && cheat_type == CHEAT_DUNGEON) {
50         return;
51     }
52     if (!cheat_peek && cheat_type == CHEAT_OBJECT) {
53         return;
54     }
55     if (!cheat_hear && cheat_type == CHEAT_MONSTER) {
56         return;
57     }
58     if (!cheat_xtra && cheat_type == CHEAT_MISC) {
59         return;
60     }
61
62     va_list vp;
63     char buf[1024];
64     va_start(vp, fmt);
65     (void)vstrnfmt(buf, 1024, fmt, vp);
66     va_end(vp);
67     msg_print_wizard(player_ptr, cheat_type, buf);
68 }