Exemplo n.º 1
0
void CUnitHandler::IdleUnitUpdate(int frame) {
	list<integer2> limboremoveunits;

	for (list<integer2>::iterator i = Limbo.begin(); i != Limbo.end(); i++) {
		if (i->y > 0) {
			i->y--;
		}
		else {
			if (ai->cb->GetUnitDef(i->x) == NULL) {
				// ignore dead unit
			} else {
				IdleUnits[ai->ut->GetCategory(i->x)].push_back(i->x);
			}

			limboremoveunits.push_back(*i);
		}
	}

	if (limboremoveunits.size()) {
		for (list<integer2>::iterator i = limboremoveunits.begin(); i != limboremoveunits.end(); i++) {
			Limbo.remove(*i);
		}
	}

	// make sure that all the builders are in action (hack?)
	if (frame % 15 == 0) {
		for (list<BuilderTracker*>::iterator i = BuilderTrackers.begin(); i != BuilderTrackers.end(); i++) {
			// the new test
			if ((*i)->idleStartFrame != -2) {
				// the brand new builders must be filtered still
				bool ans = VerifyOrder(*i);
				const CCommandQueue* mycommands = ai->cb->GetCurrentUnitCommands((*i)->builderID);
				Command c;

				if (mycommands->size() > 0)
					c = mycommands->front();

				// two sec delay is ok
				if (((*i)->commandOrderPushFrame + LAG_ACCEPTANCE) < frame) {
					if (!ans) {
						char text[512];
						float3 pos = ai->cb->GetUnitPos((*i)->builderID);
						sprintf(text, "builder %i VerifyOrder failed ", (*i)->builderID);

						ClearOrder(*i, false);

						if (!mycommands->empty())
							DecodeOrder(*i, true);
						else
							IdleUnitAdd((*i)->builderID, frame);
					}
				}
			}
		}
	}
}
Exemplo n.º 2
0
void CUnitHandler::IdleUnitAdd(int unit)
{	
	//L("IdleUnitAdd: " << unit);
	int category = ai->ut->GetCategory(unit);
	if(category != -1){
		const deque<Command>* mycommands = ai->cb->GetCurrentUnitCommands(unit);
		if(mycommands->empty()){
		
			if(category == CAT_BUILDER)
			{
				BuilderTracker* builderTracker = GetBuilderTracker(unit);
				//L("it was a builder");
				
				// Add clear here
				ClearOrder(builderTracker, true);
				
				if(builderTracker->idleStartFrame == -2)
				{
					// It was in the idle list allready ?
					IdleUnitRemove(builderTracker->builderID);
				}
				builderTracker->idleStartFrame = -2; // Its in the idle list now
				if(builderTracker->commandOrderPushFrame == -2) // Make shure that if the unit was just built it will have some time to leave the factory
				{
					builderTracker->commandOrderPushFrame = ai->cb->GetCurrentFrame() + 30*3;
				}
				//else if(builderTracker->commandOrderPushFrame == -)
				//	builderTracker->commandOrderPushFrame = ;
			}

			integer2 myunit(unit,LIMBOTIME);
			//L("Adding unit : " << myunit.x << " To Limbo " << myunit.y);
			Limbo.remove(myunit);
			//IdleUnitRemove(unit);  // This might be a better idea, but its over the edge (possible assertion)
			Limbo.push_back(myunit);
		}
		else
		{
			// The unit have orders still
			if(category == CAT_BUILDER)
			{
				BuilderTracker* builderTracker = GetBuilderTracker(unit);
				assert(false);
				DecodeOrder(builderTracker, true);
			}
		}
	}
}
Exemplo n.º 3
0
void CUnitHandler::IdleUnitAdd(int unit, int frame) {
	UnitCategory category = ai->ut->GetCategory(unit);

	if (category != CAT_LAST) {
		const CCommandQueue* myCommands = ai->cb->GetCurrentUnitCommands(unit);

		if (myCommands->empty()) {
			if (category == CAT_BUILDER) {
				BuilderTracker* builderTracker = GetBuilderTracker(unit);
				// add clear here
				ClearOrder(builderTracker, true);

				if (builderTracker->idleStartFrame == -2) {
					// it was in the idle list already?
					IdleUnitRemove(builderTracker->builderID);
				}

				builderTracker->idleStartFrame = -2;

				if (builderTracker->commandOrderPushFrame == -2) {
					// make sure that if the unit was just built
					// it will have some time to leave the factory
					builderTracker->commandOrderPushFrame = frame + 30 * 3;
				}
			}

			integer2 myunit(unit, LIMBOTIME);
			Limbo.remove(myunit);
			Limbo.push_back(myunit);
		} else {
			// the unit has orders still, so should not be idle
			if (category == CAT_BUILDER) {
				if (false) {
					// KLOOTNOTE: somehow we are reaching this branch
					// on initialization when USE_CREG is not defined,
					// mycommands->size() returns garbage?
					//
					// BuilderTracker* builderTracker = GetBuilderTracker(unit);
					// DecodeOrder(builderTracker, true);
				}
			}
		}
	}
}
Exemplo n.º 4
0
void CUnitHandler::IdleUnitUpdate(int frame) {
	std::list<integer2> limboremoveunits;

	for (std::list<integer2>::iterator i = Limbo.begin(); i != Limbo.end(); i++) {
		if (i->y > 0) {
			i->y--;
		} else {
			if (ai->cb->GetUnitDef(i->x) == NULL) {
				// ignore dead unit
			} else {
				IdleUnits[ai->ut->GetCategory(i->x)].push_back(i->x);
			}

			limboremoveunits.push_back(*i);
		}
	}

	if (limboremoveunits.size()) {
		for (std::list<integer2>::iterator i = limboremoveunits.begin(); i != limboremoveunits.end(); i++) {
			Limbo.remove(*i);
		}
	}

	// make sure that all the builders are in action (hack?)
	if (frame % 15 == 0) {
		for (std::list<BuilderTracker*>::iterator i = BuilderTrackers.begin(); i != BuilderTrackers.end(); i++) {
			if ((*i)->idleStartFrame != -2) {
				// the brand new builders must be filtered still
				bool ans = VerifyOrder(*i);
				const int builderID = (*i)->builderID;
				const CCommandQueue* myCommands = ai->cb->GetCurrentUnitCommands(builderID);
				Command c;

				if (myCommands->size() > 0) {
					c = myCommands->front();
				}

				// two sec delay is ok
				if (((*i)->commandOrderPushFrame + LAG_ACCEPTANCE) < frame) {
					if (!ans) {
						float3 pos = ai->cb->GetUnitPos(builderID);

						std::stringstream msg;
							msg << "[CUnitHandler::IdleUnitUpdate()][frame=" << frame << "]\n";
							msg << "\tfailed to verify order for builder " << builderID;
							msg << " with " << (myCommands->size()) << " remaining commands\n";
						ai->GetLogger()->Log(msg.str());

						ClearOrder(*i, false);

						// due to the Legacy AI Wrapper inner workings,
						// the command-queue we fetched above is now invalid,
						// because it got changed in ClearOrder()
						myCommands = ai->cb->GetCurrentUnitCommands(builderID);
						if (!myCommands->empty()) {
							DecodeOrder(*i, true);
						} else {
							IdleUnitAdd(builderID, frame);
						}
					}
				}
			}
		}
	}
}
bool SampleInstrumentTable::key(unsigned long p_unicode, unsigned long p_scan_code,bool p_press,bool p_repeat,int p_modifier_mask) {
	
	if (!p_press)
		return true;
	KeyBindList kbind=KeyBind::get_bind( p_scan_code|p_modifier_mask );
	
	if (kbind==KB_MAX)
		return false;
	
	
	bool capture=false;
	switch (kbind) {
	
		case KB_PATTERN_RAISE_NOTES: {
			
			for (int i=0;i<Note::NOTES;i++) {
				if (instrument->get_note_number(i)>=Note::NOTES)
					continue;
				int new_note=instrument->get_note_number(i)+1;
				if (new_note>=Note::NOTES)
					new_note=Note::EMPTY;
				
				instrument->set_note_number(i,new_note);
			}
			
		} break;
		case KB_PATTERN_LOWER_NOTES: {
			
			for (int i=0;i<Note::NOTES;i++) {
				if (instrument->get_note_number(i)>=Note::NOTES)
					continue;
				if (instrument->get_note_number(i)==0)
					continue;
				instrument->set_note_number(i,instrument->get_note_number(i)-1);
				
			}
			
		} break;
		case KB_CURSOR_WRITE_MASK: {
			
			//for (int i=0;i<Note::NOTES;i++) {
			instrument->set_sample_number(cursor_y,sample_mask);
			MoveDown();
			//}
			
		} break;
		/*	
		case KB_CURSOR_INSERT: {

			editor->orderlist_insert();
		} break;
		case KB_CURSOR_DELETE: {

			editor->orderlist_delete();
	} break; */
		case KB_CURSOR_MOVE_UP: {

			MoveUp();
			capture=true;
		} break;
		case KB_CURSOR_MOVE_DOWN: {

			MoveDown();
			capture=true;

		} break;
		case KB_CURSOR_MOVE_LEFT: {

			if (MoveLeft())
				capture=true;

		} break;
		case KB_CURSOR_MOVE_RIGHT: {

			if (MoveRight())
				capture=true;

		} break;
		case KB_CURSOR_PAGE_UP: {

			PageUp();
			capture=true;

		} break;
		case KB_CURSOR_PAGE_DOWN: {

			PageDown();

			capture=true;
		} break;
		
		case KB_CURSOR_FIELD_CLEAR: {
			
			ClearOrder();
			
			
		} break;
		default: {
			
			
			switch (cursor_x) {
				case 0: {

					int tmpkey = editor->get_note_from_charcode(kbind);
					if (tmpkey>=0) {

						instrument->set_note_number(cursor_y,tmpkey);
						instrument->set_sample_number(cursor_y,sample_mask);

						MoveDown();
					}
				} break;
				case 1: {

					if ((p_unicode>='0') && (p_unicode<='9')) {

						int aux_numb=instrument->get_note_number(cursor_y) % 12;

						instrument->set_note_number(cursor_y,(p_unicode-'0')*12+aux_numb);
						MoveDown();
					}
				} break;
				case 2: {

					if ((p_unicode>='0') && (p_unicode<='9')) {

						int aux_numb=instrument->get_sample_number(cursor_y);
						
						if (aux_numb==Note::EMPTY) aux_numb=0;
						else aux_numb++;

						int num_right=aux_numb % 10;

						aux_numb=(p_unicode-'0')*10+num_right;

						if (aux_numb==0) aux_numb=Note::EMPTY;
						else aux_numb--;

						sample_mask=aux_numb;
						instrument->set_sample_number(cursor_y,aux_numb);
						MoveRight();
					}
				} break;
				case 3: {

					if ((p_unicode>='0') && (p_unicode<='9')) {

						int aux_numb=instrument->get_sample_number(cursor_y);
						int num_left;
						if (aux_numb==Note::EMPTY) aux_numb=0;
						else aux_numb++;

						num_left=aux_numb / 10;

						aux_numb=num_left*10+(p_unicode-'0');

						if (aux_numb==0) aux_numb=Note::EMPTY;
						else aux_numb--;

						sample_mask=aux_numb;
						instrument->set_sample_number(cursor_y,aux_numb);
						MoveLeft();
						MoveDown();
					}
				} break;
			}
		}
	}
	
	if (range)
		range->set(row_offset);
	update();
	return capture;
}
Exemplo n.º 6
0
void CUnitHandler::IdleUnitUpdate() {
//	std::cout << "CUnitHandler::IdleUnitUpdate()" << std::endl;

	list<integer2> limboremoveunits;
	for(list<integer2>::iterator i = Limbo.begin(); i != Limbo.end(); i++){
		if(i->y > 0){
			i->y = i->y - 1;
		}
		else{
			//L("adding unit to idle units: " << i->x);
			if(ai->cb->GetUnitDef(i->x) == NULL)
			{
				//L(" Removeing dead unit... ");
				
			}
			else
				IdleUnits[ai->ut->GetCategory(i->x)]->push_back(i->x);
			if(ai->ut->GetCategory(i->x) == CAT_BUILDER)
			{
				//GetBuilderTracker(i->x)->idleStartFrame = -1; // Its ok now, stop the force idle  (hack)
			}
			
				
			limboremoveunits.push_back(*i);
		}
	}
	if(limboremoveunits.size()){
		for(list<integer2>::iterator i = limboremoveunits.begin(); i != limboremoveunits.end(); i++){
			Limbo.remove(*i);
		}
	}
	// Make shure that all the builders are in action:   (hack ?)
	if(ai->cb->GetCurrentFrame() % 15 == 0)
		for(list<BuilderTracker*>::iterator i = BuilderTrackers.begin(); i != BuilderTrackers.end(); i++){
			
			// The new test:
			if((*i)->idleStartFrame != -2) // The brand new builders must be filtered still
			{
				//L("VerifyOrder");
				bool ans = VerifyOrder(*i);
				const deque<Command>* mycommands = ai->cb->GetCurrentUnitCommands((*i)->builderID);
				Command c;
				if(mycommands->size() > 0)
					c = mycommands->front();
				
				// Two sec delay is ok
				if(( (*i)->commandOrderPushFrame + LAG_ACCEPTANCE) < ai->cb->GetCurrentFrame())
				{
					//assert(ans);
					if(!ans)
					{
						char text[512];
						float3 pos = ai->cb->GetUnitPos((*i)->builderID);
						sprintf(text, "builder %i VerifyOrder failed ", (*i)->builderID);
						AIHCAddMapPoint amp;
						amp.label = text;
						amp.pos = pos;
						////ai->cb->HandleCommand(&amp);
						
						ClearOrder(*i, false);
						if(!mycommands->empty())
							DecodeOrder(*i, true);
						else // Its idle
							IdleUnitAdd((*i)->builderID);
							
					}
				}
			}
			
			/*
			if((*i)->buildTaskId == 0 && (*i)->taskPlanId == 0 && (*i)->factoryId == 0 && (*i)->customOrderId == 0 && (*i)->idleStartFrame != -2)
			{
				// Its without tasks and not in the idle list
				if((*i)->idleStartFrame == -1)
				{
					(*i)->idleStartFrame = ai->cb->GetCurrentFrame();
				}
				else
				{
					if(((*i)->idleStartFrame + 90) < ai->cb->GetCurrentFrame())
					{
						//L("Idle unit command force: " << (*i)->builderID);
						char text[512];
						float3 pos = ai->cb->GetUnitPos((*i)->builderID);
						sprintf(text, "builder %i without tasks and not in the idle list (idle forced)", (*i)->builderID);
						AIHCAddMapPoint amp;
						amp.label = text;
						amp.pos = pos;
						////ai->cb->HandleCommand(&amp);
						IdleUnitAdd((*i)->builderID);
						(*i)->idleStartFrame =  ai->cb->GetCurrentFrame(); // Just to cut down on the spam, if its not idle
					}
				}
			} else if((*i)->idleStartFrame != -2) // This will only be ok if idleStartFrame is changed to -1 on unit UnitFinished
			{
			*/
			/*
				//L("VerifyOrder");
				bool ans = VerifyOrder(*i);
				const deque<Command>* mycommands = ai->cb->GetCurrentUnitCommands((*i)->builderID);
				Command c;
				if(mycommands->size() > 0)
					c = mycommands->front();
				
				// Two sec delay is ok
				if(( (*i)->commandOrderPushFrame + 30 * 2) < ai->cb->GetCurrentFrame())
				{
					//assert(ans);
					if(!ans)
					{
						char text[512];
						float3 pos = ai->cb->GetUnitPos((*i)->builderID);
						sprintf(text, "builder %i VerifyOrder failed ", (*i)->builderID);
						AIHCAddMapPoint amp;
						amp.label = text;
						amp.pos = pos;
						////ai->cb->HandleCommand(&amp);
					}
				}
				* /
			}
			*/
		}
}