summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/acr.cc53
-rw-r--r--crawl-ref/source/message.cc68
-rw-r--r--crawl-ref/source/message.h31
3 files changed, 125 insertions, 27 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 68c291e727..a40ab9fb4e 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -56,6 +56,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <sstream>
+#include <iostream>
#ifdef DOS
#include <dos.h>
@@ -99,6 +100,7 @@
#include "macro.h"
#include "makeitem.h"
#include "maps.h"
+#include "message.h"
#include "misc.h"
#include "monplace.h"
#include "monstuff.h"
@@ -226,16 +228,16 @@ int main( int argc, char *argv[] )
SysEnv.scorefile.clear();
}
- bool game_start = initialise();
+ const bool game_start = initialise();
// override some options for tutorial
init_tutorial_options();
if (game_start || Options.always_greet)
{
- mprf( "Welcome, %s the %s %s.",
- you.your_name,
- species_name( you.species,you.experience_level ),
- you.class_name );
+ mpr_stream << "Welcome, " << you.your_name << " the "
+ << species_name( you.species,you.experience_level )
+ << " " << you.class_name << "."
+ << std::endl;
// Starting messages can go here as this should only happen
// at the start of a new game -- bwr
@@ -310,9 +312,11 @@ int main( int argc, char *argv[] )
Options.tut_just_triggered = true;
// print stats and everything
prep_input();
- int ch = 'x';
- mpr("Press any key to start the tutorial intro, "
- "or Escape to skip it.", MSGCH_TUTORIAL);
+ int ch = 'x';
+ mpr_stream << setchan(MSGCH_TUTORIAL)
+ << "Press any key to start the tutorial intro, "
+ << "or Escape to skip it."
+ << std::endl;
ch = c_getch();
if (ch != ESCAPE)
@@ -2818,10 +2822,6 @@ static void close_door(int door_x, int door_y)
// returns true if a new character
static bool initialise(void)
{
- bool ret;
-
- int i = 0, j = 0; // counter variables {dlb}
-
you.symbol = '@';
you.colour = LIGHTGREY;
@@ -2834,26 +2834,26 @@ static bool initialise(void)
init_monsters(mcolour); // this needs to be way up top {dlb}
init_spell_descs(); // this needs to be way up top {dlb}
+ // Ensure no buffering on the mpr() stream.
+ mpr_stream << std::nounitbuf;
+
// init item array:
- for (i = 0; i < MAX_ITEMS; i++)
+ for (int i = 0; i < MAX_ITEMS; i++)
init_item( i );
// empty messaging string
strcpy(info, "");
- for (i = 0; i < MAX_MONSTERS; i++)
+ for (int i = 0; i < MAX_MONSTERS; i++)
menv[i].reset();
- for (i = 0; i < GXM; i++)
- {
- for (j = 0; j < GYM; j++)
- {
- igrd[i][j] = NON_ITEM;
- mgrd[i][j] = NON_MONSTER;
- env.map[i][j] = 0;
+ igrd.init(NON_ITEM);
+ mgrd.init(NON_MONSTER);
+ env.map.init(0);
+
+ for (int i = 0; i < GXM; i++)
+ for (int j = 0; j < GYM; j++)
env.map_col[i][j].clear();
- }
- }
you.unique_creatures.init(false);
you.unique_items.init(UNIQ_NOT_EXISTS);
@@ -2879,8 +2879,7 @@ static bool initialise(void)
clrscr();
// sets up a new game:
- bool newc = new_game();
- ret = newc; // newc will be mangled later so we'll take a copy --bwr
+ const bool newc = new_game();
if (!newc)
restore_game();
@@ -2934,7 +2933,7 @@ static bool initialise(void)
}
#ifdef CLUA_BINDINGS
- clua.runhook("chk_startgame", "%b", ret);
+ clua.runhook("chk_startgame", "%b", newc);
std::string yname = you.your_name;
read_init_file(true);
strncpy(you.your_name, yname.c_str(), kNameLen);
@@ -2952,7 +2951,7 @@ static bool initialise(void)
crawl_state.need_save = true;
- return (ret);
+ return (newc);
}
// An attempt to tone down berserk a little bit. -- bwross
diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc
index 0438fb3c0f..2bdee01794 100644
--- a/crawl-ref/source/message.cc
+++ b/crawl-ref/source/message.cc
@@ -47,14 +47,82 @@ int New_Message_Count = 0;
static bool suppress_messages = false;
static void base_mpr(const char *inf, int channel, int param);
+// globals controlling message output
+// there must be a better way to do this!
+static bool mpr_stream_silent = false;
+static msg_channel_type mpr_stream_channel = MSGCH_PLAIN;
+static int mpr_stream_param = 0;
+
+std::ostream mpr_stream(new mpr_stream_buf);
+
+setchan::setchan(msg_channel_type chan)
+{
+ m_chan = chan;
+}
+
+setparam::setparam(int param)
+{
+ m_param = param;
+}
+
+std::ostream& operator<<(std::ostream& os, const setchan& sc)
+{
+ mpr_stream_channel = sc.m_chan;
+ return os;
+}
+
+std::ostream& operator<<(std::ostream& os, const setparam& sp)
+{
+ mpr_stream_param = sp.m_param;
+ return os;
+}
+
+mpr_stream_buf::mpr_stream_buf()
+{
+ for ( int i = 0; i < INTERNAL_LENGTH; ++i )
+ internal_buf[0] = 0;
+ internal_count = 0;
+}
+
+// again, can be improved
+int mpr_stream_buf::overflow(int c)
+{
+ if ( c == '\n' )
+ {
+ // null-terminate the string
+ internal_buf[internal_count] = 0;
+
+ if ( !mpr_stream_silent )
+ mpr(internal_buf, mpr_stream_channel, mpr_stream_param);
+
+ internal_count = 0;
+
+ // reset to defaults (channel changing isn't sticky)
+ mpr_stream_channel = MSGCH_PLAIN;
+ mpr_stream_param = 0;
+ }
+ else
+ internal_buf[internal_count++] = c;
+
+ if ( internal_count + 3 > INTERNAL_LENGTH )
+ {
+ mpr("oops, hit overflow", MSGCH_DANGER);
+ internal_count = 0;
+ return std::streambuf::traits_type::eof();
+ }
+ return 0;
+}
+
no_messages::no_messages() : msuppressed(suppress_messages)
{
suppress_messages = true;
+ mpr_stream_silent = true;
}
no_messages::~no_messages()
{
suppress_messages = msuppressed;
+ mpr_stream_silent = msuppressed;
}
static char god_message_altar_colour( char god )
diff --git a/crawl-ref/source/message.h b/crawl-ref/source/message.h
index 3fcf7d881e..96a2094f40 100644
--- a/crawl-ref/source/message.h
+++ b/crawl-ref/source/message.h
@@ -15,6 +15,7 @@
#define MESSAGE_H
#include <string>
+#include <streambuf>
#include "externs.h"
@@ -105,4 +106,34 @@ std::string get_last_messages(int mcount);
int channel_to_colour( int channel, int param = 0 );
+struct setchan
+{
+ setchan(msg_channel_type chan);
+ msg_channel_type m_chan;
+};
+
+struct setparam
+{
+ setparam(int param);
+ int m_param;
+};
+
+std::ostream& operator<<(std::ostream& os, const setchan& sc);
+std::ostream& operator<<(std::ostream& os, const setparam& sp);
+
+class mpr_stream_buf : public std::streambuf
+{
+public:
+ mpr_stream_buf();
+protected:
+ int overflow(int c);
+private:
+ static const int INTERNAL_LENGTH = 500;
+ char internal_buf[500]; // if your terminal is wider than this, too bad
+ int internal_count;
+};
+
+extern std::ostream mpr_stream;
+
+
#endif