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); } } } }
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); } } } } }
int main(int argc, char **argv){ SDL_Window *window = 0; SDL_Renderer *renderer = 0; SDL_Texture *texture = 0; SDL_Event event; bool run = true; mouse mymouse; timer timer(60); unit myunit(300,300); if(SDL_Init(SDL_INIT_EVERYTHING) != 0 ){ std::cout<< "SDL init error: " << SDL_GetError() << std::endl; return 1; } if(SDL_CreateWindowAndRenderer(KSCREEN_WIDTH,KSCREEN_HEIGHT,0,&window,&renderer) !=0 ){ std::cout<< "Create window and renderer error: " << SDL_GetError() << std::endl; return 1; } texture = util_create_texture_from_bitmap("background.bmp",renderer); while(run){ timer.start(); while(SDL_PollEvent(&event)){ switch(event.type){ case SDL_QUIT: run = false; break; case SDL_KEYDOWN: switch(event.key.keysym.sym){ case SDLK_ESCAPE: run = false; break; case SDLK_DOWN: printf("left pressed\n"); break; } break; } } myunit.run(renderer,&event,mymouse); //doesnt flicker when here mymouse.run(renderer,&event); //SDL_RenderDrawLine(renderer,0,0,640,480); // test line.. SDL_RenderPresent(renderer); util_render_texture_to_renderer(0,0,texture,renderer); //using background as a clear.. timer.end(); timer.delay(); } SDL_DestroyTexture(texture); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); std::cout<<"quit success" << std::endl; return 0; }