adds new files from trunk (merge preparation)
still does not compile!
This commit is contained in:
parent
e433a699a6
commit
055f3dd879
4 changed files with 370 additions and 0 deletions
60
src/attack_prediction.hpp
Normal file
60
src/attack_prediction.hpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* $Id$ */
|
||||
|
||||
#ifndef ATTACK_PREDICTION_H_INCLUDED
|
||||
#define ATTACK_PREDICTION_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
// This encapsulates all we need to know for this combat.
|
||||
struct combatant
|
||||
{
|
||||
// Construct a combatant.
|
||||
// As an optimization, if it has no weapons which could drain,
|
||||
// we can simply never calculate hitpoints > current hp.
|
||||
combatant(unsigned hp, unsigned max_hp, bool slowed,
|
||||
bool could_ever_drain = true);
|
||||
|
||||
// Select a weapon.
|
||||
void set_weapon(unsigned num_attacks, bool drains, bool berserk,
|
||||
bool swarm, bool firststrike);
|
||||
|
||||
// Set effect against this particular opponent.
|
||||
void set_effectiveness(unsigned damage, double hit_chance, bool slows);
|
||||
|
||||
// Fight!
|
||||
void fight(combatant &opponent);
|
||||
|
||||
// Only used in benchmarking.
|
||||
void reset();
|
||||
void print(const char label[], unsigned int battle) const;
|
||||
|
||||
// Resulting probability distribution (may NOT be as large as max_hp)
|
||||
std::vector<double> hp_dist;
|
||||
|
||||
// Resulting chance we were not hit by this opponent (important if
|
||||
// it poisons)
|
||||
double untouched;
|
||||
|
||||
private:
|
||||
// How many attacks? (Matters for swarm).
|
||||
unsigned num_attacks(unsigned int hp) const;
|
||||
|
||||
// Usually uniform, but if we have swarm, then can be different.
|
||||
std::vector<double> hit_chances_;
|
||||
double base_hit_chance_;
|
||||
|
||||
// Starting hitpoints, max hp.
|
||||
unsigned hp_, max_hp_;
|
||||
|
||||
// Are we slowed already? (Halves damage, can't be slowed again).
|
||||
bool slowed_;
|
||||
|
||||
// Weapon stats.
|
||||
unsigned base_num_attacks_, damage_;
|
||||
bool drains_, slows_, berserk_, swarm_, firststrike_;
|
||||
|
||||
// Summary of matrix used to calculate last battle (unslowed & slowed).
|
||||
std::vector<double> summary[2];
|
||||
};
|
||||
|
||||
#endif
|
184
src/loadscreen.cpp
Normal file
184
src/loadscreen.cpp
Normal file
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
Copyright (C) 2005 by Joeri Melis <joeri_melis@hotmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "loadscreen.hpp"
|
||||
|
||||
#include "font.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
|
||||
//#include <iostream>
|
||||
|
||||
#define MIN_PERCENTAGE 0
|
||||
#define MAX_PERCENTAGE 100
|
||||
|
||||
void loadscreen::set_progress(const int percentage, const std::string &text, const bool commit)
|
||||
{
|
||||
/* Saturate percentage. */
|
||||
prcnt_ = percentage < MIN_PERCENTAGE ? MIN_PERCENTAGE: percentage > MAX_PERCENTAGE ? MAX_PERCENTAGE: percentage;
|
||||
/* Set progress bar parameters. */
|
||||
int fcr = 0, fcg = 0, fcb = 255; /* Finished piece. */
|
||||
int lcr = 0, lcg = 0, lcb = 63; /* Leftover piece. */
|
||||
int bcr = 255, bcg = 255, bcb = 255; /* Border color. */
|
||||
int bw = 5; /* Border width. */
|
||||
bw = 2*bw > screen_.getx() ? 0: 2*bw > screen_.gety() ? 0: bw;
|
||||
int scrx = screen_.getx() - 2*bw; /* Available width. */
|
||||
int scry = screen_.gety() - 2*bw; /* Available height. */
|
||||
int pbw = scrx/2; /* Used width. */
|
||||
int pbh = scry/16; /* Used heigth. */
|
||||
int pbx = (scrx - pbw)/2; /* Horizontal location. */
|
||||
int pby = (scry - pbh)/2; /* Vertical location. */
|
||||
surface const gdis = screen_.getSurface();
|
||||
SDL_Rect area;
|
||||
/* Draw top border. */
|
||||
area.x = pbx; area.y = pby;
|
||||
area.w = pbw + 2*bw; area.h = bw;
|
||||
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
|
||||
/* Draw bottom border. */
|
||||
area.x = pbx; area.y = pby + pbh + bw;
|
||||
area.w = pbw + 2*bw; area.h = bw;
|
||||
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
|
||||
/* Draw left border. */
|
||||
area.x = pbx; area.y = pby + bw;
|
||||
area.w = bw; area.h = pbh;
|
||||
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
|
||||
/* Draw right border. */
|
||||
area.x = pbx + pbw + bw; area.y = pby + bw;
|
||||
area.w = bw; area.h = pbh;
|
||||
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
|
||||
/* Draw the finished bar area. */
|
||||
area.x = pbx + bw; area.y = pby + bw;
|
||||
area.w = (prcnt_ * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.h = pbh;
|
||||
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,fcr,fcg,fcb));
|
||||
/* Draw the leftover bar area. */
|
||||
area.x = pbx + bw + (prcnt_ * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.y = pby + bw;
|
||||
area.w = ((MAX_PERCENTAGE - prcnt_) * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.h = pbh;
|
||||
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,lcr,lcg,lcb));
|
||||
/* Clear the last text and draw new if text is provided. */
|
||||
if(text.length()>0)
|
||||
{
|
||||
SDL_FillRect(gdis,&textarea_,SDL_MapRGB(gdis->format,0,0,0));
|
||||
textarea_ = font::line_size(text, font::SIZE_NORMAL);
|
||||
textarea_.x = scrx/2 + bw - textarea_.w / 2;
|
||||
textarea_.y = pby + pbh + 4*bw;
|
||||
textarea_ = font::draw_text(&screen_,textarea_,font::SIZE_NORMAL,font::NORMAL_COLOUR,text,textarea_.x,textarea_.y);
|
||||
}
|
||||
/* Flip the double buffering so the change becomes visible */
|
||||
if(commit)
|
||||
{
|
||||
SDL_Flip(gdis);
|
||||
}
|
||||
}
|
||||
|
||||
void loadscreen::increment_progress(const int percentage, const std::string &text, const bool commit) {
|
||||
set_progress(prcnt_ + percentage, text, commit);
|
||||
}
|
||||
|
||||
void loadscreen::clear_screen(const bool commit)
|
||||
{
|
||||
int scrx = screen_.getx(); /* Screen width. */
|
||||
int scry = screen_.gety(); /* Screen height. */
|
||||
SDL_Rect area = {0, 0, scrx, scry}; /* Screen area. */
|
||||
surface const disp(screen_.getSurface()); /* Screen surface. */
|
||||
/* Make everything black. */
|
||||
SDL_FillRect(disp,&area,SDL_MapRGB(disp->format,0,0,0));
|
||||
if(commit)
|
||||
{
|
||||
SDL_Flip(disp); /* Flip the double buffering. */
|
||||
}
|
||||
}
|
||||
|
||||
loadscreen *loadscreen::global_loadscreen = 0;
|
||||
|
||||
#define CALLS_TO_FILESYSTEM 112
|
||||
#define PRCNT_BY_FILESYSTEM 20
|
||||
#define CALLS_TO_BINARYWML 9561
|
||||
#define PRCNT_BY_BINARYWML 20
|
||||
#define CALLS_TO_SETCONFIG 306
|
||||
#define PRCNT_BY_SETCONFIG 30
|
||||
#define CALLS_TO_PARSER 50448
|
||||
#define PRCNT_BY_PARSER 20
|
||||
|
||||
void increment_filesystem_progress () {
|
||||
unsigned newpct, oldpct;
|
||||
// Only do something if the variable is filled in.
|
||||
// I am assuming non parallel access here!
|
||||
if (loadscreen::global_loadscreen != 0) {
|
||||
if (loadscreen::global_loadscreen->filesystem_counter == 0) {
|
||||
loadscreen::global_loadscreen->increment_progress(0, "Verifying cache.");
|
||||
}
|
||||
oldpct = (PRCNT_BY_FILESYSTEM * loadscreen::global_loadscreen->filesystem_counter) / CALLS_TO_FILESYSTEM;
|
||||
newpct = (PRCNT_BY_FILESYSTEM * ++(loadscreen::global_loadscreen->filesystem_counter)) / CALLS_TO_FILESYSTEM;
|
||||
//std::cerr << "Calls " << num;
|
||||
if(oldpct != newpct) {
|
||||
//std::cerr << " percent " << newpct;
|
||||
loadscreen::global_loadscreen->increment_progress(newpct - oldpct);
|
||||
}
|
||||
//std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void increment_binary_wml_progress () {
|
||||
unsigned newpct, oldpct;
|
||||
// Only do something if the variable is filled in.
|
||||
// I am assuming non parallel access here!
|
||||
if (loadscreen::global_loadscreen != 0) {
|
||||
if (loadscreen::global_loadscreen->binarywml_counter == 0) {
|
||||
loadscreen::global_loadscreen->increment_progress(0, "Reading cache.");
|
||||
}
|
||||
oldpct = (PRCNT_BY_BINARYWML * loadscreen::global_loadscreen->binarywml_counter) / CALLS_TO_BINARYWML;
|
||||
newpct = (PRCNT_BY_BINARYWML * ++(loadscreen::global_loadscreen->binarywml_counter)) / CALLS_TO_BINARYWML;
|
||||
//std::cerr << "Calls " << num;
|
||||
if(oldpct != newpct) {
|
||||
//std::cerr << " percent " << newpct;
|
||||
loadscreen::global_loadscreen->increment_progress(newpct - oldpct);
|
||||
}
|
||||
//std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void increment_set_config_progress () {
|
||||
unsigned newpct, oldpct;
|
||||
// Only do something if the variable is filled in.
|
||||
// I am assuming non parallel access here!
|
||||
if (loadscreen::global_loadscreen != 0) {
|
||||
if (loadscreen::global_loadscreen->setconfig_counter == 0) {
|
||||
loadscreen::global_loadscreen->increment_progress(0, "Reading unit files.");
|
||||
}
|
||||
oldpct = (PRCNT_BY_SETCONFIG * loadscreen::global_loadscreen->setconfig_counter) / CALLS_TO_SETCONFIG;
|
||||
newpct = (PRCNT_BY_SETCONFIG * ++(loadscreen::global_loadscreen->setconfig_counter)) / CALLS_TO_SETCONFIG;
|
||||
//std::cerr << "Calls " << num;
|
||||
if(oldpct != newpct) {
|
||||
//std::cerr << " percent " << newpct;
|
||||
loadscreen::global_loadscreen->increment_progress(newpct - oldpct);
|
||||
}
|
||||
//std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void increment_parser_progress () {
|
||||
unsigned newpct, oldpct;
|
||||
// Only do something if the variable is filled in.
|
||||
// I am assuming non parallel access here!
|
||||
if (loadscreen::global_loadscreen != 0) {
|
||||
if (loadscreen::global_loadscreen->parser_counter == 0) {
|
||||
loadscreen::global_loadscreen->increment_progress(0, "Reading files and creating cache.");
|
||||
}
|
||||
oldpct = (PRCNT_BY_PARSER * loadscreen::global_loadscreen->parser_counter) / CALLS_TO_PARSER;
|
||||
newpct = (PRCNT_BY_PARSER * ++(loadscreen::global_loadscreen->parser_counter)) / CALLS_TO_PARSER;
|
||||
//std::cerr << "Calls " << loadscreen::global_loadscreen->parser_counter;
|
||||
if(oldpct != newpct) {
|
||||
// std::cerr << " percent " << newpct;
|
||||
loadscreen::global_loadscreen->increment_progress(newpct - oldpct);
|
||||
}
|
||||
//std::cerr << std::endl;
|
||||
}
|
||||
}
|
79
src/loadscreen.hpp
Normal file
79
src/loadscreen.hpp
Normal file
|
@ -0,0 +1,79 @@
|
|||
#ifndef JM_LOADSCREEN_HPP
|
||||
#define JM_LOADSCREEN_HPP
|
||||
|
||||
/*
|
||||
Copyright (C) 2005 by Joeri Melis <joeri_melis@hotmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#include "font.hpp"
|
||||
#include "video.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class loadscreen {
|
||||
public:
|
||||
// Preferred constructor
|
||||
loadscreen(CVideo &screen, const int &percent = 0) :
|
||||
filesystem_counter(0),
|
||||
binarywml_counter(0),
|
||||
setconfig_counter(0),
|
||||
parser_counter(0),
|
||||
screen_(screen), prcnt_(percent)
|
||||
{
|
||||
/* Nothing. */
|
||||
}
|
||||
// Keep default copy constructor
|
||||
// Keep default copy assignment
|
||||
// Destructor, dumps the counter values to stderr
|
||||
~loadscreen()
|
||||
{
|
||||
std::cerr << "loadscreen: filesystem counter = " << filesystem_counter << std::endl;
|
||||
std::cerr << "loadscreen: binarywml counter = " << binarywml_counter << std::endl;
|
||||
std::cerr << "loadscreen: setconfig counter = " << setconfig_counter << std::endl;
|
||||
std::cerr << "loadscreen: parser counter = " << parser_counter << std::endl;
|
||||
}
|
||||
|
||||
// Function to display a load progress bar.
|
||||
void set_progress(const int percentage=0, const std::string &text="", const bool commit=true);
|
||||
// Function to increment the progress bar.
|
||||
void increment_progress(const int percentage=1, const std::string &text="", const bool commit=true);
|
||||
// Function to draw a blank screen.
|
||||
void clear_screen(const bool commit=true);
|
||||
|
||||
// Counters
|
||||
int filesystem_counter;
|
||||
int binarywml_counter;
|
||||
int setconfig_counter;
|
||||
int parser_counter;
|
||||
|
||||
// A global loadscreen instance that can be used to avoid
|
||||
// passing it on to functions that are many levels deep.
|
||||
static loadscreen *global_loadscreen;
|
||||
private:
|
||||
// Prohibit default constructor
|
||||
loadscreen();
|
||||
|
||||
// Data members
|
||||
CVideo &screen_;
|
||||
SDL_Rect textarea_;
|
||||
int prcnt_;
|
||||
};
|
||||
|
||||
// Global accessible functions that centralize the loadscreen related work.
|
||||
void increment_filesystem_progress();
|
||||
void increment_binary_wml_progress();
|
||||
void increment_set_config_progress();
|
||||
void increment_parser_progress();
|
||||
|
||||
#endif
|
47
src/loadscreen_empty.cpp
Normal file
47
src/loadscreen_empty.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
Copyright (C) 2005 by Joeri Melis <joeri_melis@hotmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "loadscreen.hpp"
|
||||
|
||||
#include "font.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
|
||||
//#include <iostream>
|
||||
|
||||
#define MIN_PERCENTAGE 0
|
||||
#define MAX_PERCENTAGE 100
|
||||
|
||||
void loadscreen::set_progress(const int /*percentage*/, const std::string &/*text*/, const bool /*commit*/)
|
||||
{}
|
||||
|
||||
void loadscreen::increment_progress(const int /*percentage*/, const std::string &/*text*/, const bool /*commit*/) {}
|
||||
|
||||
void loadscreen::clear_screen(const bool /*commit*/) {}
|
||||
|
||||
loadscreen *loadscreen::global_loadscreen = 0;
|
||||
|
||||
#define CALLS_TO_FILESYSTEM 112
|
||||
#define PRCNT_BY_FILESYSTEM 20
|
||||
#define CALLS_TO_BINARYWML 9561
|
||||
#define PRCNT_BY_BINARYWML 20
|
||||
#define CALLS_TO_SETCONFIG 306
|
||||
#define PRCNT_BY_SETCONFIG 30
|
||||
#define CALLS_TO_PARSER 50448
|
||||
#define PRCNT_BY_PARSER 20
|
||||
|
||||
void increment_filesystem_progress () {}
|
||||
|
||||
void increment_binary_wml_progress () {}
|
||||
|
||||
void increment_set_config_progress () {}
|
||||
|
||||
void increment_parser_progress () {}
|
Loading…
Add table
Reference in a new issue