Esempio n. 1
0
//---- Begin of function FirmCamp::builder_stay_after_construction ----//
//
// This function is called by Firm::process_construction()
// to assign the builder into the firm after the construction
// of the firm is complete.
//
// return: <int> 1 - the builder has been successfully assigned
//							into the firm.
//					  0 - failed.
//
int FirmCamp::builder_stay_after_construction()
{
	if( !builder_recno )
		return 0;

	Unit *unitPtr = unit_array[builder_recno];

	if( unitPtr->is_civilian() )		// only assign military unit
		return 0;

	unitPtr->set_mode(0);			// reset it from UNIT_MODE_CONSTRUCT_???

	assign_unit(builder_recno);

	builder_recno = 0;

	return soldier_count || overseer_recno;
}
Esempio n. 2
0
bool hp98035_io_card::parse_unit_command(const uint8_t*& p, unsigned unit_no)
{
	unit_no--;
	timer_unit_t& unit = m_units[ unit_no ];
	bool get_out = false;
	unsigned msec;
	uint8_t to_match[ 5 ];
	std::ostringstream out;

	LOG(("U %c %u %p\n" , *p , unit_no , &unit));

	switch (*p++) {
	case '=':
		// Assign unit
		if (*p == 'I') {
			p++;
			get_out = assign_unit(unit , p , true);
		} else if (*p == 'O') {
			p++;
			get_out = assign_unit(unit , p , false);
		}
		break;

	case 'C':
		// Clear input unit
		if (unit.m_input && unit.m_port) {
			unit.m_value = 0;
		} else {
			set_error(ERR_MASK_WRONG_UNIT);
		}
		break;

	case 'D':
		// Set delay on output unit
		if (parse_msec(p , msec)) {
			if (!unit.m_input && unit.m_port) {
				if (unit.m_state == UNIT_IDLE) {
					unit.m_delay = msec;
				} else {
					set_error(ERR_MASK_CANT_EXEC);
				}
			} else {
				set_error(ERR_MASK_WRONG_UNIT);
			}
		} else {
			set_error(ERR_MASK_WRONG_INS);
		}
		get_out = true;
		break;

	case 'G':
		// Activate unit
		if (unit.m_port && unit.m_state == UNIT_IDLE) {
			unit.adv_state(true);

			LOG(("act %p %d %d %u %02u:%02u:%02u:%02u %u %u %u\n" , &unit , unit.m_state , unit.m_input , unit.m_port , unit.m_match_datetime[ 0 ] , unit.m_match_datetime[ 1 ] , unit.m_match_datetime[ 2 ] , unit.m_match_datetime[ 3 ] , unit.m_delay , unit.m_period , unit.m_value));
		} else {
			set_error(ERR_MASK_WRONG_UNIT);
		}
		break;

	case 'H':
		// Halt unit
		if (unit.m_port) {
			unit.deactivate();
		} else {
			set_error(ERR_MASK_WRONG_UNIT);
		}
		break;

	case 'M':
		// Set date/time to match on output unit
		if (!unit.m_input && unit.m_port) {
			if (unit.m_state == UNIT_IDLE) {
				if (*p == '\0') {
					unit.m_match_datetime[ 0 ] = EMPTY_FIELD;
					unit.m_match_datetime[ 1 ] = EMPTY_FIELD;
					unit.m_match_datetime[ 2 ] = EMPTY_FIELD;
					unit.m_match_datetime[ 3 ] = EMPTY_FIELD;
				} else if (parse_datetime(p , to_match) && *p == '\0') {
					unit.m_match_datetime[ 0 ] = to_match[ 1 ];
					unit.m_match_datetime[ 1 ] = to_match[ 2 ];
					unit.m_match_datetime[ 2 ] = to_match[ 3 ];
					unit.m_match_datetime[ 3 ] = to_match[ 4 ];
				} else {
					set_error(ERR_MASK_WRONG_INS);
				}
			} else {
				set_error(ERR_MASK_CANT_EXEC);
			}
		} else {
			set_error(ERR_MASK_WRONG_UNIT);
		}
		get_out = true;
		break;

	case 'P':
		// Set period on output unit
		if (parse_msec(p , msec)) {
			if (!unit.m_input && unit.m_port) {
				if (unit.m_state == UNIT_IDLE) {
					unit.m_period = msec;
				} else {
					set_error(ERR_MASK_CANT_EXEC);
				}
			} else {
				set_error(ERR_MASK_WRONG_UNIT);
			}
		} else {
			set_error(ERR_MASK_WRONG_INS);
		}
		get_out = true;
		break;

	case 'V':
		// Get value of input unit
		if (unit.m_input && unit.m_port) {
			util::stream_format(out , "%010u" , unit.m_value);
			set_obuffer(out.str().c_str());
		} else {
			set_error(ERR_MASK_WRONG_UNIT);
		}
		break;
	}

	return get_out;
}