Skip to content
Open

1 #1

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
d8f194c
1
Sep 12, 2021
6cc00ea
2
Avshugan Sep 12, 2021
39011a9
3
Avshugan Sep 12, 2021
c2f1ab7
4
Avshugan Sep 13, 2021
beafef6
5
Avshugan Sep 16, 2021
05c0612
6
Avshugan Sep 17, 2021
4f91e2d
7
Avshugan Sep 18, 2021
35eea7f
8
Sep 19, 2021
c87ec26
9
Avshugan Sep 19, 2021
2c6dc5b
10
Avshugan Sep 21, 2021
ce8ab9c
11
Avshugan Sep 22, 2021
bb22b0c
12
Avshugan Sep 24, 2021
c88b3cc
13
Avshugan Sep 24, 2021
4b70b94
14
Avshugan Sep 25, 2021
74a800f
15
Avshugan Sep 25, 2021
81eba34
16
Avshugan Sep 25, 2021
825dd56
17
Avshugan Sep 25, 2021
1b407c4
18
Avshugan Sep 29, 2021
8f2a5a1
19
Avshugan Sep 29, 2021
c220655
20
Avshugan Sep 30, 2021
b10912e
21
Avshugan Sep 30, 2021
c2c3121
22
Avshugan Sep 30, 2021
0172bbb
23
Avshugan Oct 2, 2021
06553aa
24
Avshugan Oct 3, 2021
7936bd8
25
Avshugan Oct 3, 2021
9f84157
26
Avshugan Oct 4, 2021
be5b79d
27
Avshugan Oct 5, 2021
8192291
28
Avshugan Oct 8, 2021
d1b1b8d
29
Avshugan Oct 10, 2021
16bd266
30
Avshugan Oct 11, 2021
84602a1
31
Avshugan Oct 13, 2021
e2c280a
32
Avshugan Oct 15, 2021
974d436
33
Avshugan Oct 16, 2021
907f809
34
Avshugan Oct 17, 2021
b84a80a
35
Avshugan Oct 21, 2021
2367c15
36
Avshugan Oct 24, 2021
90b60ae
37
Avshugan Oct 24, 2021
1d896ec
38
Avshugan Oct 25, 2021
6ecd91d
39
Avshugan Oct 26, 2021
f8568f3
40
Avshugan Oct 27, 2021
81a1ff1
41
Avshugan Oct 27, 2021
ce3912c
42
Avshugan Oct 27, 2021
2b5c5af
43
Avshugan Oct 28, 2021
0112553
44
Avshugan Oct 28, 2021
5d6dd33
45
Avshugan Oct 28, 2021
c100fc3
46
Avshugan Oct 31, 2021
e3b4f30
47
Avshugan Nov 17, 2021
cbc355b
48
Avshugan Nov 18, 2021
4c702a1
49
Avshugan Nov 18, 2021
1624221
normalMap
Nov 18, 2021
487458a
normalMap1
Nov 18, 2021
6b0b744
51
Avshugan Nov 19, 2021
1b14694
52
Avshugan Nov 19, 2021
9e6ac3b
53
Avshugan Nov 19, 2021
98c35fe
54
Avshugan Nov 24, 2021
01e20e7
55
Avshugan Nov 25, 2021
3ae41ab
56
Avshugan Nov 25, 2021
1a41453
57
Avshugan Nov 25, 2021
cc78f41
58
Avshugan Nov 25, 2021
0d880bb
map and res
Nov 26, 2021
17e7b35
60
Avshugan Nov 26, 2021
16b8787
61
Avshugan Nov 26, 2021
220a743
62
Avshugan Nov 28, 2021
b06d52c
63
Avshugan Nov 28, 2021
503c781
64
Avshugan Nov 28, 2021
baf95a8
65
Avshugan Nov 29, 2021
8955de9
66
Avshugan Nov 30, 2021
61ae640
67
Avshugan Dec 1, 2021
cc8e98c
2 players and otheLand
Dec 2, 2021
6f79b22
69
Avshugan Dec 3, 2021
9b173f2
70
Avshugan Dec 3, 2021
d64bac4
70
Avshugan Dec 11, 2021
a9be3f2
end
Avshugan Dec 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions Controllers/Enums.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#ifndef ENUMS_H
#define ENUMS_H

struct CountInEnums
{
int resources() { return 10; }
};


enum class Contents
{
Resource,
Unit,
Building
};


enum class MainLandscapes
{
Plain,
Mountain,
Tundra,
Snow,
Ice,
Coast,
Desert,
Ocean
};


enum class OtherLandscapes
{
Nothing,
Forest,
Jungles,
Hills,
ForestAndHills,
JunglesAndHills
};


enum class Units
{
Bowman,
Citizen,
Swordsman,
Worker,
};


enum class Resources
{
Fish,
Oil,
Aluminum,
Coal,
Horses,
Gold,
Iron,
Silver,
Stone,
Uranium,
};


enum class Buildings
{
Farm,
FishingBoat,
Fort,
LumberMill,
Mine,
OilWell,
Pasture,
Quarry,
Town,
TradingPost
};


enum class Countries
{
Nothing,
Russia,
America,
China,
England
};

enum class Mod{
Show,
Play
};

#endif // ENUMS_H
67 changes: 67 additions & 0 deletions Controllers/FindUnitWay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "FindUnitWay.h"
#include "iostream"


