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

The Cold War 1947 - 1991

Discussion in 'Civ2 - Scenario League' started by JPetroski, Apr 13, 2020.

  1. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,891
    Location:
    Ontario
    Put parentheses around the or conditions.

    Code:
    if (city == object.cSydney or city == object.cMelbourne or city == object.cAdelaide or city == object.cHobart or city == object.cBrisbane or city == object.cPerth or city == object.cDarwin) and conqueror == object.tChina and defender == object.tProWest and object.cLondon.owner == object.tEurope and civ.hasTech(object.tEurope, civ.getTech(3)) and not civ.hasTech(object.tEurope, civ.getTech(4,6,8,10)) then
    
    One reason you might consider having an event driven mobilization is to have a bit of implicit politics regarding armies. That is, it might make sense for the USA to have a total war style mobilization to fight the Soviets in Europe, but there probably wouldn't be the political will for such a mobilization in order to set up dozens of pro west governments in Africa.

    Another option would be for human players to make troops 'deployable'. For example, stationed in a 'military base' with adequate transportation. Then, the human version of these events will teleport units to the combat zone as a rapid response, but only if the units are actually available.
     
  2. Patine

    Patine Deity

    Joined:
    Feb 14, 2011
    Messages:
    7,249
    Does LUA allow one to keep an Engineer placed at the start for a player in a "torpor," (that is, a sleep status that can only be broken by a triggered event)? If that is possible, you could put such Engineers at the start on remote locations like Diego Garcia and such, and have them awaken when the historical lease and base-building would happen.
     
  3. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,958
    Thanks, that worked great!

    Also, thanks for your help on writing those lessons again - I just figured out how to save myself a ton of time with the MP events by using strings!
     
  4. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,958
    I'm not sure about that but you can create cities at will for any tribe you want, and I believe you can name them as well. I just think this needs to be a little more open ended of a scenario. Why start it right at the beginning of the Cold War and not see where the game takes you?
     
  5. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,891
    Location:
    Ontario
    @JPetroski
    This won't do what it looks like you expect it to do:
    Code:
    not civ.hasTech(object.tEurope, civ.getTech(4,6,8,10))
    
    It is equivalent to
    Code:
    not civ.hasTech(object.tEurope,civ.getTech(4))
    
    Instead, define this function in your code, and use it where you need it
    Code:
    -- returns true if the tribe has any of the technologies
    -- in the table techList
    -- values in techList can be either integers or technology objects
    local function hasAnyTech(tribe,techList)
        for key,value in pairs(techList) do
            if type(value)==number and tribe:hasTech(civ.getTech(value)) then
                return true
            elseif civ.isTech(value) and tribe:hasTech(value) then
                return true
            end
        end
        return false
    end
    
    (This is not tested, so you might have to fix something.)

    You could have an event that spends an engineer's movement each turn before the player gets a chance to move it (until some condition is met), but as JPetroski points out, it would be less trouble simply to create a city when it is needed. Or, to create the engineer on the square when it is needed.

    For that matter, you could create a city directly on the ocean via event (but that could create a problem when only helicopters can capture it).
     
  6. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,958
    What I'm trying to do with that is make sure that the correct bonus unit is given to a civ dependent on another civs tech. I may be missing something but I've tested it pretty extensively on multiple events and the functionality I want does work. Basically I want a city captured late game to give F16s as opposed to Spitfires. By using elseifs and progressively "moving up the line," it seems to work.

    Did you think I was attempting something else?
     
  7. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,891
    Location:
    Ontario
    To me, it looks like that condition is trying to check that the Europeans don't have any of the technologies indexed by 4, 6, 8, and 10. However, the condition will only check that the Europeans don't have technology 4. Perhaps this doesn't matter, if elseifs are giving other implicit conditions, but then there was no reason to write civ.getTech(4,6,8,10), since it is the same as civ.getTech(4).
     
  8. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,958
    Ah I see. So the reason it is working for me is that you can't get tech 6 unless you have 4, but really all the techs after 4 aren't counted in what I've written?
     
  9. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,891
    Location:
    Ontario
    That's correct. You'd have to check each technology individually (in the same way you checked each city), or write a function like I did that can handle multiple checks.
     
  10. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,958
    Having decided to stop making mega-single player events at this stage, and instead simply aim to build out a scenario that can be played "out the box" MP or SP, I've made much better progress. The Asian events are done, and I'm going to move on to the Middle East now.

    I've decided to handle certain hot spots in a bit of a compromised way. Let's look at Vietnam.

    Vietnam (Hanoi and Saigon) start under European control with some Communist (Pro-East) forces lurking in the jungles.
    At any point between turn 2 and 70, there is a 20% chance that a massive rebellion will erupt, and the Pro-East will get a sizeable army once.
    If the Pro-East capture one of these two cities, they get a boost of units.
    If the Pro-East lose one of these two cities, they also get a boost of units.
    The last two above happen as many times as necessary (there is no "just once" condition).

    This should turn Southeast Asia into a quagmire that is going to be very difficult to prevent from becoming Communist. To do so, you'd basically need to sink in enough forces that you can kill the original troops, kill the main event troops, and hold both cities without losing them, because the second you lose them there are more reinforcements.

    At the same time, the Soviet player can directly add Pro-East troops if they're so inclined and have the funds.

    I don't plan on doing this everywhere, but some of the larger decolonization conflicts such as Vietnam, Algiera, Congo, and Malaya probably warrant this.
     
    Tanelorn likes this.
  11. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,958
    Would this kind of logic work or do I need parentheses here? I left them out because there is only one "or"

    Code:
    if object.cTehran.owner == object.tProEast and object.cBaghdad.owner == object.tProWest or object.cTehran.owner == object.tProWest and object.cBaghdad.owner == object.tProEast then
    but I'm wondering if I need parentheses around each statement like this:

    Code:
    if (object.cTehran.owner == object.tProEast and object.cBaghdad.owner == object.tProWest) or (object.cTehran.owner == object.tProWest and object.cBaghdad.owner == object.tProEast) then 
    What I'm trying to do is set up a situation where once Iran and Iraq are controlled by opposing pro factions, the Iran Iraq war will be triggered. I think in the create unit I can have object.cTehran.owner as the unit owner and place the Iranian units on their side of the border, under the correct civ's control that way, right?

    Code:
    if (object.cTehran.owner == object.tProEast and object.cBaghdad.owner == object.tProWest) or (object.cTehran.owner == object.tProWest and object.cBaghdad.owner == object.tProEast) then 
            justOnce("Iran Iraq War", function()   
            civ.ui.text(func.splitlines(object.xIranIraqWar))
            civlua.createUnit(object.uT55, object.cTehran.owner, {{41,69,0}}, {count=5, randomize=false, veteran=false})
            civlua.createUnit(object.uT55, object.cBaghdad.owner, {{35,69,0}}, {count=5, randomize=false, veteran=false})
        end)
       
        end 
    
     
  12. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,958
    Sorry to stack up so many questions but what I'm trying to do here is have an event where a terrorist unit shows up somewhere in the world. Given the huge amount of coordinates, I really need to use a string to talk about where it shows up. However, this throws a nil value.

    I tried correcting it by taking these coordinates and basically putting them after "local potentialTerroristLocations = " and then plugging "potentialTerroristLocations" in where the location goes, but them I'm told that it is looking for a tile and got a table. I'm a little lost because a table is fine in the normal event but it isn't when I refer to a table I created prior to the event?

    What is a good way to go about handling this so players will know where to send their special forces?

    Code:
    
    if turn >=1 and turn <=135 and math.random() < 0.99 then 
        civlua.createUnit(object.uTerrorist, object.tNeutrals, {{11,53,0},{10,38,0},{284,36,0},{283,27,0},{280,30,0},{282,54,0},{13,61,0},{29,45,0},{32,32,0},{28,22,0},{35,57,0},
            {38,54,0},{28,74,0},{30,68,0},{226,58,0},{216,52,0},{210,66,0},{195,69,0},{192,62,0},{191,45,0},
            {3,43,0},{5,39,0},{9,45,0},{27,67,0},{22,68,0},{117,97,0},{2,50,0},{2,48,0},{10,52,0},{13,43,0},
            {30,28,0},{26,24,0},{23,19,0},{22,30,0},{23,43,0},{20,52,0},{12,42,0},{8,32,0},{283,63,0},{286,60,0},{7,69,0},{21,73,0},
            {9,63,0},{1,39,0},{287,33,0},{7,13,0},{14,12,0},{19,7,0},{119,193,0},{121,185,0},{112,194,0},{113,199,0},{96,190,0},
            {107,157,0},{215,73,0},{205,63,0},{211,47,0},{228,52,0},{228,62,0},{223,67,0},{218,72,0},{222,78,0},{215,73,0},{198,64,0},
            {61,83,0},{60,72,0},{55,73,0},{52,80,0},{36,90,0},{35,93,0},{37,95,0},{38,90,0},{22,90,0},{27,107,0},{19,183,0},
            {24,182,0},{119,189,0},{15,185,0},{14,170,0},{66,76,0},{82,102,0},{81,95,0},{102,114,0}}, {count=1, randomize=true, veteran=false})
        civ.ui.text(func.splitlines("A group of terrorists seizes hostages near ".. tostring (object.uTerrorist.location.x,object.uTerrorist.location.y,object.uTerrorist.location.z) .."! The hostages' only hope is that some special forces can rescue them!"))
       
    end 
    
     
  13. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,891
    Location:
    Ontario
    Just like in arithmetic, you need parentheses whenever you want to do something in a different order than the regular order of operations. It doesn't hurt to put them in even when they are not needed, so if you're not sure (or just want to make things clear) put them in anyway.

    Lua operators and operators precedence

    Since and is evaluated before or, I don't think you need them in this case, but it doesn't hurt at all to leave them in, so I would do that.

    Be careful with the operator not, since it is evaluated before other operators, so

    Code:
    not a == b
    
    is the same as

    Code:
    (not a) == b
    
    This caused me some debugging difficulty in the Legacy Event Engine.

    You should be able to specify potentialTerroristLocations and use it in civlua.createUnit .

    The problem I see with this code is that object.uTerrorist is a unitType, NOT an actual unit, so it doesn't have a location.

    civlua.createUnit returns a table containing the units created, so you want something like

    Code:
    local newUnits = civlua.createUnit(--[[arguments]])
    local newTerrorist = newUnits[1]
    if newTerrorist then
        civ.ui.text(func.splitlines("A group of terrorists seizes hostages near "..tostring(newTerrorist.location.x,newTerrorist.location.y,newTerrorist.location.z).."!  The hostages' only hope is that some special forces can rescue them!"))
    end
    
    I have the if newTerrorist then condition to make sure that something was actually created, (just in case the squares were covered or something).

    A couple notes:
    1. func.splitlines isn't necessary here. I'm pretty sure I was mistaken about its effects a long time ago. You only need it if you are trying to have a line break in your message, that is you want

    This is the first line.
    This is the second line.

    Instead of

    This is the first line. This is the second line.

    2. I have some text functionality that might be useful in the text module.

    text.substitute(message,substitutionTable)
    This lets you put %STRINGj (for jin 0 to 9) in your message, and replace it with substitutionTable[j], so you can specify an entire message as one string.

    text.simple(message,title)
    This gives you text and title, and handles stuff like splitlines for you. You can also use %PAGEBREAK in the text to split a message into two windows. If message is a table of strings, they will be displayed in order as separate windows.

    text.addToArchive(tribe or TribeID,messageBody,messageTitle,archiveTitle)
    Adds a message to the tribe's archive

    text.displayNextOpportunity(tribe or Table of Tribes, messageBody,messageTitle, archiveTitle)
    This shows a message to each tribe specified, either immediately or after their next production phase. If archiveTitle isn't nil, then the message is stored in the player's archive for future reference. Note that text.displayAccumulatedMessages() must be in the after production event for this to work.

    Edit: removed italics, changed a couple i's to j's, inserted a [j].
     
    Last edited: Aug 2, 2020
    JPetroski likes this.
  14. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,958
    That NextOpportunity event is a nifty idea indeed.
     
  15. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,958
    This stuff is fickle. It is not working as I intended. It seems to work fine for the first turn with the US/Pro-West only. It won't continue working on turn 2. Any ideas what I'm doing wrong?


    Code:
    --US and Pro-West
    if turn >=1 and turn <=135 and (tribe == object.tProWest or tribe == object.tUSA) then
    civ.ui.text(func.splitlines("This is a test to see if my diplomacy model is working.  The US and Pro West Should be ALLIED this turn, and the Soviets should NOT."))
    civ.getTribe(4).treaties[civ.getTribe(5)] = 0x0009
    civ.getTribe(1).treaties[civ.getTribe(2)] = civ.getTribe(1).treaties[civ.getTribe(2)] & ~0x0005
    end
    
    if turn >=1 and turn <=135 and (tribe == object.tChina or tribe == object.tProEast or tribe == object.tUSSR or tribe == object.tEurope or tribe == object.tIndia)  then
    civ.ui.text(func.splitlines("This is a test to see if my diplomacy model is working.  The US and Pro West Should NOT be Allied this turn, but the Soviets should be."))
    civ.getTribe(4).treaties[civ.getTribe(5)] = civ.getTribe(4).treaties[civ.getTribe(5)] & ~0x0005
    civ.getTribe(1).treaties[civ.getTribe(2)] = 0x0009
    end
    
    I basically need a reliable situation where alliances change each turn:

    -US/Pro-West should only be Allied on their turns but no one else's (so others can attack Pro-West without dragging in US)
    -USSR/Pro-East should only be Allied on their turns but no one else's (same reason)
    -USSR and China should only be Allied on their turns if China doesn't have tech 35
    -USA and Europe should only be Allied on their turns if Europe doesn't have tech 58

    object.tNeutrals = civ.getTribe(0)
    object.tUSSR = civ.getTribe(1)
    object.tProEast = civ.getTribe(2)
    object.tChina = civ.getTribe(3)
    object.tUSA = civ.getTribe(4)
    object.tProWest = civ.getTribe(5)
    object.tEurope = civ.getTribe(6)
    object.tIndia = civ.getTribe(7)

    I'm trying to put this code in the afterProduction sequence to get this effect... The text boxes show up so the event is working with the exception of the actual change to diplomacy.
     
  16. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,891
    Location:
    Ontario
    The short answer is that the diplomacy module has the following functions that will do what you want (and similar functions for the other diplomacy statuses).
    Code:
    diplomacy.allianceExists(tribe1,tribe2)-->bool
    diplomacy.setAlliance(tribe1,tribe2)
    diplomacy.clearAlliance(tribe1,tribe2)
    
    If you want to set treaties manually, you have to set them with both tribes, that is
    Code:
    tribeA.treaties[tribeB] = x
    tribeB.treaties[tribeA] = x
    
    Also, the General Library has some functions to check, set, and clear bits, which you will probably find easier to use.
     
  17. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,958
    I completely forgot there was a diplomacy module... sorry about that. You guys have built so much I have a hard time keeping up. I'll go check the github.
     
  18. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,891
    Location:
    Ontario
    You should already have a copy with Brown Man's burden. In any case, I'll update the github page so the most recent version is available.
     
  19. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,958
    These modules are really something else. I wasted probably 2 hours messing around this morning and I plug this in and it just works. I hope other designers will start taking a look at them soon as they make life 100% easier.
     
  20. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,958
    What do you all think of this for advantages/disadvantages for the tribes? Is there anything below that you would find so off-putting you would never want to play it, or do these appear interesting? I'm trying to make it so Europe is as interesting as the U.S. and USSR. Thoughts?

    USA
    Advantages
    -Army bases cost 1/2 as much as everyone else's to allow for easier power projection
    -Starts with some powerful wonders, but these can be made obsolete by others.
    -When a US mainland civ is conquered, partisans will appear (once).
    -Full unit set

    Disadvantages
    -While it isn't built yet, in the proxy war module, I'm considering if perhaps there should be a percentage chance that the proxies aren't actually deployed, but you lose the money.... "The Senate learns of our international meddling. A special committee ends this foreign adventure." something along those lines. Maybe espionage techs reduce the chance of this occuring.
    -I'm considering not allowing them to build freight... Yes, you read that right. I'm considering removing this from them so their proxy has to build freight, trade with the US to make money, and then buy equipment from them. I'll reduce the science payout for freight completely so other civs don't get a science advantage, but the US will absolutely need to meddle in affairs everywhere (and maintain a huge navy) to ensure that they get lots of money from their proxies.
    -Has a malus to conquering new cities and holding directly. Will want to swap them to proxy civ.

    USSR
    Advantages
    -Soviet cities will spawn Partisans every time they're conquered, and the attacker will lose 250 gold (attrition).
    -Soviets will be able to spawn rebels/proxy wars much more efficiently than the U.S. For one, the units will always spawn. Secondly, they'll be cheaper.
    -Full unit set

    Disadvantages
    -Mostly geographic... Need to build proxies or you'll be poor as you likely can't trade with Europe or the U.S.
    -Also can't use freight from them so both superpowers must expand.
    -Like the U.S., has a malus to conquering new cities and holding directly. Will want to swap them to proxy civ.

    Europe
    Advantages
    -Only civ that can build superhighways, and this acts like an airport that can teleport any ground or air unit 1x per turn to another city with the same improvement - should allow them to muster forces quickly in regions, and to have good trade payouts/economy.
    -Can build own freighters - doesn't rely on proxy system
    -Only one of the "big three" that can actually occupy new cities, with all that entails.
    -Full unit set

    Disadvantages
    -Everyone is gunning for your colonies. Chances are, you're going to lose a lot of cities.
    -Starts off less developed as it is still recovering from WW2. Has a chance to grow immensely strong, however.
    -Border with the Soviets that will need to be defended.
    -Most of their best units can only be built in Europe proper, but their empire will span the globe.

    China
    Advantages
    -Very cheap (10 shield) infantry
    -Sun Tzu WoW
    -Proper alliance with Soviets early game that will stay in place until China decides it is time to end it
    -When China ends the alliance, will get a cash bonus each turn
    -Has opportunity to become industrial powerhouse as one of 2 civs that can build all three tiers of industrial buildings

    Disadvantages
    -Lacks unique unit set for the most part. Needs to buy other equipment.
    -Starts off very small (4 cities) and needs to build from the ground up. At war with powerful neighbor

    India
    Advantages
    -The only civ that can buy equipment from anyone they darn well please. May allow a tech advantage over neighbors because I want to make it so you can only buy equipment one level below another country's best (so you'd buy Spitfires and not F-86, but given you can choose between 3 civs, you can buy from whoever has the better stuff).
    -Has opportunity to become industrial powerhouse as one of 2 civs that can build all three tiers of industrial buildings
    -Only civ that can access Democracy government, with all that entails.

    Disadvantages
    -Lacks unique unit set for the most part.
    -Starts small and at war with powerful neighbor.

    Any suggestions for changes are welcome...
     

Share This Page