void MenuCreateTower::appearance()
{
	setVisible( true );
	hideConfirmButton();
	runEvent( "appearance" );
	_disabled = false;
	ScoreCounter::shared().observer( kScoreLevel ).add( _ID, std::bind( &MenuCreateTower::onChangeMoney, this, std::placeholders::_1 ) );
	changeCost();
	onChangeMoney( ScoreCounter::shared().getMoney( kScoreLevel ) );
	scheduleUpdate();
}
void router::run()
{
	printf("From %s: router::run called.\n",_name);
	pa3Map::iterator nt_it;
	unsigned long nbrIPprf;
	_dv_table.insert(pa3Map::value_type(toPrefix(_myIP), 0));
	for (nt_it = _nbr_table.begin(); nt_it != _nbr_table.end(); nt_it++)
	{
		nbrIPprf = toPrefix((*nt_it).first);
/*		if ((nbrIP.S_un.S_addr>>8) != (_myIP.S_un.S_addr>>8))// from other AS?
		{
//			nbrIP.S_un.S_addr != 0x80000000; this may not work
		}	*/
		_dv_table.insert(pa3Map::value_type(nbrIPprf, (*nt_it).second));
		_fwd_table.insert(IFWMap::value_type(nbrIPprf, (*nt_it).first));
	}
	printf("initial DV..");
	printDV();
	printFT("run");
	propaganda_DV();

	bool bRun = true;
	while (bRun)
	{
		size_t sz = _pcomm->readMsg(_inbuf, BUFF_SIZE);
		if (sz == 0)
			propaganda_DV();	 
		else
		{
			switch (_inbuf[0])
			{
			case MSGTYPE_HMSG:
				forwrdMsg(&_inbuf[1], sz);
				break;
			case MSGTYPE_RDV:
				updateDV(&_inbuf[1], (sz-1));
				break;
			case MSGTYPE_CCHNG:
				changeCost(&_inbuf[1], (sz-1));
				break;
			case MSGTYPE_CDN:
				downLink(&_inbuf[1], (sz-1));
				break;
			case MSGTYPE_CASDN:
				ASdownLink(&_inbuf[1], (sz-1));
				break;
			case MSGTYPE_CASUP:
				ASupink(&_inbuf[1], (sz-1));
				break;
			case MSGTYPE_CPRNT:
				printFT("MSGTYPE_CPRNT");
				break;
			case MSGTYPE_CQUIT:
				bRun = false;
				break;
			case MSGTYPE_CPRNT_DV:
				printDV();
				break;
			case MSGTYPE_CPRNT_NT:
				printNT();
				break;
			default:
				printf("From %s: unknown message type %d. The message is dropped.\n",_name,_inbuf[0]);
			}
		}
	}
}