void OneMove::add_move(Position pos)
{
minimove.push_back(pos);
end = pos;
}

OneMove Way::get_move_in_way(size_t num_move) const{
if(num_move > way.size())
throw std::runtime_error("get_move_in_way(): The path has fewer moves");
return way[num_move];
}

size_t Way::get_count_moves_in_way() const
{
return way.size();
}

void Way::add_move(OneMove move)
{
way.push_back(move);
}

Way FindUnitWay::get_way(class Unit *unit, IMapForFind *map, Position start, Position end)
{
Position go{start};
Way way;
OneMove onemove{start};

int movement_points = unit->get_movement();
if (!movement_points)
movement_points = unit->get_max_movement();
while(go != end)
{
std::vector<Position> neighbors = map->adjacent_cells(go);
Position min_distance{neighbors[0]};
for(size_t i{1}; i < neighbors.size(); ++i)
{
Position temp{neighbors[i]};
if(abs(int(temp.y) - int(end.y)) < abs(int(min_distance.y) - int(end.y)))
min_distance = temp;
if(abs(int(temp.y) - int(end.y)) == abs(int(min_distance.y) - int(end.y)))
if(abs(int(temp.x) - int(end.x)) < abs(int(min_distance.x) - int(end.x)))
min_distance = temp;
}
onemove.add_move(min_distance);
onemove.spent_movement_points++;
go = min_distance;
--movement_points;
if(!movement_points)
{
movement_points = unit->get_max_movement();
way.add_move(onemove);
onemove = OneMove{min_distance};
}
}
way.add_move(onemove);
return way;
}

OneMove FindUnitWay::get_first_move(class Unit* unit, IMapForFind* map, Position start, Position end)
{
return get_way(unit, map, start, end).get_move_in_way(0);
}
55 changes: 55 additions & 0 deletions Controllers/FindUnitWay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef FINDUNITWAY_H
#define FINDUNITWAY_H

#include <vector>

#include "../Graphics/Map/IMap.h"
#include "../Graphics/Units/Unit.h"
#include "../IObject.h"


struct OneMove
{
Position start;
Position end;
int spent_movement_points = 0;

/*
* массив который хранит подперемещения в одном перемещении
* первый элемент равняется start
* последний элемент равняется end
*/
std::vector<Position> minimove;

OneMove(Position _start, Position _end,
int _spent_movement_points, std::vector<Position> _minimove)
:start{_start}, end{_end}, spent_movement_points{_spent_movement_points},
minimove{_minimove}
{}
OneMove(Position _start)
:start{_start}, end{_start}
{ minimove.push_back(start); }

void add_move(Position pos);
};


class Way : public IObject
{
std::vector<OneMove> way;
public:
/// number_move с нуля
OneMove get_move_in_way(size_t number_move) const;
size_t get_count_moves_in_way() const;
void add_move(OneMove move);
};


class FindUnitWay : public IObject
{
public:
Way get_way(class Unit* unit, IMapForFind* map, Position start, Position end);
OneMove get_first_move(class Unit* unit, IMapForFind* map, Position start, Position end);
};

#endif // FINDUNITWAY_H
56 changes: 56 additions & 0 deletions Controllers/FindVision.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "FindVision.h"
#include <iostream>


std::vector<Position> FindVision::unit_vision(class Unit* unit, Position pos_unit, IMapForFind* map) const
{
std::vector<Position> res;

std::queue<std::pair<Position, int>> queue;
queue.push({pos_unit, unit->get_vision()});
while(!queue.empty()){
std::pair<Position, int> pair = queue.front();
queue.pop();
if(std::find(res.begin(), res.end(), pair.first) == res.end())
res.push_back(pair.first);

if(pair.second != 0)
for(Position pos : map->adjacent_cells(pair.first))
queue.push({pos, pair.second-1});
}
return res;
}

std::vector<Position> FindVision::town_vision(PlayerTown* town, IMapForFind* map) const
{
std::vector<Position> res;

std::queue<std::pair<Position, int>> queue;
queue.push({town->position_town(), 3});
while(!queue.empty()){
std::pair<Position, int> pair = queue.front();
queue.pop();
if(std::find(res.begin(), res.end(), pair.first) == res.end())
{
Countries country_cell = map->get_cell_country(pair.first);
bool is_visible = false;

if(town->get_country() == country_cell)
is_visible = true;

for(auto pos : map->adjacent_cells(pair.first))
{
country_cell = map->get_cell_country(pos);
if(town->get_country() == country_cell)
is_visible = true;
}
if(is_visible)
res.push_back(pair.first);
}

if(pair.second != 0)
for(Position pos : map->adjacent_cells(pair.first))
queue.push({pos, pair.second-1});
}
return res;
}
20 changes: 20 additions & 0 deletions Controllers/FindVision.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef FINDUNITVISION_H
#define FINDUNITVISION_H

#include <queue>
#include <vector>

#include "Player/PlayerTown.h"
#include "../IObject.h"
#include "../Graphics/Map/IMap.h"
#include "../Graphics/Units/Unit.h"


class FindVision : public IObject
{
public:
std::vector<Position> unit_vision(class Unit* unit, Position pos_unit, IMapForFind* map) const;
std::vector<Position> town_vision(PlayerTown* town, IMapForFind* map) const;
};

#endif // FINDUNITVISION_H
Loading