bool complete_building(Unit &u) { if (u.has_attribute(attr_type::building)) { auto &build = u.get_attribute<attr_type::building>(); build.completed = 1.0f; // set ground under a completed building auto target_location = u.location.get(); bool placed_ok = target_location->place(build.completion_state); if (placed_ok) { target_location->set_ground(build.foundation_terrain, 0); } return placed_ok; } return false; }
static void update_ground(Word p ARG_LD) { Functor t = valueTerm(*p); int arity = arityFunctor(t->definition); Word a = &t->arguments[arity]; int ground = TRUE; while(--a >= t->arguments) { if ( !can_share(a PASS_LD) ) { ground = FALSE; break; } } if ( ground ) set_ground(t->definition); }
void BuildAction::update_in_range(unsigned int time, Unit *target_unit) { if (target_unit->has_attribute(attr_type::building)) { auto &build = target_unit->get_attribute<attr_type::building>(); // upgrade floating outlines auto target_location = target_unit->location.get(); if (target_location->is_floating()) { // try to place the object if (target_location->place(object_state::placed)) { // modify ground terrain if (build.foundation_terrain > 0) { target_location->set_ground(build.foundation_terrain, 0); } } else { // failed to start construction this->complete = 1.0f; return; } } // increment building completion build.completed += build_rate * time; this->complete = build.completed; if (this->complete >= 1.0f) { target_location->place(build.completion_state); } } else { this->complete = 1.0f; } // inc frame this->frame += time * this->frame_rate / 2.5f; }