HEAD: sfllaw/jim's patch for xplc detection broke xplc detection in
[wvapps.git] / twc / src / twcplayerclient.h
bloba6c6ae12f1fe91aac2051bff157b78ac09cde2cb
1 /* -*- Mode: C++ -*- */
2 #ifndef __TWCPLAYERCLIENT_H
3 #define __TWCPLAYERCLIENT_H
5 #include "twcevent.h"
6 #include "twcship.h"
7 #include <uniconf.h>
8 #include <wvlog.h>
9 #include <wvstreamclone.h>
10 #include <wvstringlist.h>
11 #include <wvtcp.h>
13 DeclareWvTable2(IntTable, int);
15 int find_next_unused(const UniConf &cfg);
17 class TWCGameController;
18 class TWCObject;
19 class TWCObjectIf;
21 typedef WvCallback<WvString, WvStringParm> TWCQnACallback;
22 typedef WvCallback<void> TWCEndConvCallback;
24 struct TWCQnA
26 WvString question;
27 WvString answer;
28 WvString default_answer;
29 TWCQnACallback check_answer;
31 TWCQnA(WvStringParm _question, WvStringParm _default_answer,
32 TWCQnACallback _check_answer)
33 : question(_question), default_answer(_default_answer),
34 check_answer(_check_answer) {}
36 DeclareWvList2(TWCConversation, TWCQnA);
39 class TWCPlayerClient
41 protected:
42 WvLog log;
43 TWCObject *location;
45 public:
46 TWCGameController &game;
47 TWCPlayer &player;
49 TWCPlayerClient(TWCGameController &_game, TWCPlayer &_player);
50 virtual ~TWCPlayerClient();
52 virtual void die();
54 // For mostly cosmetic messages.
55 virtual void msg(WvStringParm s) = 0;
56 virtual void msg(WVSTRING_FORMAT_DECL) = 0;
58 virtual void set_location(TWCObject *_location);
60 virtual bool areyousure() { return true; }
62 // For events that take place in a particular sector
63 // i.e. ships docking, warping, fighting, etc.
64 virtual void event(TWCEventType type, int actor, int target,
65 WvStringParm eventmsg) = 0;
66 virtual void weapon_recharged() = 0;
68 virtual WvString try_passwd() = 0;
70 protected:
71 #if 0
72 // twcstardock.cc
73 void starbar_drink();
74 void starbar_grub();
75 void starbar_talk();
76 void starbar_eavesdrop();
77 void starbar_visit();
78 void starbar_underground();
79 void sell_ship(int ship);
80 #endif
84 class TWCHumanPlayerClient: public WvStreamClone, public TWCPlayerClient
86 protected:
87 TWCObjectIf *interface;
89 public:
90 TWCHumanPlayerClient(WvTCPConn *tcp, TWCGameController &_game,
91 TWCPlayer &_player);
92 virtual ~TWCHumanPlayerClient();
94 virtual void die();
96 virtual void msg(WvStringParm s) { print(s); }
97 virtual void msg(WVSTRING_FORMAT_DECL)
98 { print(WvString(WVSTRING_FORMAT_CALL)); }
100 virtual void set_location(TWCObject *_location);
102 char *continue_getline();
103 int get_int(bool &abort, int dflt = 0);
104 void quit();
106 int menu(const IntTable &items, WvStringParm prompt);
108 virtual bool areyousure();
109 virtual void weapon_recharged()
110 { print("\nYour ship's weapon has recharged.\n"); }
112 virtual void event(TWCEventType type, int actor, int target,
113 WvStringParm eventmsg);
114 bool new_ship(bool first_ship);
116 void print_ships_menu(const TWCShipList &ships, WvStringParm prompt);
117 TWCShip *ship_menu(const TWCShipList &ships, WvStringParm prompt);
118 TWCShip *acquire_target(WvStringParm prompt, WvStringParm docked);
120 virtual WvString try_passwd();
122 void display_inventory(TWCShip *ship, bool menu = false);
124 void do_conversation(TWCConversation &_conv, TWCEndConvCallback _endconv);
125 void do_conversation_callback(WvStream &, void *);
127 private:
128 bool create_new_interface;
129 TWCConversation conv;
130 TWCEndConvCallback endconv;
132 virtual void execute();
133 void send_question();
136 DeclareWvList(TWCPlayerClient);
137 DeclareWvDict(TWCPlayerClient, int, player.id);
138 DeclareWvDict(TWCHumanPlayerClient, int, player.id);
140 #endif // __TWCPLAYERCLIENT_H