Announcement

Collapse
No announcement yet.

Slic

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Slic

    Wonder if I could get a little advice on SLIC please.

    Have ben doing a bit for myself but cant get this bit to work. Curiously, it works sometimes but not others.

    I have incorporated Locutu's repair code into a cradle mod expansion. Works fine for cities. Have developed a new unit, the supply train, wanted the code to work for units stacked with a supply train.
    Code-

    for (a = 0; a < player[0].armies; a = a + 1) {
    GetArmyByIndex(player[0], a, tmpArmy);
    army[0] = tmpArmy;
    i = 0;
    while(i < army[0].size && success == 0) {
    GetUnitFromArmy(army[0], i, tmpUnit);
    if(tmpUnit.type == UnitDB(UNIT_SUPPLY_TRAIN)) {
    success = 1;
    //}
    }
    i = i + 1;
    }
    if(success == 1) {
    tmpLoc = tmpUnit.location;
    for (k = 0; k < GetUnitsAtLocation(tmpLoc); k = k + 1) {
    GetUnitFromCell(tmpLoc, k, tmpUnit);


    Then the repair code goes here, have declared all things, returns no errors, just does not work most of the time.

    I hope the line format comes across ok in the post.

  • #2
    The only thing I can think of is that there might be a problem with the army array. There is a bug with built in arrays, for instance if you assign a variable to a field of it and you used this it loses its value. Therfore you should better use this code:

    Code:
    for (a = 0; a < player[0].armies; a = a + 1) {
    	GetArmyByIndex(player[0], a, tmpArmy);
    	i = 0;
    	while(i < tmpArmy.size && success == 0) {
    		GetUnitFromArmy(tmpArmy, i, tmpUnit);
    		if(tmpUnit.type == UnitDB(UNIT_SUPPLY_TRAIN)) {
    			success = 1;
    		}
    		i = i + 1;
    	}
    	if(success == 1) {
    		tmpLoc = tmpUnit.location;
    		for (k = 0; k < GetUnitsAtLocation(tmpLoc); k = k + 1) {
    			GetUnitFromCell(tmpLoc, k, tmpUnit);
    In theory your code should work, but it might not work, however this way, you also save an assignement.

    -Martin
    Civ2 military advisor: "No complaints, Sir!"

    Comment


    • #3
      Thanks Martin, I will give that a try.:-)))

      Comment


      • #4
        I tried the above and it did not work so in frustration I deleted it all and started again. Copied the repair code again, deleted the 3 lines that referred to cities and changed two others where it said tmpCity to tmpUnit then went back to IW's introduction to SLIC.

        Inserted-
        for (i = 0; i < player[0].units; i = i + 1) {
        GetUnitByIndex(player[0], i, tmpUnit);
        if(tmpUnit.type == UnitDB(UNIT_SUPPLY_TRAIN)){

        And, hey presto it has worked half a dozen times in tests using cheat mode.

        Comment


        • #5
          New Problem.

          Cant figure out how to write into this bit of code the following. I am using this to give an advance if I build a colony on a good (iron ore). It works fine.


          elseif (HasGood(ColonyLoc)==ResourceDB(TERRAIN_WHITE_MOUN TAIN_GOOD_TWO)){ //iron ore
          if(HasAdvance(tmpPlayer, ID_ADVANCE_BRONZE_WORKING)) {

          Event:GrantAdvance(tmpPlayer, AdvanceDB(ADVANCE_METAL_WORKING),0);
          }
          else {
          Event:GrantAdvance(tmpPlayer, AdvanceDB(ADVANCE_BRONZE_WORKING),0);
          }
          }
          What I wanted to do is -
          Check for Bronze Working and give it to the player if he does not have it,
          else give metal working if the player already has bronze working,
          else give iron working if the player already has metal working.

          Not experienced enough to write it.

          Help appreciated.

          Comment


          • #6
            Originally posted by stankarp
            What I wanted to do is -
            Check for Bronze Working and give it to the player if he does not have it,
            else give metal working if the player already has bronze working,
            else give iron working if the player already has metal working.

            Not experienced enough to write it.

            Help appreciated.
            You should do something like this:

            Code:
            if(!HasAdvance(tmpPlayer, ID_ADVANCE_BRONZE_WORKING)) {
            	Event:GrantAdvance(tmpPlayer, AdvanceDB(ADVANCE_BRONZE_WORKING),0);
            }
            else if(!HasAdvance(tmpPlayer, ID_ADVANCE_METAL_WORKING)){
            	Event:GrantAdvance(tmpPlayer, AdvanceDB(ADVANCE_METAL_WORKING),0);
            }
            else if(!HasAdvance(tmpPlayer, ID_ADVANCE_IRON_WORKING)){
            	Event:GrantAdvance(tmpPlayer, AdvanceDB(ADVANCE_IRON_WORKING),0);
            }
            For the other code you should check the retuen value of GetUnitByIndex so that you new if the function filled the tmpUnit variable with a value:

            Code:
            for (i = 0; i < player[0].units; i = i + 1) {
            	if( GetUnitByIndex(player[0], i, tmpUnit)){
            		if(tmpUnit.type == UnitDB(UNIT_SUPPLY_TRAIN)){
            -Martin
            Civ2 military advisor: "No complaints, Sir!"

            Comment


            • #7
              Thanks Martin, will give that a try.

              Comment


              • #8
                Sorry, forgot to update and thank Martin.

                Code now working fine, thanks:-))

                Comment


                • #9
                  Hi, wondering if I could get someone to verify this will work. My programming ability doesnt match my big ideas, its from the disasters number generator.
                  tmpPlayer = player[0];
                  if((g.year >= 3) && (g.year <= 150)) {
                  PlagueChance = random(80);
                  }
                  elseif((g.year >= 151) && (g.year <= 300)) {
                  PlagueChance = random(120);
                  }
                  elseif((g.year >= 301) && (g.year <= 1000)) {
                  PlagueChance = random(80);
                  }
                  The idea is that the chance of the event starts of higher, drops back then gets greater again. It does not return any errors but because of the nature of the code, it is hard to check accurately.

                  Help much appreciated.

                  Comment


                  • #10
                    Another small one, this one returns no errors but does not work as it should.

                    I have a new tileimp, Outpost. I want to prevent the human player pillaging his OWN Outposts but not other players Outposts.

                    HandleEvent(CutImprovements)'Stan_PillageOutpost' pre {
                    location_t tmpLoc;

                    if(IsHumanPlayer(player[0])){
                    if (TileHasImprovement(tmpLoc, TerrainImprovementDB(TILEIMP_OUTPOST))){
                    if(CellOwner(tmpLoc)){
                    return STOP;
                    }
                    }
                    }
                    }

                    I can prevent any Outposts being pillaged but cant work out the correct code to limit it to pillaging your own Outposts.

                    Comment


                    • #11
                      Silly question time: Wouldnt the human just know not to pillage their own outposts?
                      Call to Power 2: Apolyton Edition - download the latest version (12th June 2011)
                      CtP2 AE Wiki & Modding Reference
                      One way to compile the CtP2 Source Code.

                      Comment


                      • #12
                        Bit more to it.

                        I am working on a code that gives an advance to the human if he disbands a nomad type and spends 300-600 pw on a particular good to create a new tile improvement-OUTPOST, eg, on copper, you get copper smelting, a different way of treating strategic goods.

                        If you already have copper smelting you get bronze working. Iron is better, with 6 potential advances from copper smelting to paper (after Barracks).

                        The obvious cheat is that the human keeps disbanding nomads on the same good which is not what I had in mind. I have altered the code so that if you disband a nomad type on an existing outpost, you get nothing.

                        But the loophole is you pillage the Outpost away and then disband the nomad. Thats why I want to prevent the human from pillaging his own Outposts, so he has to find another good of the type to get the next advance.

                        The code also collects gold and/or pw from the outpost, so every good on the map can be used in theory. Some also fight plague and famine in my disasters code variation.

                        Comment


                        • #13
                          Sounds cool Stankarp (can the AI handle it?) maybe another option is that you have to upgrade to a different unit to get the next advance. like after nomad you get colonist and a colonist has to disband. colonists would be available in a diffferent age so it will keep the players from advance to fast by goods.


                          If you need graphics I'd like to help, alas my stuff is in storage until october
                          Formerly known as "E" on Apolyton

                          See me at Civfanatics.com

                          Comment


                          • #14
                            Hi E,

                            To some extent it starts to cost more for advances because in Cradle, nomads become obsolete at Tribunal Empire and the new settler costs heaps, so by then you really think about disbanding such units for an advance. Especially as the code only gives you early advances.

                            Normally a player would not pillage a valuable tilimp of theirs but Iron is such a valuable resource, it might be worth it to get to phalanx quickly before the AI.

                            The ai does not build outposts on resources. It does build it as a normal tileimp. It already gets heaps of pw and gold from a cheat slic code and tilimp as well so it is always well ahead on tech. My code was a way of keeping pace for a while.

                            BTW E, did you see my comment re bad shadow files in the sprite editor thread? I am sure the bad shadows come from running makespr in win XP.

                            Comment


                            • #15
                              Originally posted by stankarp
                              Hi, wondering if I could get someone to verify this will work. My programming ability doesnt match my big ideas, its from the disasters number generator.
                              tmpPlayer = player[0];
                              if((g.year >= 3) && (g.year <= 150)) {
                              PlagueChance = random(80);
                              }
                              elseif((g.year >= 151) && (g.year <= 300)) {
                              PlagueChance = random(120);
                              }
                              elseif((g.year >= 301) && (g.year <= 1000)) {
                              PlagueChance = random(80);
                              }
                              The idea is that the chance of the event starts of higher, drops back then gets greater again. It does not return any errors but because of the nature of the code, it is hard to check accurately.

                              Help much appreciated.
                              I would do it rather like this:

                              Code:
                              PlagueRan = Random(100);
                              if((g.year > 150) && (g.year <= 300)){
                              	PlagueChance = 80;
                              }
                              else{
                              	PlagueChance = 40;
                              }
                              if(PlagueRan < PlagueChance)
                              	//Do something
                              }
                              This code does something in 80 of 100 cases from turn 151 to turn 300, while the other turns the chance is only 40%. Your code is a little bit different, probably you have a threshold as well, but as it is not part of the code you posted I assume it is fixed. Let's say your threshold is 60 and if the PlagueChance is bigger a plague happens, this means in that case the plague chance is 50% when it is high and 25% when it is low. And that leads me two the conclusion that your code works as well, but might be not so obvious what it does as my code.

                              For your second problem replace the line:
                              Code:
                              if(CellOwner(tmpLoc)){
                              by
                              Code:
                              if(CellOwner(tmpLoc) == player[0].owner){
                              And you should be fine.

                              -Martin
                              Civ2 military advisor: "No complaints, Sir!"

                              Comment

                              Working...
                              X