File: messages.cpp

package info (click to toggle)
qonk 0.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,076 kB
  • ctags: 2,026
  • sloc: cpp: 14,978; sh: 3,464; makefile: 200
file content (164 lines) | stat: -rw-r--r-- 4,767 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright 2005 by Anthony Liekens anthony@liekens.net

#include "messages.h"
#include "timer.h"
#include "settings.h"
#include "coordinate.h"
#include "extensions.h"
#include "game.h"
#include "canvas.h"

using namespace std;

Message::Message( Uint32 time, string message, Uint32 displayTime, Uint8 r, Uint8 g, Uint8 b ) {
  this->message = string( "[" ) + Timer::getTimeMMSS(time) + "] " + message;
  this->displayTime= displayTime;
  this->r = r;
  this->g = g;
  this->b = b;
}

Message::Message( Uint32 time, string message, Uint32 displayTime, Uint32 color ) {
  this->message = string( "[" ) + Timer::getTimeMMSS(time) + "] " + message;
  this->displayTime = displayTime;
  this->r = getGreen( color );
  this->g = getRed( color );
  this->b = getBlue( color );
}

Message::Message( Uint32 time, string message, Uint8 r, Uint8 g, Uint8 b ) {
  this->message = string( "[" ) + Timer::getTimeMMSS(time) + "] " + message;
  this->displayTime= 10000;
  this->r = r;
  this->g = g;
  this->b = b;
}

Message::Message( Uint32 time, string message, Uint32 color ) {
  this->message = string( "[" ) + Timer::getTimeMMSS(time) + "] " + message;
  this->displayTime = 10000;
  this->r = getGreen( color );
  this->g = getRed( color );
  this->b = getBlue( color );
}

void
Message::render( int &x, int &y, int time) {
  if( time > 0 ) {
    
    // default parameters for showing a message
    
    int dx = Canvas::getFontHeight();
    int alpha = 255;
    
    // fading in a message
    if( time < 500 ) {
      dx = (int)( ( dx * time ) / 600.0 );
      alpha = (int)( ( alpha * time ) / 600.0 );
    }
    
    // fading out a message
    if( time > displayTime - 500 ) {
      int timeleft = displayTime - time;
      dx = (int)( ( dx * timeleft ) / 600.0 );
      alpha = (int)( ( alpha * timeleft ) / 600.0 );
    }
    
    // do we still show ourselves?
    if( time > displayTime ) {
    
      dx = 0;
      alpha = 0;
      
    } else {
    
      Canvas::drawText( x, y - dx, message.c_str(), r, g, b, alpha );
      
    }
    
    y -= dx;
  } 
   // Begin Jacobsen
  if ( time == -1 )
	  Canvas::drawText( x, y , message.c_str(), r, g, b, 255 );
    // End jacobsen
}

Uint32
Message::getDisplayTime() {
  return displayTime;
}
//Jacobsen - added init of fleetStrengthMessage
Messages::Messages() : fleetStrengthMessage(0, "Fleet strength 50%",0x808080) {
}

Messages::~Messages() {
  clear();
}

void
Messages::addMessage( Uint32 time, Message m ) {
  insert( pair< Uint32, Message>( time, m ) );
}

void
Messages::cleanup(Uint32 time) {
  while( ( size() > 0 ) && ( begin()->first + begin()->second.getDisplayTime() < time ) )
    erase( begin() );
}

void
Messages::render(Uint32 time) {
  cleanup(time);
  int x = 12; 
  int y = Settings::getGameHeight() - 28;
  for( reverse_iterator i = rbegin(); i != rend(); i++ ) {
    i->second.render(x, y, (int)time - (int)i->first );
  }
  
  //Begin Jacobsen
  x = Settings::getGameWidth() - 80; 
  y = Settings::getGameHeight() - 28;
  fleetStrengthMessage.render(x,y,-1);
  //End Jacobsen
}

//Begin Jacobsen
void Messages::setFleetStrengthMessage( Message m ) {
	fleetStrengthMessage = m;
}
//End Jacobsen

void
MSGwon(Game *game, int nextPlanets, int nextComputerPlayers){
  Uint32 time = game->getTime();
	game->addMessage(200, Message(time, "You have QONKuered the solar system! You won!", 20000, 0xffffff ) );
	stringstream s;
	s << "Try again, with " << nextPlanets << " planets and " << nextComputerPlayers << " AI players!";
	game->addMessage(400, Message(time, s.str(), 20000, 0x808080 ) );

  s.str("");
  s << "Use [" << Settings::getAsString(GA_NEXT_ROUND);
  s << "] to start the next round";

	game->addMessage(600, Message(time, s.str(), 40000, 0x808080 ) );
}

void 
MSGlost(Game *game) {
	Uint32 time = game->getTime();
  game->addMessage(0, Message(time, "GAME OVER!!! You lost all your planets and ships, you are dead!", 20000, 0xffffff ) );
	game->addMessage(200, Message(time, "Press [R] ...", 40000, 0x808080 ) );
}

void 
MSGstart(Game *game) {
  Uint32 time = game->getTime();
  game->addMessage( 000, Message(time, "Let's QONK! Kick the AI players out!", 15000, 0xffffff ) );
  game->addMessage( 200, Message(time, "[Left click and drag] for multi select, [Middle click] for single select.", 10000, 0x808080 ) );
  game->addMessage( 400, Message(time, "[Right click] to send ships.", 10000, 0x808080 ) );
  game->addMessage( 600, Message(time, "[P]ause,[A]ll planets,[R]estart.", 10000, 0x808080 ) );
  game->addMessage( 700, Message(time, "[Escape] to quit", 10000, 0x808080 ) );
  game->addMessage( 800, Message(time, "[1]-[0] fleet selection (10%-100%)", 10000, 0x808080 ) );
  game->addMessage(1000, Message(time, "Initial fleet selection is 50%", 10000, 0x808080 ) );
}