added basic handling for communication conflict
This commit is contained in:
parent
7ddde5e2ec
commit
8deedd9098
@ -49,6 +49,7 @@ void Dude::update(BehaviorFunction func)
|
||||
{
|
||||
func(&m_action, m_memory, (Info*)this);
|
||||
m_receivedComData = false;
|
||||
memcpy(m_com_data.data, 0, COM_SIZE);
|
||||
}
|
||||
|
||||
PixelType Dude::getNear(Dir d) const
|
||||
|
16
src/dude.h
16
src/dude.h
@ -21,22 +21,30 @@ private:
|
||||
|
||||
public:
|
||||
Dude(const Coord &_pos, Map *_map, int &_team);
|
||||
//general use functions
|
||||
void update(BehaviorFunction func);
|
||||
const Action& getAction() { return m_action; }
|
||||
int getTeam(){ return m_team; }
|
||||
void setSuccess(bool success) { m_success = success; }
|
||||
void setInventory(PixelType item) { m_inventory = item; }
|
||||
|
||||
//life-related function
|
||||
bool isAlive() { return !m_dead; }
|
||||
void perish() { m_dead = true; }
|
||||
|
||||
//movement-related function
|
||||
const Coord& getPos() { return m_pos; }
|
||||
void move(Dir d);
|
||||
void receiveComData(Dir dir, const char *data);
|
||||
void update(BehaviorFunction func);
|
||||
|
||||
//function inherited from Info
|
||||
virtual bool getSuccess() const { return m_success; }
|
||||
virtual PixelType getInventory() const { return m_inventory; }
|
||||
virtual const Com* getCom() const { return m_receivedComData ? &m_com_data : nullptr; }
|
||||
virtual PixelType getNear(Dir d) const;
|
||||
virtual int getInfo(Dir d) const;
|
||||
|
||||
// setter for the variable returned by functions of Info
|
||||
void setSuccess(bool success) { m_success = success; }
|
||||
void setInventory(PixelType item) { m_inventory = item; }
|
||||
void receiveComData(Dir dir, const char *data);
|
||||
};
|
||||
|
||||
#endif // DUDE_H
|
||||
|
@ -195,17 +195,23 @@ void Simulation::handleAction(Dude *dude)
|
||||
{
|
||||
Dude *targetDude = target.data.dudePtr;
|
||||
// TODO check conflicts between writers
|
||||
if(targetDude->getCom() == nullptr){
|
||||
targetDude->receiveComData(Dir((action.dir+2)%4), targetDude->getAction().com_data.data);
|
||||
dude->setSuccess(true);
|
||||
}else
|
||||
dude->setSuccess(false);
|
||||
break;
|
||||
}
|
||||
case LIBRARY:
|
||||
{
|
||||
int offset = (action.com_data.flag & 3)*COM_SIZE;
|
||||
if(action.com_data.flag & Com::READ)
|
||||
if(dude->getCom() == nullptr){
|
||||
dude->receiveComData(action.dir, target.data.knowledge + offset);
|
||||
else
|
||||
{
|
||||
dude->setSuccess(true);
|
||||
}else
|
||||
dude->setSuccess(false);
|
||||
else{
|
||||
memcpy(target.data.knowledge + offset, action.com_data.data, COM_SIZE);
|
||||
dude->setSuccess(true);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user