diff --git a/behaviors/hello.cpp b/behaviors/hello.cpp index 5eaf0d1..74ab942 100644 --- a/behaviors/hello.cpp +++ b/behaviors/hello.cpp @@ -6,5 +6,5 @@ extern "C" void think(Action *action, char *memory, const Info *info) { action->type = Action::MOVE; // the Dude will move - action->dir = Dir( std::rand() % 4 ); // the direction of the movement will be random + action->dir = Dir(0);//std::rand() % 4 ); // the direction of the movement will be random } diff --git a/behaviors/hello.dll b/behaviors/hello.dll deleted file mode 100644 index 7ebaead..0000000 Binary files a/behaviors/hello.dll and /dev/null differ diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 017f017..0f3d69f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -42,6 +42,7 @@ void MainWindow::updateSimu() { p_simu->update(); ui->dateLabel->setText(QString::number(++m_date)); + ui->populationLabel->setText(QString::number(p_simu->getPopulation())); ui->drawWidget->updateDudesBehavior(); ui->drawWidget->repaint(); } diff --git a/src/simulation.cpp b/src/simulation.cpp index 5140658..1708507 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -35,22 +35,33 @@ void Simulation::update() { //TODO: check if target pixel is walkable and has no dude Coord spawnPos = p_map->team(i) + Coord(Dir(rand()%4)); - m_dudes.push_back(new Dude(spawnPos,p_map,i)); + Dude *dude = new Dude(spawnPos,p_map,i); + (*p_map)[spawnPos].data.dudePtr = dude; + p_map->updatePixel(spawnPos); + m_dudes.push_back(dude); } } } // TODO finish conversion of handleAction() void Simulation::handleAction(Action *action, Dude *dude){ - Coord targetPos(dude->getPos() + Coord(action->dir)); - Pixel target = p_map->getPixel(targetPos); + Coord currentPos(dude->getPos()); + Coord targetPos(currentPos + Coord(action->dir)); + Pixel source = (*p_map)[currentPos]; + Pixel target = (*p_map)[targetPos]; Dude* targetDude; dude->setSuccess(false); if(action == NULL) return; switch(action->type){ case Action::MOVE: - if (isWalkable(target.type)) - NULL; // TODO: move action + if (isWalkable(target.type) && target.data.dudePtr == NULL){ + source.data.dudePtr = NULL; + target.data.dudePtr = dude; + dude->move(action->dir); + p_map->updatePixel(currentPos); + p_map->updatePixel(targetPos); + std::cout << "Moving to [" << targetPos.x << "," << targetPos.y << "]"<< std::endl; + } break; case Action::ATTACK: if (isDestroyable(target.type)) diff --git a/src/simulation.h b/src/simulation.h index 3566ae8..e7927ff 100644 --- a/src/simulation.h +++ b/src/simulation.h @@ -16,6 +16,7 @@ private: public: Simulation(MapScene *_map, std::vector &_behaviors); MapScene* getMap() { return (MapScene*) p_map; } + int getPopulation(){return m_dudes.size();} /** * @brief update runs one step of simulation diff --git a/src/team.cpp b/src/team.cpp index b71172b..39813b5 100644 --- a/src/team.cpp +++ b/src/team.cpp @@ -32,7 +32,7 @@ void Team::destroySpawn(){ Action* Team::update(Dude *dude) { - Action* action; + Action* action = new Action(); m_behavior(action, dude->getMemory(),(Info*) dude); return action; }