Example #1
0
//------- Begin of function Town::think_reward --------//
//
// Think about granting the villagers.
//
void Town::think_reward()
{
	if( !has_linked_own_camp )
		return;

	if( accumulated_reward_penalty > 0 )
		return;

	//---- if accumulated_reward_penalty>0, don't grant unless the villagers are near the rebel level ----//

	Nation* ownNation = nation_array[nation_recno];
	int averageLoyalty = average_loyalty();

	if( averageLoyalty < REBEL_LOYALTY + 5 + ownNation->pref_loyalty_concern/10 )		// 35 to 45
	{
		int importanceRating;

		if( averageLoyalty < REBEL_LOYALTY+5 )
			importanceRating = 40+population;
		else
			importanceRating = population;

		if( ownNation->ai_should_spend(importanceRating) )
			reward( COMMAND_AI );
	}
}
Example #2
0
void ActivenessComponent::SendActivenessInfo()
{
    GameMsg_S2C_GetActivenessDataRes response;
    response.m_eSex = (ESexType)m_pRoleAttr->GetSex();
    response.m_nActiveness = m_nActivenessScore;

    std::list<ActivenessRewardConfig> listTempRewardConfig;
    ActivenessDataManager::Instance().GetTargetRewardConfigList(listTempRewardConfig);
    int nRewardIndex = 0;
    for (std::list<ActivenessRewardConfig>::iterator it = listTempRewardConfig.begin(); it != listTempRewardConfig.end(); ++it, ++nRewardIndex)
    {
        ActivenessReward reward(*it);
        reward.m_nRewardIndex = nRewardIndex;
        reward.m_bReceived = HasReceivedReward(reward.m_ActivenessRewardConfig.GetRequireScore());
        response.m_listRewardState.push_back(reward);
    }

    std::list<ActivenessTargetConfig> listTempTarget;
    ActivenessDataManager::Instance().GetTargetConfigList(listTempTarget);
    for (std::list<ActivenessTargetConfig>::iterator it = listTempTarget.begin();
        it != listTempTarget.end(); ++it)
    {
        ActivenessTarget targetProgress(*it);
        targetProgress.SetProgress(m_mapTargetProgress[it->m_nTargetType]);
        response.m_listTargetProgress.push_back(targetProgress);
    }

    m_pRoleNet->SendPlayerMsg(&response);
}
Example #3
0
void Contract::GetContractRow( PyPackedRow* into )
{
    into->SetField( "contractID",			new PyInt(		contractID() ) );
    into->SetField( "issuerID",				new PyInt(		issuerID() ) );
    into->SetField( "issuerCorpID",			new PyInt(		issuerCorpID() ) );
    into->SetField( "type",					new PyInt(		type() ) );
    into->SetField( "availability",			new PyInt(		avail() ) );
    into->SetField( "assigneeID",			new PyInt(		assigneeID() ) );
    into->SetField( "numDays",				new PyInt(		0 ) );
    into->SetField( "startStationID",		new PyInt(		startStationID() ) );
    into->SetField( "endStationID",			new PyInt(		endStationID() ) );
    into->SetField( "startSolarSystemID",   new PyInt(		startSolarSystemID() ) );
    into->SetField( "endSolarSystemID",		new PyInt(		endSolarSystemID() ) );
    into->SetField( "startRegionID",		new PyInt(		startRegionID() ) );
    into->SetField( "endRegionID",			new PyInt(		endRegionID() ) );
    into->SetField( "price",				new PyFloat(	price() ) );
    into->SetField( "reward",				new PyFloat(	reward() ) );
    into->SetField( "collateral",			new PyFloat(	collateral() ) );
    into->SetField( "title",				new PyWString(	title().c_str(), title().length() ) );
    into->SetField( "description",			new PyWString(	description().c_str(), description().length() ) );
    into->SetField( "forCorp",				new PyBool(		forCorp() ) );
    into->SetField( "status",				new PyInt(		status() ) );
    into->SetField( "acceptorID",			new PyInt(		acceptorID() ) );
    into->SetField( "dateIssued",			new PyLong(		dateIssued() ) );
    into->SetField( "dateExpired",			new PyLong(		dateExpired() ) );
    into->SetField( "dateAccepted",			new PyLong(		dateAccepted() ) );
    into->SetField( "dateCompleted",		new PyLong(		dateCompleted() ) );
    into->SetField( "volume",				new PyFloat(	volume() ) );
    into->SetField( "issuerAllianceID",		new PyInt(		issuerAllianceID() ) );
    into->SetField( "issuerWalletKey",		new PyInt(		issuerWalletKey() ) );
    into->SetField( "acceptorWalletKey",	new PyInt(		0 ) );
    into->SetField( "crateID",				new PyInt(		0 ) );
}
Example #4
0
void TXCache::lookup(const void *key, void *data)
{
	status_t r;
	int i;
	t_fetchdata_params p;
	thread_id tid;

restart:
	m_lock.Lock();
	i=findindex(key);
	if(i<0){
		acquire_sem(m_fetchers_sem);
		i=findoldest();
		assert(m_fetcher[i]==0);
		reward(i);	// ceci empêchera i d'être choisi par findoldest() 
					//  dans un autre thread.
		memcpy(getkey(i),key,m_keysize);
		p.txcache=this;
		p.key=key;
		p.data=getdata(i);
		tid=spawn_thread(fetchdata_,"TXCache::fetchdata",
			B_NORMAL_PRIORITY,&p);
		if(tid<B_NO_ERROR){
			printf("spawn_thread failed file=%s line %d\n",__FILE__,__LINE__);
			exit(-1);
		}
		m_fetcher[i]=tid;
		m_lock.Unlock();	// on déverouille. On est protégé par m_fetchers_sem
		wait_for_thread(tid,&r);
		m_lock.Lock();
		m_fetcher[i]=0;
		release_sem(m_fetchers_sem);
	}else{
		tid=m_fetcher[i];
		if(tid){
			m_lock.Unlock();
			wait_for_thread(tid,&r);
			goto restart;
		}
	}
	memcpy(data,getdata(i),m_datasize);
	reward(i);
	m_lock.Unlock();
}
Example #5
0
void GridWorld::applyOn(const DAction& ac)
{
//     LOG_DEBUG(*dstate << " " << ac);
  
    // if we are on a goal, we eat it
    if(last_reward > 0) {
        world[state->x][state->y] = -1;
	
	//and pass to the next
        state->currentGoal++;
        if(state->currentGoal < NBGOALS) {
            state->xgoal = XGOALS[state->currentGoal];
            state->ygoal = YGOALS[state->currentGoal];
        }
    }

    int direction = ac[MOV];
    switch(direction) {
    case 0:
        if(accessible(state->x, state->y - 1))
            state->y --;
        break;
    case 1:
        if(accessible(state->x, state->y + 1))
            state->y ++;
        break;
    case 2:
        if(accessible(state->x - 1, state->y))
            state->x --;
        break;
    case 3:
        if(accessible(state->x + 1, state->y))
            state->x ++;
        break;
    }

    last_reward = reward();
}
Example #6
0
int Unit::think_reward()
{
	Nation* ownNation = nation_array[nation_recno];

	//----------------------------------------------------------//
	// The need to secure high loyalty on this unit is based on:
	// -its skill
	// -its combat level 
	// -soldiers commanded by this unit
	//----------------------------------------------------------//

	if( spy_recno && true_nation_recno() == nation_recno )		// if this is a spy of ours
	{
		return 0;		// Spy::think_reward() will handle this.
	}

	int curLoyalty = loyalty;
	int neededLoyalty;

	//----- if this unit is on a mission ------/

	if( ai_action_id )
	{
		neededLoyalty = UNIT_BETRAY_LOYALTY+10;
	}

	//----- otherwise only reward soldiers and generals ------//

	else if( skill.skill_id == SKILL_LEADING )
	{
		//----- calculate the needed loyalty --------//

		neededLoyalty = commanded_soldier_count()*5 + skill.skill_level;

		if( unit_mode == UNIT_MODE_OVERSEE )		// if this unit is an overseer
		{
			if( loyalty < UNIT_BETRAY_LOYALTY )		// if this unit's loyalty is < betrayel level, reward immediately
			{
				reward(nation_recno);		// reward it immediatley if it's an overseer, don't check ai_should_spend()
				return 1;
			}

			neededLoyalty += 30;
		}

		neededLoyalty = MAX( UNIT_BETRAY_LOYALTY+10, neededLoyalty );		// 10 points above the betray loyalty level to prevent betrayal
		neededLoyalty = MIN( 100, neededLoyalty );
	}
	else
	{
		return 0;
	}

	//------- if the loyalty is already high enough ------//

	if( curLoyalty >= neededLoyalty )
		return 0;

	//---------- see how many cash & profit we have now ---------//

	int rewardNeedRating = neededLoyalty - curLoyalty;

	if( curLoyalty < UNIT_BETRAY_LOYALTY+5 )
		rewardNeedRating += 50;

	if( ownNation->ai_should_spend(rewardNeedRating) )
	{
		reward(nation_recno);
		return 1;
	}

	return 0;
}
Example #7
0
double Controller::update(Angle angle, double speed, double inReward, vec inLmr, int color) {
	if(t%inv_sampling_rate == 0 && !SILENT){
		pi_array = join_rows(pi_array, pin->get_output());
		if(gvlearn_on){
			gv_array = join_rows(gv_array, gvl->w(0));
		}
		if(lvlearn_on){
			for(int i = 0; i < lv_array.size(); i++)
				lv_array.at(i) = join_rows(lv_array.at(i), lvl->w(i));
			ref_array = join_rows(ref_array, lvl->RefPI());
		}
	}
	t++;

	/*** Check, if inward ***/
	if(t > t_home || accum_reward(0) > 1.){
		inward = 1.;
		//printf("t= %u > %u or sum(R)= %g\n", t, t_home, accum_reward(0));
	}

	/*** Path Integration Mechanism ***/
	if(pin_on)
		pin->update(angle, speed);

	if(gvlearn_on && gl_w > 0.)
		pi_w = HV().len() * (1. - expl_factor(0))*(1.-accu(lv_value));
	else
		pi_w = 0.0;
	pi_m =  ((HV().ang()).i() - angle).S();		//NEW PI COMMAND
	if(homing_on && inward!=0.){
		//printf("this should not be! %g\n", inward);
		pi_w = 0.5;
		pi_m = ((HV().ang()).i() - angle).S();
		rand_m = 0.0;//0.25;
	}
	if(pi_w < 0.)
		pi_w = 0.;
	output_hv = pi_w * pi_m;



	/*** Reward and value update ***/
	if(lvlearn_on){
		for(int i = 0; i < num_lv_units; i++)
			lv_value(i) = 1. - exp(-0.5*lvl->eligibility_value(i));
	}
	delta_beta = mu_beta*((1./expl_beta) + lambda * value(0) * expl_factor(0));
	if(beta_on)
		expl_beta += delta_beta;
	if(expl_factor(0) < 0.0001 && delta_beta < 0.01)
		beta_on = false;

	for(int i = 0; i < num_colors; i++){
		if(i == color){
			reward(i) = inReward;
			if(inward==0.){
				value(i) = (reward(i) /*+ accu(lv_value)*/) + disc_factor * value(i);
				if(!const_expl)
					expl_factor(i) = exp(- expl_beta * value(i));
				else
					expl_factor(i) += d_expl_factor(i);
				expl_factor.elem( find(expl_factor > 1.) ).ones();    //clip expl
				expl_factor.elem( find(expl_factor < 0.) ).zeros();   //clip expl
			}
		}
		else{
			reward(i) = 0.0;
		}
	}
	accum_reward += reward;

	/*** Global Vector Learning Circuits TODO ***/
	if(gvlearn_on){
		for(int i = 0; i < num_colors; i++){
			gvl->update(pin->get_output(), reward(i), expl_factor(i));
			cGV.at(i) = (GV(i) - HV());
		}

		gl_w = (1. - inward)*GV(0).len() * (1.-expl_factor(0));
		gl_m = (GV(0).ang() - angle).S();			//NEW GV COMMAND
	}
	//stream << cGV.at(0).ang().deg() << endl;
	output_gv = gl_w * gl_m;

	/*** Local Vector Learning Circuits TODO ***/
	if(lvlearn_on){

		lvl->update(angle, speed, inReward, inLmr);

		rl_m = 0.0;
		rl_w = (1. - inward);
		for(int i = 0; i < num_lv_units; i++){
			//cLV.at(i) = (LV(i) - HV());
			if(inward == 0.){
				gl_w = 0.0;
				pi_w = 0.0;
				rl_m += lv_value(i) * (LV().len()*(LV().ang() - angle).S() + RV().len()*(RV().ang().i() - angle).S());
			}
		}
		//if(VERBOSE && t%100==0)
			//printf("t = %u\tHV = (%f, %f)\tLV = (%f, %f)\tRV = (%f, %f)\n", t, HV().ang().deg(), HV().len(), LV().ang().deg(), LV().len(), RV().ang().deg(), RV().len());
		output_lv = rl_w * rl_m;
	}
	else
		output_lv = 0.;

	/*** Random foraging ***/
	if(lvlearn_on){
		rand_w = (1. - inward)*0.6*expl_factor(0)*(1.-accu(lv_value));
	}
	else
		rand_w = (1. - inward)*0.6*expl_factor(0);
	rand_m = randn(0.0, 1.);
	if(inward == 1)
		rand_m = 0.;

	output_rand = rand_w * rand_m;

	/*** Navigation Control Output ***/
	output = output_rand + output_hv + output_gv + output_lv;
	//output = output_rand + output_hv + 0.0 + output_lv; // Route formation

	return output;
}
Example #8
0
//--------- Begin of function FirmBase::detect_info ---------//
//
void FirmBase::detect_info()
{
	if( detect_basic_info() )
		return;

	if( !should_show_info() )
		return;

	//------ detect the overseer button -----//

	int rc = mouse.any_click(INFO_X1+6, INFO_Y1+58, INFO_X1+5+UNIT_LARGE_ICON_WIDTH, INFO_Y1+57+UNIT_LARGE_ICON_HEIGHT, LEFT_BUTTON) ? 1 
		: mouse.any_click(INFO_X1+6, INFO_Y1+58, INFO_X1+5+UNIT_LARGE_ICON_WIDTH, INFO_Y1+57+UNIT_LARGE_ICON_HEIGHT, RIGHT_BUTTON) ? 2 : 0;

	if( rc==1 )		// display this overseer's info
	{
		selected_worker_id = 0;
		disp_base_info(INFO_Y1+54, INFO_UPDATE);
		disp_worker_list(INFO_Y1+104, INFO_UPDATE);
		disp_worker_info(INFO_Y1+168, INFO_UPDATE);
	}

	//--------- detect soldier info ---------//

	if( detect_worker_list() )
	{
		disp_base_info(INFO_Y1+54, INFO_UPDATE);
		disp_worker_list(INFO_Y1+104, INFO_UPDATE);
		disp_worker_info(INFO_Y1+168, INFO_UPDATE);
	}

	//---------- detect spy button ----------//

	detect_spy_button();

	if( !own_firm() )
		return;

	//------ detect the overseer button -----//

	if( rc==2 )
	{
		if(remote.is_enable())
		{
			// packet structure : <firm recno>
			short *shortPtr=(short *)remote.new_send_queue_msg(MSG_FIRM_MOBL_OVERSEER, sizeof(short));
			shortPtr[0] = firm_recno;
		}
		else
		{
			assign_overseer(0);		// the overseer quits the camp
		}
	}

	//----------- detect invoke -----------//

	if( button_invoke.detect() )
	{
		if(remote.is_enable())
		{
			// ##### begin Gilbert 14/10 #######//
			// packet structure : <firm recno>
			short *shortPtr=(short *)remote.new_send_queue_msg(MSG_F_BASE_INVOKE_GOD, sizeof(short));
			shortPtr[0] = firm_recno;
			// ##### end Gilbert 14/10 #######//
		}
		else
		{
			invoke_god();
		}
	}

	//----------- detect reward -----------//

	if( button_reward.detect() )
	{
		reward(selected_worker_id, COMMAND_PLAYER);
		// ##### begin Gilbert 26/9 ########//
		se_ctrl.immediate_sound("TURN_ON");
		// ##### end Gilbert 26/9 ########//
	}
}
Example #9
0
//[[Rcpp::export]]
Rcpp::List AddDualBounds(const arma::cube& path,
                         Rcpp::NumericVector control_,
                         Rcpp::Function Reward_,
                         Rcpp::Function Scrap_,
                         const arma::cube& mart,
                         const arma::ucube& path_action) {
  // Extract parameters
  const std::size_t n_dec = path.n_slices;
  const std::size_t n_path = path.n_rows;
  const std::size_t n_dim = path.n_cols;
  const arma::ivec c_dims = control_.attr("dim");
  const std::size_t n_pos = c_dims(0);
  const std::size_t n_action = c_dims(1);
  arma::imat control;  // full control
  arma::cube control2;  // partial control
  bool full_control;
  if (c_dims.n_elem == 3) {
    full_control = false;
    arma::cube temp_control2(control_.begin(), n_pos, n_action, n_pos, false);
    control2 = temp_control2;
  } else {
    full_control = true;
    arma::mat temp_control(control_.begin(), n_pos, n_action, false);
    control = arma::conv_to<arma::imat>::from(temp_control);
  }
  // Initialise with scrap value
  arma::cube primals(n_path, n_pos, n_dec);
  primals.slice(n_dec - 1) = Rcpp::as<arma::mat>(
      Scrap_(Rcpp::as<Rcpp::NumericMatrix>(Rcpp::wrap(path.slice(n_dec - 1)))));
  arma::cube duals = primals;
  // Perform the backward induction
  arma::uword policy;
  arma::cube reward(n_path, n_action, n_pos);
  if (full_control) {  // For the full control case
    arma::uword next;
    for (int tt = (n_dec - 2); tt >= 0; tt--) {
      reward = Rcpp::as<arma::cube>(Reward_(
          Rcpp::as<Rcpp::NumericMatrix>(Rcpp::wrap(path.slice(tt))), tt + 1));
#pragma omp parallel for private(policy, next)
      for (std::size_t ii = 0; ii < n_path; ii++) {
        for (std::size_t pp = 0; pp < n_pos; pp++) {
          // Primal values
          policy = path_action(ii, pp, tt) - 1;  // R to C indexing
          next = control(pp, policy) - 1;
          primals(ii, pp, tt) = reward(ii, policy, pp) + mart(ii, next, tt)
              + primals(ii, next, tt + 1);
          // Dual values
          next = control(pp, 0) - 1;
          duals(ii, pp, tt) = reward(ii, 0, pp) + mart(ii, next, tt)
              + duals(ii, next, tt + 1);
          for (std::size_t aa = 1; aa < n_action; aa++) {
            next = control(pp, aa) - 1;
            duals(ii, pp, tt) = std::max(reward(ii, aa, pp) + mart(ii, next, tt)
                         + duals(ii, next, tt + 1), duals(ii, pp, tt));
          }
        }
      }
    }
  } else {  // Positions evolve randomly
    arma::rowvec mod(n_pos);
    arma::rowvec prob_weight(n_pos);
    for (int tt = (n_dec - 2); tt >= 0; tt--) {
      reward = Rcpp::as<arma::cube>(Reward_(
          Rcpp::as<Rcpp::NumericMatrix>(Rcpp::wrap(path.slice(tt))), tt + 1));
#pragma omp parallel for private(policy, prob_weight, mod)
      for (std::size_t ii = 0; ii < n_path; ii++) {
        for (std::size_t pp = 0; pp < n_pos; pp++) {
          //  Primal values
          mod = primals.slice(tt + 1).row(ii) + mart.slice(tt).row(ii);
          policy = path_action(ii, pp, tt) - 1;
          prob_weight = control2.tube(pp, policy);
          primals(ii, pp, tt) =
              reward(ii, policy, pp) + arma::sum(prob_weight % mod);
          // Dual values
          mod = duals.slice(tt + 1).row(ii) + mart.slice(tt).row(ii);
          prob_weight = control2.tube(pp, 0);
          duals(ii, pp, tt) = reward(ii, 0, pp) + arma::sum(prob_weight % mod);
          for (std::size_t aa = 1; aa < n_action; aa++) {
            prob_weight = control2.tube(pp, aa);
            duals(ii, pp, tt) =
                std::max(reward(ii, aa, pp) + arma::sum(prob_weight % mod),
                         duals(ii, pp, tt));
          }
        }
      }
    }
  }
  return Rcpp::List::create(Rcpp::Named("primal") = primals,
                            Rcpp::Named("dual") = duals);
}
Example #10
0
//--------- Begin of function FirmCamp::detect_camp_info ---------//
//
void FirmCamp::detect_camp_info()
{
	int rc;
	if( is_own() )
	{
		//----------- detect patrol -----------//

		if( (rc = button_patrol.detect(0, 0, 1)) )
		{
			if (rc == 2)
			{
				patrol_state = (++patrol_state) % 3;
			}
			else
			if(remote.is_enable())
			{
				// packet structure : <firm recno> <patrol_state>
				short *shortPtr=(short *)remote.new_send_queue_msg(MSG_F_CAMP_PATROL, 2 * sizeof(short));
				shortPtr[0] = firm_recno;
				shortPtr[1] = patrol_state;
			}
			else
			{
				patrol(patrol_state);
			}
		//	se_ctrl.immediate_sound("SORTIE");
			if( overseer_recno )
			{
				Unit *overseer = unit_array[overseer_recno];
				se_res.sound( center_x, center_y, 1, 'S', overseer->sprite_id, "ACK");
			}
			else
			if( soldier_count > 0 )
			{
				Soldier *soldierPtr = &soldier_array[0];
				int unitId = soldierPtr->unit_id;
				UnitInfo *unitInfo = unit_res[unitId];
				se_res.sound( center_x, center_y, 1, 'S', unitInfo->sprite_id, "ACK");
			}				
		}

		//----------- detect reward -----------//

		if( button_reward.detect() )
		{
			reward(selected_soldier_id, COMMAND_PLAYER);
			se_ctrl.immediate_sound("TURN_ON");
		}

		if( firm_id==FIRM_CAMP && button_camp_upgrade.detect() )
		{
			if (!upgrading_firm_id)
			{
				se_ctrl.immediate_sound("TURN_ON");
				start_upgrade(FIRM_FORT, COMMAND_PLAYER);	
			}
		}

		//----- detect defense mode button -------//

		if( button_defense.detect() )
		{
			se_ctrl.immediate_sound( !defense_flag?"TURN_ON":"TURN_OFF");

			if( !remote.is_enable() )
			{
				// update RemoteMsg::toggle_camp_patrol()
				defense_flag = !defense_flag;
			}
			else
			{
				// packet structure : <firm recno> <defense_flag>
				short *shortPtr=(short *)remote.new_send_queue_msg(MSG_F_CAMP_TOGGLE_PATROL, 2*sizeof(short));
				shortPtr[0] = firm_recno;
				shortPtr[1] = !defense_flag;
			}

//			button_defense.update_bitmap( defense_flag ? "DEFENSE1" : "DEFENSE0" );
		}

		if( button_promote.detect() )
		{
			promote_soldier( selected_soldier_id, COMMAND_PLAYER );
			se_ctrl.immediate_sound("PROMOTE");
		}
	}
}
Example #11
0
//------- Begin of function Town::think_ai_migrate --------//
//
// Think about migrating to another town.
//
int Town::think_ai_migrate()
{
	if( info.game_date < setup_date+90 )		// don't move if this town has just been set up for less than 90 days. It may be a town set up by think_split_town()
		return 0;

	Nation* nationPtr = nation_array[nation_recno];

	//-- the higher the loyalty, the higher the chance all the unit can be migrated --//

	int averageLoyalty = average_loyalty();
	int minMigrateLoyalty = 35 + nationPtr->pref_loyalty_concern/10;		// 35 to 45

	if( averageLoyalty < minMigrateLoyalty )
	{
		//-- if the total population is low (we need people) and the cash is high (we have money), then grant to increase loyalty for migration --//

		if( accumulated_reward_penalty==0 &&
			 average_target_loyalty() < minMigrateLoyalty+5 )		// if the average target loyalty is also lower than
		{
			if( nationPtr->ai_should_spend( 20+nationPtr->pref_territorial_cohesiveness/2 ) )		// 20 to 70 
				reward( COMMAND_AI );
		}

		if( average_loyalty() < minMigrateLoyalty )
			return 0;
	}

	if( !should_ai_migrate() )
		return 0;

	//------ think about which town to migrate to ------//

	int bestTownRecno = think_ai_migrate_to_town();

	if( !bestTownRecno )
		return 0;

	//--- check if there are already units currently migrating to the destination town ---//

	Town* destTownPtr = town_array[bestTownRecno];

	if( nationPtr->is_action_exist( destTownPtr->loc_x1, destTownPtr->loc_y1,
		 loc_x1, loc_y1, ACTION_AI_SETTLE_TO_OTHER_TOWN, 0, 0, 1 ) )		// last 1-check duplication on the destination town only
	{
		return 0;
	}

	//--------- queue for migration now ---------//

	int migrateCount = (average_loyalty() - MIN_RECRUIT_LOYALTY) / 5;

	migrateCount = min( migrateCount, jobless_population );

	if( migrateCount <= 0 )
		return 0;

	nationPtr->add_action( destTownPtr->loc_x1, destTownPtr->loc_y1,
		 loc_x1, loc_y1, ACTION_AI_SETTLE_TO_OTHER_TOWN, 0, migrateCount);

	return 1;
}
Example #12
0
//--------- Begin of function FirmCamp::detect_info ---------//
//
void FirmCamp::detect_info()
{
	if( detect_basic_info() )
		return;

	if( !should_show_info() )
		return;

	//------ detect the overseer button -----//

	int rc = mouse.single_click(INFO_X1+6, INFO_Y1+58,
				INFO_X1+5+UNIT_LARGE_ICON_WIDTH, INFO_Y1+57+UNIT_LARGE_ICON_HEIGHT, 2 );

	if( rc==1 )		// display this overseer's info
	{
		selected_worker_id = 0;
		disp_camp_info(INFO_Y1+54, INFO_UPDATE);
		disp_worker_list(INFO_Y1+104, INFO_UPDATE);
		disp_worker_info(INFO_Y1+168, INFO_UPDATE);
	}

	//--------- detect soldier info ---------//

	if( detect_worker_list() )
	{
		disp_camp_info(INFO_Y1+54, INFO_UPDATE);
		disp_worker_list(INFO_Y1+104, INFO_UPDATE);
		disp_worker_info(INFO_Y1+168, INFO_UPDATE);
	}

	//---------- detect spy button ----------//

	detect_spy_button();

	if( !own_firm() )
		return;

	//------ detect the overseer button -----//

	if( rc==2 )
	{
		if(remote.is_enable())
		{
			// packet structure : <firm recno>
			short *shortPtr=(short *)remote.new_send_queue_msg(MSG_FIRM_MOBL_OVERSEER, sizeof(short));
			shortPtr[0] = firm_recno;
		}
		else
		{
			assign_overseer(0);		// the overseer quits the camp
		}
	}

	//----------- detect patrol -----------//

	if( button_patrol.detect() )
	{
		if(remote.is_enable())
		{
			// packet structure : <firm recno>
			short *shortPtr=(short *)remote.new_send_queue_msg(MSG_F_CAMP_PATROL, sizeof(short));
			shortPtr[0] = firm_recno;
		}
		else
		{
			patrol();
		}
	}

	//----------- detect reward -----------//

	if( button_reward.detect() )
	{
		reward(selected_worker_id, COMMAND_PLAYER);
		// ##### begin Gilbert 25/9 ######//
		se_ctrl.immediate_sound("TURN_ON");
		// ##### end Gilbert 25/9 ######//
	}

	//----- detect defense mode button -------//

	if( button_defense.detect() )
	{
		// ##### begin Gilbert 25/9 ######//
		se_ctrl.immediate_sound( !defense_flag?(char*)"TURN_ON":(char*)"TURN_OFF");
		// ##### end Gilbert 25/9 ######//

		if( !remote.is_enable() )
		{
			// update RemoteMsg::toggle_camp_patrol()
			defense_flag = !defense_flag;
		}
		else
		{
			// packet structure : <firm recno> <defense_flag>
			short *shortPtr=(short *)remote.new_send_queue_msg(MSG_F_CAMP_TOGGLE_PATROL, 2*sizeof(short));
			shortPtr[0] = firm_recno;
			shortPtr[1] = !defense_flag;
		}

		button_defense.update_bitmap( defense_flag ? (char*)"DEFENSE1" : (char*)"DEFENSE0" );
	}
}