OSDN Git Service

Merge branch 'master' of https://github.com/hengband/hengband
[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 "view/display-messages.h"
6 #include <array>
7 #include <sstream>
8 #include <string>
9
10 void msg_print_wizard(PlayerType *player_ptr, int cheat_type, concptr msg)
11 {
12     constexpr auto max_type = 4;
13     if ((cheat_type < 0) || (cheat_type >= max_type)) {
14         throw std::logic_error("Invalid cheat type is specified!");
15     }
16
17     if (!cheat_room && cheat_type == CHEAT_DUNGEON) {
18         return;
19     }
20
21     if (!cheat_peek && cheat_type == CHEAT_OBJECT) {
22         return;
23     }
24
25     if (!cheat_hear && cheat_type == CHEAT_MONSTER) {
26         return;
27     }
28
29     if (!cheat_xtra && cheat_type == CHEAT_MISC) {
30         return;
31     }
32
33     static const std::array<std::string, max_type> cheat_mes = { { "ITEM:", "MONS:", "DUNG:", "MISC:" } };
34     std::stringstream ss;
35     ss << "WIZ-" << cheat_mes[cheat_type] << msg;
36     const auto mes = ss.str();
37     msg_print(mes);
38     if (cheat_diary_output) {
39         exe_write_diary(player_ptr, DIARY_WIZARD_LOG, 0, mes);
40     }
41 }
42
43 /*
44  * Display a formatted message, using "vstrnfmt()" and "msg_print()".
45  */
46 void msg_format_wizard(PlayerType *player_ptr, int cheat_type, concptr fmt, ...)
47 {
48     if (!cheat_room && cheat_type == CHEAT_DUNGEON) {
49         return;
50     }
51     if (!cheat_peek && cheat_type == CHEAT_OBJECT) {
52         return;
53     }
54     if (!cheat_hear && cheat_type == CHEAT_MONSTER) {
55         return;
56     }
57     if (!cheat_xtra && cheat_type == CHEAT_MISC) {
58         return;
59     }
60
61     va_list vp;
62     char buf[1024];
63     va_start(vp, fmt);
64     (void)vstrnfmt(buf, 1024, fmt, vp);
65     va_end(vp);
66     msg_print_wizard(player_ptr, cheat_type, buf);
67 }