This was SVN commit r2568.

This commit is contained in:
Matei 2005-07-30 21:07:02 +00:00
parent 5cd416d82f
commit 5b1d7b8c4b
2 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,62 @@
#include "stdafx.h"
#include "simplegroup.h"
#include "point.h"
#include "random.h"
#include "map.h"
using namespace std;
SimpleGroup::Element::Element(){
}
SimpleGroup::Element::Element(const std::string& t, int c, float d):
type(t), count(c), distance(d)
{
}
SimpleGroup::Element::~Element() {
}
bool SimpleGroup::Element::place(int cx, int cy, Map* m, Constraint* constr, vector<Object*>& ret) {
int failCount = 0;
for(int i=0; i<count; i++) {
while(true) {
float ang = RandFloat()*2*PI;
float x = cx + distance*cos(ang);
float y = cy + distance*sin(ang);
int ix = (int) x;
int iy = (int) y;
if(m->validT(ix, iy) && constr->allows(m, ix, iy)) {
ret.push_back(new Object(type, 0, x, 0, y, RandFloat()*2*PI));
break;
}
else {
failCount++;
if(failCount > 20) {
return false;
}
}
}
}
return true;
}
bool SimpleGroup::place(Map* m, Constraint* constr, vector<Object*>& ret) {
for(int i=0; i<elements.size(); i++) {
if(!elements[i]->place(x, y, m, constr, ret)) {
return false;
}
}
return true;
}
SimpleGroup::SimpleGroup(vector<SimpleGroup::Element*>& e, int _x, int _y):
elements(e), x(_x), y(_y)
{
}
SimpleGroup::~SimpleGroup(void) {
for(int i=0; i<elements.size(); i++) {
delete elements[i];
}
}

View File

@ -0,0 +1,31 @@
#ifndef __SIMPLEGROUP_H__
#define __SIMPLEGROUP_H__
#include "objectgroupplacer.h"
class SimpleGroup : public ObjectGroupPlacer
{
public:
class Element {
public:
std::string type;
int count;
float distance;
Element::Element();
Element::Element(const std::string& type, int count, float distance);
Element::~Element();
bool place(int cx, int cy, class Map* m, Constraint* constr, std::vector<Object*>& ret);
};
std::vector<Element*> elements;
int x, y;
virtual bool place(class Map* m, Constraint* constr, std::vector<Object*>& ret);
SimpleGroup(std::vector<Element*>& elements, int x, int y);
virtual ~SimpleGroup(void);
};
#endif