
#include "package.h"
#include "misc.h"
#include "globals.h"

#include <sstream>

using namespace std;

void verify_packages_here()
{
	package p;
	istringstream recv_iss(getline());
	bool found = false;
	while (recv_iss >> p.id >> p.to_x >> p.to_y >> p.weight)
	{
		found = true;
		p.x = me.x;
		p.y = me.y;
		available_packages[p.id] = p;
		d("pkg here", p.id, p.to_x, p.to_y, p.weight);
	}
	
	// if this is a base without packages, remove the base from the list
	if (!found)
	{
		for(vector< pair<long, long> >::iterator i = bases.begin(); i != bases.end(); ++i)
		{
			if (i->first == me.x && i->second == me.y)
			{
				bases.erase(i);
				d("erased base at", me.x, me.y);
			}
		}
	}
}

// printing operator
ostream & operator<< (ostream & out, const map<long,package> & p_list)
{
	for(map<long,package>::const_iterator i = p_list.begin(); i != p_list.end(); ++i)
		out << i->second.id << " " << flush;
	return out;
}