1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Workers only stop on visible danger

Discussion in 'Civ5 - SDK / LUA' started by whoward69, Mar 27, 2013.

  1. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,342
    Location:
    Near Portsmouth, UK
    I've just played one of the most enjoyable 100+ starting turns of a game ever. Despite marauding barbarians, my workers only stopped what they were doing twice.

    Code snippet to only stop workers doing what they are doing if the worker can actually see the danger and not just sniff them on the wind!

    In CvUnitsMission.cpp

    Code:
    bool bAbortMission = (!bEscortedBuilder && !hUnit->IsIgnoringDangerWakeup() && !hUnit->IsCombatUnit());
    // Stop only if the worker can actually see the enemy
    bAbortMission = (bAbortMission && hUnit->SentryAlert());
    // or stop if there is any hint of an enemy
    // bAbortMission = (bAbortMission && GET_PLAYER(hUnit->getOwner()).GetPlotDanger(*(hUnit->plot())) > 0);
    
    if(bAbortMission)
    // if(!bEscortedBuilder && !hUnit->IsIgnoringDangerWakeup() && !hUnit->IsCombatUnit() && GET_PLAYER(hUnit->getOwner()).GetPlotDanger(*(hUnit->plot())) > 0)
     
  2. DaveMcW

    DaveMcW Chieftain

    Joined:
    Oct 8, 2002
    Messages:
    6,489
    Does that make the AI more vulnerable to worker stealing?
     
  3. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,342
    Location:
    Near Portsmouth, UK
    In theory yes, but unless a fast attack unit, like a horseman, happens to stumble upon them (after all they may be fast but can only still only see two tiles), it's unlikely to happen. The AI is now pretty good at escorting workers (especially the CSes), and escorted units ignored the wake up call anyway. Also, waking a unit that can "sense danger" "from the plains behind the forested hills three tiles away" should really be considered a cheat ;)

    But if you want the AI to work the old way, just add in a GET_PLAYER(hUnit->getOwner()).IsHuman() condition to choose between the two statements
     

Share This Page