Balanced reproduction.

This commit is contained in:
Tim Schubert 2016-01-31 15:29:14 +01:00
parent 75906f2353
commit 9b81e8f460
6 changed files with 211 additions and 19 deletions

View file

@ -233,7 +233,7 @@ void Game::command(std::string input)
{
if (PlayerManager::pm->get_num_players() < 2)
{
prompt << "Please add at least one player, before starting the game.";
prompt << "Please add at least two players, before starting the game.";
}
else if (!this->started)
{

View file

@ -159,12 +159,6 @@ void FieldMeta::regenerate_resources()
this->resources *= 4;
if (this->upgrades[Regeneration_3])
this->resources *= 8;
if (this->upgrades[Reproduction_1])
this->reproduction *= 1.25;
if (this->upgrades[Reproduction_2])
this->reproduction *= 1.50;
if (this->upgrades[Reproduction_2])
this->reproduction *= 2.0;
trigger_event(BOB_FIELDUPDATEEVENT, 0, (void *) this, nullptr);
this->changed = true;
}
@ -525,7 +519,7 @@ void HexagonGrid::handle_event(SDL_Event *event)
if (event->type == BOB_NEXTTURNEVENT || event->type == BOB_NEXTROUNDEVENT)
{
std::default_random_engine generator;
std::normal_distribution<double> distribution(0.0, 1.0);
std::uniform_real_distribution<double> distribution(0.0, 1.0);
std::unordered_set<FieldMeta *> aquired;
for (auto pair : this->fields)
{
@ -535,14 +529,17 @@ void HexagonGrid::handle_event(SDL_Event *event)
for (Uint8 i = 0; i < 6; i++)
{
FieldMeta *neighbor = field->get_neighbor(i);
if (neighbor != nullptr && neighbor->get_owner() == PlayerManager::pm->default_player
&& (neighbor->get_reproduction() > distribution(generator)))
if (neighbor != nullptr && neighbor->get_owner() == PlayerManager::pm->default_player)
{
double reproduction = neighbor->get_reproduction();
if(reproduction > distribution(generator))
{
aquired.insert(neighbor);
}
}
}
}
}
for (auto foo : aquired)
{
foo->set_owner(PlayerManager::pm->get_current());

View file

@ -516,9 +516,9 @@ const std::unordered_map<Upgrade, std::string> UPGRADE_TEXTS(
{Regeneration_1, "Resources yield 2x their base resources per turn."},
{Regeneration_2, "Resources yield 4x their base resources per turn."},
{Regeneration_3, "Resources yield 8x their base resources per turn."},
{Reproduction_1, "Increase the chance for expanding to a new field at the end of the turn by 25%."},
{Reproduction_2, "Increase the chance for expanding to a new field at the end of the turn by 50%."},
{Reproduction_3, "Increase the chance for expanding to a new field at the end of the turn by 75%."},
{Reproduction_1, "Increase the chance for expanding to a new field at the end of the turn by 5%."},
{Reproduction_2, "Increase the chance for expanding to a new field at the end of the turn by 10%."},
{Reproduction_3, "Increase the chance for expanding to a new field at the end of the turn by 20%."},
{Offense_1, "Double your offense."},
{Offense_2, "Double your offense."},
{Offense_3, "Double your offense."},
@ -586,9 +586,6 @@ public:
FieldMeta(HexagonGrid *grid_, Field field_, Player &owner_)
: grid(grid_), field(field_), owner(owner_), changed(true)
{
std::default_random_engine generator;
std::normal_distribution<double> distribution(0.0, 1.0);
this->reproduction = distribution(generator);
this->upgrades = 0;
static std::random_device rd;
std::mt19937 rng(rd());
@ -642,9 +639,11 @@ public:
bool upgrade(Upgrade upgrade);
void handle_event(const SDL_Event *event);
FieldMeta *get_neighbor(Uint8 direction);
double get_reproduction() { return this->reproduction; }
double get_reproduction()
{
return upgrades[Reproduction_1] * 0.05 + upgrades[Reproduction_2] * 0.1 + upgrades[Reproduction_3] * 0.2 + 0.01;
}
private:
double reproduction;
bool changed;
const Field field;
HexagonGrid *grid;

22
src/Pixelmask.h Normal file
View file

@ -0,0 +1,22 @@
//
// Created by tim on 25.01.16.
//
#ifndef BOB_PIXELMASK_H
#define BOB_PIXELMASK_H
#include <SDL2/SDL_pixels.h>
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define rmask 0xff000000
#define gmask 0x00ff0000
#define bmask 0x0000ff00
#define amask 0x000000ff
#else
#define rmask 0x000000ff
#define gmask 0x0000ff00
#define bmask 0x00ff0000
#define amask 0xff000000
#endif
#endif //BOB_PIXELMASK_H

84
src/Wrapper.cpp Normal file
View file

@ -0,0 +1,84 @@
//
// Created by tim on 26.01.16.
//
#include "Wrapper.hpp"
void Renderer::set_target(SDL_Texture *texture)
{
if (SDL_SetRenderTarget(this->renderer, texture) < 0)
{
throw SDL_RendererException();
}
}
void Renderer::copy(SDL_Texture *texture, SDL_Rect *src, SDL_Rect *dst)
{
if (SDL_RenderCopy(this->renderer, texture, src, dst) < 0)
{
throw SDL_RendererException();
}
}
void Renderer::set_blend_mode(SDL_BlendMode mode)
{
if (SDL_SetRenderDrawBlendMode(this->renderer, mode) < 0)
{
throw SDL_RendererException();
}
}
void Renderer::fill_rect(SDL_Rect *rect)
{
if (SDL_RenderFillRect(this->renderer, rect) < 0)
{
throw SDL_Exception("Failed to draw rectangle background!");
}
}
SDL_Point Window::get_size()
{
SDL_Point size;
SDL_GetWindowSize(this->window, &size.x, &size.y);
return size;
}
int Window::get_window_id()
{
return SDL_GetWindowID(this->window);
}
void Renderer::set_draw_color(SDL_Color color)
{
SDL_SetRenderDrawColor(this->renderer, color.r, color.g, color.b, color.a);
}
void Renderer::clear()
{
SDL_RenderClear(this->renderer);
}
void Renderer::present()
{
SDL_RenderPresent(this->renderer);
}
SDL_Point Window::toggle_fullscreen()
{
SDL_DisplayMode dm;
SDL_GetCurrentDisplayMode(SDL_GetWindowDisplayIndex(this->window), &dm);
if (!this->fullscreen)
{
this->fullscreen = true;
SDL_SetWindowSize(this->window, dm.w, dm.h);
SDL_SetWindowFullscreen(this->window, SDL_WINDOW_FULLSCREEN);
}
else
{
this->fullscreen = false;
SDL_SetWindowFullscreen(this->window, 0);
SDL_SetWindowSize(this->window, this->initial_dimensions->w, this->initial_dimensions->h);
SDL_SetWindowPosition(this->window, this->initial_dimensions->x, this->initial_dimensions->y);
}
SDL_Point window_size = {0, 0};
SDL_GetWindowSize(window, &(window_size.x), &(window_size.y));
return window_size;
}

90
src/Wrapper.hpp Normal file
View file

@ -0,0 +1,90 @@
//
// Created by tim on 26.01.16.
//
#ifndef BOB_WRAPPER_H
#define BOB_WRAPPER_H
#include "SDL2/SDL.h"
#include "SDL2/SDL_ttf.h"
#include "Exceptions.hpp"
#include <stdio.h>
#include <string>
#include <cmath>
#include <iostream>
#include <sstream>
SDL_Color operator!(const SDL_Color &color);
class Window
{
private:
SDL_Window *window;
const SDL_Rect *initial_dimensions;
bool fullscreen;
public:
Window(std::string title, SDL_Rect *dimensions, Uint32 flags)
{
this->window = SDL_CreateWindow(title.c_str(), dimensions->x, dimensions->y, dimensions->w, dimensions->h,
flags);
if (this->window == nullptr)
{
SDL_DestroyWindow(this->window);
throw SDL_WindowException();
}
this->initial_dimensions = dimensions;
}
~Window()
{
SDL_DestroyWindow(this->window);
}
SDL_Window *get_window() { return this->window; }
SDL_Point get_size();
SDL_Point toggle_fullscreen();
int get_window_id();
};
class Renderer
{
public:
Renderer(Window *window, int index, Uint32 flags)
{
this->renderer = SDL_CreateRenderer(window->get_window(), index, flags);
if (renderer == nullptr)
{
SDL_DestroyRenderer(this->renderer);
throw SDL_RendererException();
}
}
~Renderer()
{
SDL_DestroyRenderer(this->renderer);
}
SDL_Renderer *get_renderer() { return this->renderer; }
void set_draw_color(SDL_Color color);
void clear();
void present();
void set_target(SDL_Texture *texture);
void copy(SDL_Texture *texture, SDL_Rect *src, SDL_Rect *dst);
void set_blend_mode(SDL_BlendMode mode);
void fill_rect(SDL_Rect *rect);
private:
SDL_Renderer *renderer;
};
#endif //BOB_WRAPPER_H