freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
VirtScreen.cpp
Go to the documentation of this file.
1  /* freg, Free-Roaming Elementary Game with open and interactive world
2  * Copyright (C) 2012-2014 Alexander 'mmaulwurff' Kromm
3  * mmaulwurff@gmail.com
4  *
5  * This file is part of FREG.
6  *
7  * FREG is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * FREG is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with FREG. If not, see <http://www.gnu.org/licenses/>. */
19 
20 /**\file VirtScreen.cpp
21  * \brief This file provides definitions of code common to all freg screens. */
22 
23 #include "VirtScreen.h"
24 #include "Player.h"
25 
28 
29 VirtScreen::VirtScreen(World * const world_, Player * const player_) :
30  w(world_),
31  player(player_),
32  settings(home_path + "freg.ini", QSettings::IniFormat),
33  previousCommand(settings.value("last_command", "moo").toString())
34 {
35  connect( w, SIGNAL(Notify(QString)), SLOT(Notify(QString)),
36  Qt::DirectConnection);
37  connect(player, SIGNAL(Notify(QString)), SLOT(Notify(QString)),
38  Qt::DirectConnection);
39  connect(player, SIGNAL(ShowFile(QString)), SLOT(DisplayFile(QString)));
40  connect(player, SIGNAL(GetFocus(int *, int *, int *)),
41  SLOT(ActionXyz(int *, int *, int *)), Qt::DirectConnection);
42 
43  connect( w, SIGNAL(GetString(QString &)),
44  SLOT(PassString(QString &)), Qt::DirectConnection);
45  connect(player, SIGNAL(GetString(QString &)),
46  SLOT(PassString(QString &)), Qt::DirectConnection);
47 
48  connect(player, SIGNAL(Updated()), SLOT(UpdatePlayer()),
49  Qt::DirectConnection);
50  connect(w, SIGNAL(UpdatedAll()), SLOT(UpdateAll()),
51  Qt::DirectConnection);
52  connect(w, SIGNAL(Moved(int)), SLOT(Move(int)),
53  Qt::DirectConnection);
54  connect(w, SIGNAL(Updated(int, int, int)), SLOT(Update(int, int, int)),
55  Qt::DirectConnection);
56  connect(w, SIGNAL(UpdatedAround(int, int, int, int)),
57  SLOT(UpdateAround(int, int, int, int)),
58  Qt::DirectConnection);
59  connect(w, SIGNAL(UpdatesEnded()), SLOT(UpdatesEnd()),
60  Qt::DirectConnection);
61 
62  connect(player, SIGNAL(Destroyed()), SLOT(DeathScreen()),
63  Qt::DirectConnection );
64 }
65 
67 
68 void VirtScreen::DisplayFile(QString /* path */) {}
69 
70 void VirtScreen::ActionXyz(int * x, int * y, int * z) const {
71  w->Focus(player->X(), player->Y(), player->Z(), x, y, z, player->GetDir());
72 }
73 
74 World * VirtScreen::GetWorld() const { return w; }
75 
76 int VirtScreen::Color(const int kind, const int sub) {
77  switch ( kind ) { // foreground_background
78  case LIQUID: switch ( sub ) {
79  case WATER: return CYAN_BLUE;
80  case SUB_CLOUD: return BLACK_WHITE;
81  case ACID: return GREEN_GREEN;
82  case H_MEAT:
83  case A_MEAT: return BLACK_RED;
84  default: return RED_YELLOW;
85  } break;
86  case FALLING: switch ( sub ) {
87  case WATER: return CYAN_WHITE;
88  case SAND: return YELLOW_WHITE;
89  } // no break;
90  default: switch ( sub ) {
91  default: return WHITE_BLACK;
92  case STONE: return BLACK_WHITE;
93  case GREENERY: return BLACK_GREEN;
94  case WOOD:
95  case SUB_NUT:
96  case SOIL: return BLACK_YELLOW;
97  case SAND: return WHITE_YELLOW;
98  case COAL: return BLACK_WHITE;
99  case IRON: return BLACK_BLACK;
100  case A_MEAT: return WHITE_RED;
101  case H_MEAT: return BLACK_RED;
102  case WATER: return WHITE_CYAN;
103  case GLASS: return BLUE_WHITE;
104  case NULLSTONE: return MAGENTA_BLACK;
105  case MOSS_STONE: return GREEN_WHITE;
106  case ROSE: return RED_GREEN;
107  case CLAY: return WHITE_RED;
108  case PAPER: return MAGENTA_WHITE;
109  case GOLD: return WHITE_YELLOW;
110  case BONE: return MAGENTA_WHITE;
111  case EXPLOSIVE: return WHITE_RED;
112  case DIAMOND: return CYAN_WHITE;
113  case ADAMANTINE: return CYAN_BLACK;
114  case SKY:
115  case STAR: return WHITE_BLACK;
116  case SUB_DUST: return BLACK_BLACK;
117  case FIRE: return RED_YELLOW;
118  case ACID: return GREEN_GREEN;
119  }
120  case DWARF: switch ( sub ) {
121  case ADAMANTINE: return CYAN_BLACK;
122  default: return WHITE_BLUE ;
123  }
124  case RABBIT: return RED_WHITE;
125  case PREDATOR: return RED_BLACK;
126  case TELEGRAPH: return BLUE_BLUE;
127  case MEDKIT: return RED_WHITE;
128  }
129 } // color_pairs Screen::Color(int kind, int sub)
130 
131 char VirtScreen::CharName(const int kind, const int sub) {
132  switch ( static_cast<kinds>(kind) ) {
133  case BUSH: return ';';
134  case DWARF: return '@';
135  case LIQUID: return '~';
136  case GRASS: return ( FIRE == sub ) ? 'f' : '.';
137  case RABBIT: return 'r';
138  case CLOCK: return 'c';
139  case PLATE: return '_';
140  case LADDER: return '^';
141  case PICK: return '\\';
142  case SHOVEL: return '|';
143  case HAMMER: return 'T';
144  case AXE: return '/';
145  case BELL: return 'b';
146  case BUCKET: return 'u';
147  case MAP:
148  case KIND_TEXT: return '?';
149  case PREDATOR: return '!';
150  case WORKBENCH: return '*';
151  case CONVERTER: return 'V';
152  case BOX:
153  case CONTAINER: return '&';
154  case DOOR: return ( STONE == sub ) ? '#' : '\'';
155  case ILLUMINATOR: return 'i';
156  case WEAPON: switch ( sub ) {
157  default: return '/';
158  case STONE: return '.';
159  case SKY: return ' ';
160  case SUB_NUT: return ',';
161  } break;
162  case ARMOUR: return 'A';
163  case HELMET: return 'H';
164  case BOOTS: return 'B';
165  case TELEGRAPH: return 't';
166  case MEDKIT: return '+';
167  case FILTER: return 'F';
168  case INFORMER: return 'I';
169  case RAIN_MACHINE: return 'R';
170  case FALLING: switch ( sub ) {
171  case SAND: return '.';
172  case WATER: return '*';
173  case STONE: return ':';
174  } // no break;
175  case BLOCK: switch ( sub ) {
176  default: return '#';
177  case SOIL: return '.';
178  case WATER: return '~';
179  case GREENERY: return '%';
180  case A_MEAT:
181  case H_MEAT: return ',';
182  case GLASS: return 'g';
183  case ROSE: return ';';
184  case COAL: return '*';
185  case STAR: return '.';
186  case SKY:
187  case AIR: return ' ';
188  } break;
189  case LAST_KIND: break;
190  }
191  Q_UNREACHABLE();
192 } // char VirtScreen::CharName(int kind, int sub)
193 
194 // Define pure virtual functions to simplify debugging
195 void VirtScreen::Update(int, int, int) { Q_UNREACHABLE(); }
196 void VirtScreen::UpdateAll() { Q_UNREACHABLE(); }
197 void VirtScreen::Move(int) { Q_UNREACHABLE(); }
198 void VirtScreen::UpdatePlayer() { Q_UNREACHABLE(); }
199 void VirtScreen::UpdateAround(int, int, int, int) { Q_UNREACHABLE(); }
200 void VirtScreen::Print() { Q_UNREACHABLE(); }
201 void VirtScreen::Notify(QString) const { Q_UNREACHABLE(); }
202 void VirtScreen::PassString(QString &) const { Q_UNREACHABLE(); }
20
Definition: header.h:135
16
Definition: header.h:176
virtual void Update(int x, int y, int z)=0
This is called when block at (x, y, z) should be updated in screen.
Definition: VirtScreen.cpp:195
10
Definition: header.h:170
static char CharName(int kind, int sub)
Definition: VirtScreen.cpp:131
virtual void ActionXyz(int *x, int *y, int *z) const
Used to get player focus coordinates from screen.
Definition: VirtScreen.cpp:70
const QString home_path
Definition: main.cpp:50
32
Definition: header.h:147
29
Definition: header.h:189
Player *const player
Definition: VirtScreen.h:190
27
Definition: header.h:187
6
Definition: header.h:121
31
Definition: header.h:146
28
Definition: header.h:188
World provides global physics and shred connection.
Definition: World.h:52
short Z() const
Definition: Xyz.cpp:30
World * GetWorld() const
Definition: VirtScreen.cpp:74
18
Definition: header.h:178
4
Definition: header.h:164
21
Definition: header.h:181
29
Definition: header.h:144
static int Color(int kind, int sub)
Definition: VirtScreen.cpp:76
0
Definition: header.h:115
26
Definition: header.h:186
dirs GetDir() const
This returns current player direction (see enum dirs in header.h)
Definition: Player.cpp:49
6
Definition: header.h:166
World *const w
Definition: VirtScreen.h:189
21
Definition: header.h:136
27
Definition: header.h:142
virtual void UpdateAll()=0
This is called when all world should be updated in sceen.
Definition: VirtScreen.cpp:196
11
Definition: header.h:126
1
Definition: header.h:116
7 (hominid meat)
Definition: header.h:167
28
Definition: header.h:143
virtual void UpdateAround(int x, int y, int z, int rng)=0
Called when area around xyz with range needs to be updated.
Definition: VirtScreen.cpp:199
7
Definition: header.h:122
int Y() const
Definition: Player.cpp:40
12
Definition: header.h:127
virtual void Notify(QString) const =0
This is called for a notification to be displayed.
Definition: VirtScreen.cpp:201
9
Definition: header.h:124
9
Definition: header.h:169
3
Definition: header.h:163
20
Definition: header.h:180
18
Definition: header.h:133
26
Definition: header.h:141
virtual void UpdatePlayer()=0
Called when some player property needs to be updated in screen.
Definition: VirtScreen.cpp:198
14
Definition: header.h:129
2
Definition: header.h:162
2
Definition: header.h:117
4
Definition: header.h:119
12
Definition: header.h:172
13
Definition: header.h:128
19
Definition: header.h:179
8
Definition: header.h:123
Nothing is LAST_KIND.
Definition: header.h:150
19
Definition: header.h:134
virtual void UpdatesEnd()
This is called when current group of updates is ended.
Definition: VirtScreen.cpp:26
5
Definition: header.h:165
22
Definition: header.h:137
virtual void PassString(QString &) const =0
This is called when string is needed to be received from input.
Definition: VirtScreen.cpp:202
VirtScreen(World *, Player *)
Constructor makes player and world connections.
Definition: VirtScreen.cpp:29
13
Definition: header.h:173
25
Definition: header.h:185
24
Definition: header.h:184
22
Definition: header.h:182
0
Definition: header.h:160
virtual void DisplayFile(QString path)
This shows a file by path.
Definition: VirtScreen.cpp:68
virtual ~VirtScreen()
Definition: VirtScreen.cpp:66
23
Definition: header.h:138
16
Definition: header.h:131
17
Definition: header.h:132
10
Definition: header.h:125
void DeathScreen()
This is called when player is dead, and displayed until respawn.
Definition: VirtScreen.cpp:27
15
Definition: header.h:130
3
Definition: header.h:118
5
Definition: header.h:120
bool Focus(int x, int y, int z, int *x_targ, int *y_targ, int *z_targ, dirs dir) const
False on error, true if focus is received to _targ successfully.
Definition: World.cpp:491
15
Definition: header.h:175
virtual void Print()=0
Prints world. Should not be called not within screen.
Definition: VirtScreen.cpp:200
This class contains information specific to player and interface for manipulating him...
Definition: Player.h:34
30
Definition: header.h:145
8 (animal meat)
Definition: header.h:168
virtual void Move(int)=0
Called when world loaded zone is moved to update world in screen.
Definition: VirtScreen.cpp:197
17
Definition: header.h:177
int X() const
Definition: Player.cpp:36
30
Definition: header.h:190
14
Definition: header.h:174