X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/5885f9816965f487fd852a9ea46bbc580c48d317..b75b5632c75f245e59a00775ffbe0affdedf8b6c:/Model/src/bomb.cpp?ds=sidebyside diff --git a/Model/src/bomb.cpp b/Model/src/bomb.cpp index 9bae0a5..82302b0 100644 --- a/Model/src/bomb.cpp +++ b/Model/src/bomb.cpp @@ -10,7 +10,7 @@ Bomb::Bomb(const std::string &_name):Source(_name) out_slots = 1; active = true; open = true; - max_flow = 1; + max_flow = actual_flow = 0.0f; } Bomb::~Bomb() @@ -20,14 +20,17 @@ Bomb::~Bomb() void Bomb::update() { if (updated) return; + actual_flow = 99999; updated = true; send_msg(OUT, MSG_QUERY_MAX_FLOW); } void Bomb::simulate() { - std::cout << name << "::Flujo entregado = " << (active && open)?max_flow:0; + std::cout << name << "::Flujo actual = " << ((active && open)?actual_flow:0) \ + << " de " << max_flow; std::cout << ((active && open)?" (funcionando)":" (apagada)") << std::endl; + updated = false; } bool Bomb::get_output() @@ -46,12 +49,18 @@ void Bomb::recieve_msg(int msg, IConector *who, void *data) // Me preguntan por el flujo máximo. // Primero me actualizo, y luego respondo update(); - float tmp = (active && open)?max_flow:0; + float tmp; + if (active && open) { + tmp = (actual_flowrecieve_msg(MSG_RESPONSE_MAX_FLOW, this, &tmp); } break; case MSG_RESPONSE_MAX_FLOW: { - max_flow = *((float *)data); + float tmp = *((float *)data); + if (tmp < actual_flow) actual_flow = tmp; } break; default: