Exemplo n.º 1
0
CharString NounStructure::status() const
{
	CharString info;
	info += "\n";

	if ( damage() > 0 )
		info += CharString().format("<color;0000ff>DAMAGE: %d%%</color>\n", (damage() * 100) / maxDamage() );
	if ( workers() != 0 )
		info += CharString().format( "Workers: %s\n", FormatNumber<char,int>( -workers() ).cstr() );
	if ( power() != 0 )
		info += CharString().format( "Power: %s\n", FormatNumber<char,int>( power() ).cstr() );
	if ( technology() != 0 )
		info += CharString().format( "Technology: %d\n", technology() );
	if ( upkeep() != 0 )
		info += CharString().format( "Upkeep: %d\n", upkeep() );

	if ( active() )
	{
		if ( food() != 0 )
			info += CharString().format( "Food: %s\n", FormatNumber<char,int>( food() ).cstr() );
		if ( habitat() != 0 )
			info += CharString().format( "Habitat: %s\n", FormatNumber<char,int>( habitat() ).cstr() );
		if ( mining() != 0 )
			info += CharString().format( "Mining: %s\n", FormatNumber<char,int>( mining() ).cstr() );
		if ( research() != 0 )
			info += CharString().format( "Research: %s\n", FormatNumber<char,int>( research() ).cstr() );
		if ( production() != 0 )
			info += CharString().format( "Production: %s\n", FormatNumber<char,int>( production() ).cstr() );
		if ( protection() != 0.0f )
			info += CharString().format( "PD: %d%%\n", (int)(protection() * 100) );
	}
	else if ( flags() & FLAG_ACTIVE )
	{
		if ( flags() & FLAG_WORKER_SHORT )
			info += "<color;0000ff>WORKER SHORTAGE!</color>\n";
		if ( flags() & FLAG_POWER_SHORT )
			info += "<color;0000ff>POWER SHORTAGE!</color>\n";
		if ( flags() & FLAG_TECH_SHORT )
			info += "<color;0000ff>TECHNOLOGY SHORTAGE!</color>\n";
	}
	else
	{
		info += "\n<color;ffffff>INACTIVE</color>\n";
	}

	if ( isBuilding() )
		info += CharString().format("\nBuilding...%d%% complete\n", buildComplete() );

	return info;
}
Exemplo n.º 2
0
Grammar::Grammar(Language language, const ParserTables &src)
: m_stateMap(stateCoreHashFunction, stateCoreCompareFunction, 4001)
, m_unfinishedSet(1001) {

  m_language      = language;
  m_verboseLevel  = 0;
  m_terminalCount = 0;

  SourcePosition dummyPos;
  for(unsigned int t = 0; t < src.getTerminalCount(); t++) {
    addTerminal(src.getSymbolName(t), TERMINAL, 0, dummyPos);
  }
  for(unsigned int nt = src.getTerminalCount(); nt < src.getSymbolCount(); nt++) {
    addNonTerminal(src.getSymbolName(nt), dummyPos);
  }
  for(unsigned int p = 0; p < src.getProductionCount(); p++) {
    Production production(src.getLeftSymbol(p), dummyPos);
    unsigned int rightSide[256]; // guess there is no more than 256 symbols on the rightside of any Production
    src.getRightSide(p, rightSide);
    for(unsigned int s = 0; s < src.getProductionLength(p); s++) {
      production.m_rightSide.add(RightSideSymbol(rightSide[s], NO_MODIFIER));
    }
    addProduction(production);
  }
}
Exemplo n.º 3
0
void prodListProduction(){
	if(lookahead==NT){
		production(); 
		prodListProduction();
	}
	else if(lookahead==0)
		return;
	else 
		printf("error2");
}
Exemplo n.º 4
0
void firms::set_info()
{	
	vector<double> x;
	x.push_back(1);
	x.push_back(production());
	_rls.update(average_price(), x);
	x.clear();
	x = _rls.get_action();
	int _f = firm_number();
	for (map<int, firm>::iterator i = _firms.begin(); i != _firms.end(); ++i)
	{
		(i->second).set_info(x[0], -x[1], _f);
	}
}
Exemplo n.º 5
0
void prodList(){
	if(lookahead==NT){
		// printf("%s", val);
		// arraylist_add(stringArray,val);
		// arraylist_add(intArray,lookahead);
		//insert(list, val, lookahead);
		//match(NT); NT is nonterminal
		production(); 
		prodListProduction();
	}
	else if(lookahead==EOLN){
		match(EOLN); production; prodListProduction();
	}
}
Exemplo n.º 6
0
int make_prod
    (const Grammar* g, char* new_prod, const char* old_prod, size_t max_size) {
    const char* old_prod_ptr = old_prod;
    const char* prod;
    if(0 != shift_to_first_nonterm(&old_prod_ptr, max_size)) {
        strncpy(new_prod, old_prod, max_size);
        return 0;
    }
    new_prod[0] = '\0';
    strncpy(new_prod, old_prod, old_prod_ptr - old_prod);
    new_prod += old_prod_ptr - old_prod;
    new_prod[0] = '\0';
    new_prod -= old_prod_ptr - old_prod;
    if(0 != production(&prod, g, *old_prod_ptr))
        return -1;
    strcat(new_prod, prod);
    strcat(new_prod, old_prod_ptr + 1);
    return 0;
}
Exemplo n.º 7
0
void firms::write_log(string model_name)
{
	for (map<int, firm>::iterator i = _firms.begin(); i != _firms.end(); ++i)
	{
		(i->second).write_log(model_name, i->first);
		//_log.setfirmaction(i->first, (i->second).getaction());
	}	
	ofstream fout;
	ostringstream fn;
	fn<<model_name<<"_average_price.txt";
	fout.open(fn.str(), ios_base::app);
	fout<<average_price()<<" ";;
	fout.close();
	fn.str("");
	fn<<model_name<<"_average_salary.txt";
	fout.open(fn.str(), ios_base::app);
	fout<<average_salary()<<" ";
	fout.close();
	fn.str("");
	fn<<model_name<<"_gdp.txt";
	fout.open(fn.str(), ios_base::app);
	fout<<gdp()<<" ";
	fout.close();
	fn.str("");
	fn<<model_name<<"_consumption.txt";
	fout.open(fn.str(), ios_base::app);
	fout<<consumption()<<" ";
	fout.close();
	fn.str("");
	fn<<model_name<<"_production.txt";
	fout.open(fn.str(), ios_base::app);
	fout<<production()<<" ";
	fout.close();
	fn.str("");
	fn<<model_name<<"_firm_number.txt";
	fout.open(fn.str(), ios_base::app);
	fout<<firm_number()<<" ";
	fout.close();
	fn.str("");
}
Exemplo n.º 8
0
void Colony::beginTurn()
{
    grow();

    if (hasBuildItem())
    {
        m_buildProgress += production();

        if (m_buildProgress >= m_buildItem->cost())
        {
            m_buildProgress -= m_buildItem->cost();
            m_buildItem->produce(this);
            emit itemFinished(this);
        }
    }
    else
    {
        emit itemFinished(this);
    }

    emit updated();
}
Exemplo n.º 9
0
//--------- Begin of function FirmFactory::next_day ---------//
//
void FirmFactory::next_day()
{
	//----- call next_day() of the base class -----//

	Firm::next_day();

	//----------- update population -------------//

	recruit_worker();

	//-------- train up the skill ------------//

	update_worker();

	//--------- daily manufacturing activities ---------//

	if( info.game_date%PROCESS_GOODS_INTERVAL == firm_recno%PROCESS_GOODS_INTERVAL )
	{
		input_raw();
		production();
		set_next_output_firm();						// set next output firm
	}
}
Exemplo n.º 10
0
double
OpNode::evaluate()
{
    return production(_op, _lchild->evaluate(), _rchild->evaluate());
}