summaryrefslogtreecommitdiffstats
path: root/pacman-c++/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pacman-c++/util.cpp')
-rw-r--r--pacman-c++/util.cpp60
1 files changed, 51 insertions, 9 deletions
diff --git a/pacman-c++/util.cpp b/pacman-c++/util.cpp
index eaf18e4..31d2e79 100644
--- a/pacman-c++/util.cpp
+++ b/pacman-c++/util.cpp
@@ -33,7 +33,6 @@ namespace Util
33 delete[] map; 33 delete[] map;
34 } 34 }
35 35
36 // temporary
37 Transmission::map_t createDemoMap() 36 Transmission::map_t createDemoMap()
38 { 37 {
39 Transmission::map_t map = createEmptyMap(); 38 Transmission::map_t map = createEmptyMap();
@@ -67,19 +66,64 @@ namespace Util
67 if (tmpl[y][x] == '#') 66 if (tmpl[y][x] == '#')
68 cur |= Color::none | Transmission::block; 67 cur |= Color::none | Transmission::block;
69 /* this is a simple hack to create areas where no 68 /* this is a simple hack to create areas where no
70 * autoplaced points will be placed (see below) 69 * autoplaced points/actors will be placed (see makePoints)
71 */ 70 */
72 else if (tmpl[y][x] == '.') 71 else if (tmpl[y][x] == '.')
73 cur |= Transmission::point; 72 cur |= Transmission::point;
74 } 73 }
75 } 74 }
75 return map;
76 }
77
78 void placeActors(Transmission::map_t map, unsigned int players, const Color::Color *colors)
79 {
80 int mindistance = 5;
81 /* this outer loop is used if there are no more valid places left
82 * so we can change mindistance
83 */
84 for(unsigned int i = 0; i < players; ++i)
85 {
86 /* get list of valid positions */
87 QList<QPoint> validpos;
88 for (unsigned int x = 0; x < Constants::map_size.width; ++x)
89 {
90 for (unsigned int y = 0; y < Constants::map_size.height; ++y)
91 {
92 Transmission::field_t &cur = map[x][y];
93 if (cur == Transmission::none)
94 validpos.append(QPoint(x, y));
95 }
96 }
97
98 /* place actors at map */
99 for(i = 0; i < players; ++i)
100 {
101 int rand = (int) (validpos.size() * (qrand() / (RAND_MAX + 1.0)));
102 QPoint newpos = validpos.at(rand);
103 map[newpos.x()][newpos.y()] = colors[i] | Transmission::pacman | Transmission::direction_none;
104 validpos.removeAt(rand);
76 105
77 map[0][0] |= Transmission::bonuspoint; 106 QMutableListIterator<QPoint> j(validpos);
78 map[1][0] |= Color::red | Transmission::pacman | Transmission::direction_right; 107 while(j.hasNext())
79 //map[23][0] = Color::blue | Transmission::pacman | Transmission::direction_none; 108 {
80 //map[24][0] = Color::green | Transmission::pacman | Transmission::direction_none; 109 j.next();
81 //map[25][0] = Color::yellow | Transmission::pacman | Transmission::direction_none; 110 QPoint tmp = j.value() - newpos;
111 if (tmp.manhattanLength() < mindistance)
112 j.remove();
113 }
82 114
115 if (validpos.empty())
116 {
117 qWarning() << "There are no more valid positions for actors left on the map";
118 mindistance -= 2;
119 break;
120 }
121 }
122 }
123 }
124
125 void makePoints(Transmission::map_t map)
126 {
83 /* auto place normal points*/ 127 /* auto place normal points*/
84 for (unsigned int x = 0; x < Constants::map_size.width; ++x) 128 for (unsigned int x = 0; x < Constants::map_size.width; ++x)
85 { 129 {
@@ -92,8 +136,6 @@ namespace Util
92 cur = Transmission::none; 136 cur = Transmission::none;
93 } 137 }
94 } 138 }
95
96 return map;
97 } 139 }
98 140
99 Transmission::field_t actorMovementToTransmission(Actor::Movement mov, Transmission::field_t def) 141 Transmission::field_t actorMovementToTransmission(Actor::Movement mov, Transmission::field_t def)