0ad/source/tools/rmgen/simpleplacers.cpp
Matei bd53b14f58 More work on RMS:
- Created binaries/data/mods/official/maps/random folder to store maps
and also moved rmlibrary.js to maps (though perhaps it should be
somewhere in system?).
- RM generator now uses "logical terrains" that can have units attached
to them in addition to textures, for things like forests.
- Added basic clump placer, avoid constraints, layered painter, and
random terrains (each tile is chosen between several options).
- Misc. infrastructure changes.

This was SVN commit r2378.
2005-06-06 07:46:28 +00:00

47 lines
No EOL
1.1 KiB
C++

#include "stdafx.h"
#include "simpleplacers.h"
#include "random.h"
using namespace std;
// ExactPlacer
ExactPlacer::ExactPlacer(CenteredPlacer* centeredPlacer, int x, int y) {
this->centeredPlacer = centeredPlacer;
this->x = x;
this->y = y;
}
ExactPlacer::~ExactPlacer() {
}
bool ExactPlacer::place(Map* m, Constraint* constr, std::vector<Point>& ret) {
return centeredPlacer->place(m, constr, ret, x, y);
}
// MultiPlacer
MultiPlacer::MultiPlacer(CenteredPlacer* centeredPlacer, int numToPlace, int maxFail) {
this->centeredPlacer = centeredPlacer;
this->numToPlace = numToPlace;
this->maxFail = maxFail;
}
MultiPlacer::~MultiPlacer() {
}
bool MultiPlacer::place(Map* m, Constraint* constr, std::vector<Point>& ret) {
int failed = 0;
int placed = 0;
while(placed < numToPlace && failed <= maxFail) {
int x = RandInt(m->size);
int y = RandInt(m->size);
if(constr->allows(m,x,y) && centeredPlacer->place(m, constr, ret, x, y)) {
placed++;
}
else {
failed++;
}
}
return placed == numToPlace;
}