Exemplo n.º 1
0
void ohoi_entity_event(enum ipmi_update_e       op,
                       ipmi_domain_t            *domain,
                       ipmi_entity_t            *entity,
                       void                     *cb_data)
{
  	struct oh_handler_state *handler = cb_data;
	struct ohoi_handler *ipmi_handler = handler->data;
	int rv;
	int inst=0;
	
	inst=ipmi_entity_get_entity_instance(entity);
	if(inst >=96) {
		inst = inst - 96;
	}
	g_static_rec_mutex_lock(&ipmi_handler->ohoih_lock);			
	switch (op) {
	  	case IPMI_ADDED:
			add_entity_event(domain, entity, handler);
			trace_ipmi_entity("ADDED", inst, entity);

			/* entity presence overall */
			rv = ipmi_entity_add_presence_handler(entity,
							      entity_presence,
							      handler);       		
			if (rv) 
				dbg("ipmi_entity_set_presence_handler: %#x", rv);

			/* hotswap handler */
			rv = ipmi_entity_add_hot_swap_handler(entity,
							      ohoi_hot_swap_cb,
							      cb_data);
			if(rv)
			  	dbg("Failed to set entity hot swap handler");

			/* sensors */
			rv= ipmi_entity_add_sensor_update_handler(entity,
								  ohoi_sensor_event,
								  handler);
			if (rv) {
				dbg("ipmi_entity_set_sensor_update_handler: %#x", rv);
				break;
			}
			/* controls */
			rv = ipmi_entity_add_control_update_handler(entity,
								    ohoi_control_event,
								    handler);
                                                                                
			if (rv) {
				dbg("ipmi_entity_set_control_update_handler: %#x", rv);
				return;
			}                                                                                
			/* inventory (a.k.a FRU) */
			rv = ipmi_entity_add_fru_update_handler(entity,
								ohoi_inventory_event,
								handler);
			if (rv) {
			  	dbg("ipmi_entity_set_fru_update_handler: %#x", rv);
				break;
			}                                                                          
			break;
			
		case IPMI_DELETED:
			delete_entity(handler, entity);
			trace_ipmi_entity("DELETED", inst, entity);
			break;
			
		case IPMI_CHANGED:
			change_entity(handler, entity);
			trace_ipmi_entity("CHANGED", inst, entity);
			break;
		default:
			dbg("Entity: Unknow change?!");
	}
	g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock);	
}
Exemplo n.º 2
0
void inventory_system::configure() {
	system_name = "Inventory";

	// Receive inventory change messages - refresh the inventory list
	subscribe<inventory_changed_message>([this](inventory_changed_message &msg) {
		dirty = true;
	});

	// Receive drop messages
	subscribe<drop_item_message>([this](drop_item_message &msg) {
		if (!entity(msg.id)) return;
		emit(item_claimed_message{msg.id, false});
		delete_component<item_carried_t>(msg.id);
		entity(msg.id)->component<item_t>()->claimed = false;
		entity(msg.id)->assign(position_t{ msg.x, msg.y, msg.z });
		entity_octree.add_node(octree_location_t{msg.x,msg.y,msg.z,msg.id});
		dirty = true;
	});

	// Receive pick-up messages
	subscribe<pickup_item_message>([this](pickup_item_message &msg) {
		if (!entity(msg.id)) return;
		auto pos = entity(msg.id)->component<position_t>();
		if (pos) {
			entity_octree.remove_node(octree_location_t{pos->x,pos->y, pos->z,msg.id});
			delete_component<position_t>(msg.id);
		}
		delete_component<item_stored_t>(msg.id);
		entity(msg.id)->assign(item_carried_t{ msg.loc, msg.collector });
		dirty = true;
		emit(renderables_changed_message{});
	});

	// Receive item destruction messages
	subscribe<destroy_item_message>([this](destroy_item_message &msg) {
		if (!entity(msg.id)) return;
		auto pos = entity(msg.id)->component<position_t>();
		if (pos) {
			entity_octree.remove_node(octree_location_t{pos->x,pos->y, pos->z,msg.id});
			delete_component<position_t>(msg.id);
		}

		delete_entity(msg.id);
	});

	// Receive claim messages - update an item as claimed/unclaimed
	subscribe<item_claimed_message>([] (item_claimed_message &msg) {
		auto e = entity(msg.id);
		if (e) {
			auto item = e->component<item_t>();
			item->claimed = msg.claimed;
		}
	});

	// Receive build requests - claim components and add to the designations list.
	subscribe<build_request_message>([this] (build_request_message &msg) {
		if (!msg.building) return;

		// Claim components, create the designations
		available_building_t building = msg.building.get();

		// Build designation
		building_designation_t designate;
		designate.x = msg.x;
		designate.y = msg.y;
		designate.z = msg.z;
		designate.name = building.name;
		designate.tag = building.tag;
		designate.components = building.components;
    	designate.width = building.width;
    	designate.height = building.height;
    	designate.glyphs = building.glyphs;

		for (const auto &requested_component : building.components) {
			const std::size_t component_id = claim_item_by_reaction_input(requested_component);
			std::cout << "Component [" << requested_component.tag << "] #" << component_id << "\n";
			designate.component_ids.push_back(std::make_pair(component_id, false));
		}

		auto building_template = create_entity()
			->assign(position_t{msg.x, msg.y, msg.z})
			->assign(building_t{ designate.tag, designate.width, designate.height, designate.glyphs, false });
		designate.building_entity = building_template->id;

		designations->buildings.push_back(designate);

        int sx = designate.x;
        int sy = designate.y;
        if (designate.width == 3) --sx;
        if (designate.height == 3) --sy;

		for (int x = sx; x < sx + designate.width; ++x) {
			for (int y=sy; y < sy + designate.height; ++y) {
				const auto idx = mapidx(x,y,camera_position->region_z);
				current_region->tile_flags[idx].set(CONSTRUCTION);
				current_region->tile_vegetation_type[idx] = 0;
                current_region->calc_render(idx);
			}
		}
	});

	subscribe<cancel_build_request_message>([this] (cancel_build_request_message &msg) {
		if (msg.building_entity == 0) return;

		// Unclaim components
		for (auto &d : designations->buildings) {
			if (d.building_entity == msg.building_entity) {
				for (auto &c : d.component_ids) {
					unclaim_by_id(c.first);
					each<position_t, item_carried_t>([&c] (entity_t &carrier, position_t &pos, item_carried_t &carried) {
						if (carrier.id == c.first) {
							emit(drop_item_message{c.first, pos.x, pos.y, pos.z});
						}
					});
				}
			}
		}

		// Remove any settler references to the building
		each<settler_ai_t>([&msg] (entity_t &e, settler_ai_t &ai) {
			if (ai.job_type_major == JOB_CONST && ai.building_target && ai.building_target->building_entity == msg.building_entity) {
				for (auto &c : ai.building_target->component_ids) {
					unclaim_by_id(c.first);
					each<position_t, item_carried_t>([&c] (entity_t &carrier, position_t &pos, item_carried_t &carried) {
						if (carrier.id == c.first) {
							emit(drop_item_message{c.first, pos.x, pos.y, pos.z});
						}
					});
				}
				ai.job_type_major = JOB_IDLE;
				ai.job_status = "Idle";
			}
		});

		// Erase from vector
		designations->buildings.erase(std::remove_if(
			designations->buildings.begin(),
			designations->buildings.end(),
			[&msg] (building_designation_t a) { return a.building_entity == msg.building_entity; }
		), designations->buildings.end());

		// Delete entity
		delete_entity(msg.building_entity);
	});
}