Announcement

Collapse
No announcement yet.

E's Source Code attempts

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

  • #46
    Martin, I'm going to go withe first case. Its the one that applies best to CtP2 right now.

    Civ3 lets you build colonies that sends goods to cities and you can share via network. In this NeedsCityGood it makes it only in a radius or by trade so if I make it many gods than it will be impossible to make a unit. So lets go with just one good, mainly since my code seems structured to it now.

    there are other things we need to do with goods but I think NeedsCityGood will be a good start (and could make the AtG scenario more interesting once we get around to fixing that).
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • #47
      Originally posted by E
      Martin, I'm going to go withe first case. Its the one that applies best to CtP2 right now.
      You gottn't my question, so again:

      Case 1:

      good1


      Case 2

      good1
      ||good2
      ||good3
      ||good4


      Case 3

      good1
      &&good2
      &&good3
      &&good4

      What happens if you put in the list of case 2 and case 3 just one element, for visualization I used the strike out. Once you have answered this question, ask yourself whether you still need to implement case 1.

      Now answer this question and post the answer. And just to make it clear, I won't help you until you will have answered my question.

      And now it shouldn't be too difficuilt anymore.

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

      Comment


      • #48
        ok, in "or" statements the city must have good1 or good2 or good3 in order to build the unit. (aka the function will return true if the city has and of the "or" goods, kind of like what ahappened with my first code hen it passed any good in the radius)

        in the "and" statements the city must have all of the goods in order to build it (aka the function will return false if any of the && statements are false)

        If a "or" is not there then the function will still return true if you have good1 but no other goods.

        In the "and" case it will return false if the good is not there when you try and build the unit.


        this is based on my assumption that you meand the good1 etc is the good listed in the needscitygood part, or were refering to the good in the DB? or the good that has to be in the radius?
        Formerly known as "E" on Apolyton

        See me at Civfanatics.com

        Comment


        • #49
          You gottn't my question. Look at the lists with the strike outs. You don't need to have any knowledge about C++ or any knowledge about the source code of CTP2, just look at the cases in my previous post.

          There you see that case Case 2 and Case 3 are the multiple ones. They are lists containing four elments or entries or whatever you want to call them. You don't need to put more then one element into these lists, you can put just one element into such a list. This is visualized by the strike outs. Now if you remove the striked out elements, what happens to Case 2 and Case3, especially if you compare them to Case 1.

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

          Comment


          • #50
            as you said before:
            First the only one good choice.
            Second the at least one of good choice.
            Third the all good choice.

            So you are saying that case2 and case3 will meet the requirements of case 1. Ok. But right now I don't need to code multiple goods because the other game elements don't help.

            To me it looks like you are asking if I want to include multiple good stuff in an either or/and case. Civ3 uses AND but we can use OR also, which I can code later. Right now I just want to get if a city has a good OR is is buying a good.
            Formerly known as "E" on Apolyton

            See me at Civfanatics.com

            Comment


            • #51
              Originally posted by E
              So you are saying that case2 and case3 will meet the requirements of case 1.
              To reword it a little bit, if you just put one element into these lists of case2 and case3, then they become case1. The consequence is that implementing case1 is useless, as you get it if you implement one of the others. And as you think that case2 and case3 are of use, so why bothering with case1?

              Originally posted by E
              Ok. But right now I don't need to code multiple goods because the other game elements don't help.
              I don't understand this sentence.

              Originally posted by E
              To me it looks like you are asking if I want to include multiple good stuff in an either or/and case. Civ3 uses AND but we can use OR also, which I can code later. Right now I just want to get if a city has a good OR is is buying a good.
              I don't know which one is easier, but you already implemented similar code for the OR case, for instance the culture only code is something like this. Or your intended Civ only code.

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

              Comment


              • #52
                Well to answer now your question.

                Whether you have multiple version or single version of GetNeedsCityGoodIndex it returns a resource database index, that's an integer.

                m_buyingResources and m_collectingResources store the number of goods the city receives or collects respectively. Both have the size of the resource database. Therefore the [] operator accepts resource database indeces, which as is said are numbers.

                By the way you just want to know whether the entry in one of them is bigger zero. So sum the numbers and then do the check, should save a one or two operations.

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

                Comment


                • #53
                  thanks Martin, tonight or tomorrow I should be able to get to it. Once this is done I think I'm going to try adding that pop-up about if you want to attack someone you are at peace with. its needed I think.
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • #54
                    Finally it works!

                    Code:
                    	if(rec->GetNeedsCityGood() > 0) {
                    		sint32 g;
                    		bool found = false;
                    		for(g = 0; g < g_theResourceDB->NumRecords(); g++) {
                    			if((m_buyingResources[g] + m_collectingResources[g]) > 0) {
                    				if((HasResource(g) || m_buyingResources[g]) && rec->GetNeedsCityGoodIndex()== g) 
                    					found = true;
                    					break;
                    			}
                    		}
                    				if(!found)
                    				return FALSE;
                    	}
                    but you mentioned it was slow before, is there any way to optimize it? I'll post it once you approve
                    Formerly known as "E" on Apolyton

                    See me at Civfanatics.com

                    Comment


                    • #55
                      But this doesn't look like the CityStyleOnly for instance. And GetNeedsCityGoodIndex requires one argument, in the Case2. And cycling through the whole resource database is a waste of time, your CityStyleOnly code doesn't cycle through thewhole city style database, either. Just through the elements of CityStyleOnly.

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

                      Comment


                      • #56
                        when I pased g through NeedsCityGood it said that it does not take an argument.

                        I tried copying the citystyle a few times and got A LOT of errors. I assue you were talking about the line in bold which I used to try to match NeedsCityGood == m_buyingresources but it was not having it.

                        Code:
                        // Added by E - Compares Unit CityStyle to the CityStyle of the City
                        	if(rec->GetNumCityStyleOnly() > 0) {
                        		sint32 s;
                        		bool found = false;
                        		for(s = 0; s < rec->GetNumCityStyleOnly(); s++) {
                        			[b]if(rec->GetCityStyleOnlyIndex(s) == m_cityStyle) {[/b]
                        				found = true;
                        				break;
                        			}
                        		}
                        		if(!found)
                        			return FALSE;
                        	}
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • #57
                          Originally posted by E
                          when I pased g through NeedsCityGood it said that it does not take an argument.
                          Of course to make it accept multiple entries you have to modify the according *.cdb file. And when you are doing it add an NeedsCityGoodAll flag, this isn't far away once you have done this.

                          Originally posted by E
                          I tried copying the citystyle a few times and got A LOT of errors. I assue you were talking about the line in bold which I used to try to match NeedsCityGood == m_buyingresources but it was not having it.
                          Of course this equal check doesn't work, NeedsCityGood isn't defined anywhere.

                          Originally posted by E
                          Code:
                          // Added by E - Compares Unit CityStyle to the CityStyle of the City
                          	if(rec->GetNumCityStyleOnly() > 0) {
                          		sint32 s;
                          		bool found = false;
                          		for(s = 0; s < rec->GetNumCityStyleOnly(); s++) {
                          			[b]if(rec->GetCityStyleOnlyIndex(s) == m_cityStyle) {[/b]
                          				found = true;
                          				break;
                          			}
                          		}
                          		if(!found)
                          			return FALSE;
                          	}
                          Actual I told you how the condition instead of the bold line looks like. If the sum of collecting and buying resources is bigger zero, then you have found it, and the type of resource you want to check comes out of GetNeedsCityGoodIndex method.

                          So basical you have to modify one line in a *.cdb file and three lines in your code and delete another line. And of course you have to fix the indention.

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

                          Comment


                          • #58
                            Originally posted by Martin Gühmann


                            Of course to make it accept multiple entries you have to modify the according *.cdb file. And when you are doing it add an NeedsCityGoodAll flag, this isn't far away once you have done this.
                            modify the cdb? I think I know what I have to do....
                            NeedsCityGoodAll flag...are you intending that if one city has a resource or is buying resource than the unit is available to all cities?


                            Of course this equal check doesn't work, NeedsCityGood isn't defined anywhere.
                            Thats what the compiler said

                            Actual I told you how the condition instead of the bold line looks like. If the sum of collecting and buying resources is bigger zero, then you have found it, and the type of resource you want to check comes out of GetNeedsCityGoodIndex method.

                            So basical you have to modify one line in a *.cdb file and three lines in your code and delete another line. And of course you have to fix the indention.

                            -Martin

                            I assume these are the bold I need to modify. I guess I need to combine them?

                            Code:
                            	if(rec->GetNeedsCityGood() > 0) {
                            		sint32 g;
                            		bool found = false;
                            		[b]for(g = 0; g < g_theResourceDB->NumRecords(); g++) {
                            			if((m_buyingResources[g] + m_collectingResources[g]) > 0) {
                            				if((HasResource(g) || m_buyingResources[g]) && rec->GetNeedsCityGoodIndex()== g) [/b]
                            					found = true;
                            					break;
                            			}
                            		}
                            				if(!found)
                            				return FALSE;
                            	}
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • #59
                              Originally posted by E
                              modify the cdb? I think I know what I have to do....
                              NeedsCityGoodAll flag...are you intending that if one city has a resource or is buying resource than the unit is available to all cities?
                              No, actual this is Case3. Easy to implement once you have done Case2.

                              Originally posted by E
                              I assume these are the bold I need to modify. I guess I need to combine them?

                              Code:
                              	if(rec->GetNeedsCityGood() > 0) {
                              		sint32 g;
                              		bool found = false;
                              		[b]for(g = 0; g < g_theResourceDB->NumRecords(); g++) {
                              			if((m_buyingResources[g] + m_collectingResources[g]) > 0) {
                              				if((HasResource(g) || m_buyingResources[g]) && rec->GetNeedsCityGoodIndex()== g) [/b]
                              					found = true;
                              					break;
                              			}
                              		}
                              				if(!found)
                              				return FALSE;
                              	}
                              Not quite, you got 2 of 3 to modify, but the line to delete is under the bold.

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

                              Comment


                              • #60
                                Originally posted by Martin Gühmann
                                No, actual this is Case3. Easy to implement once you have done Case2.
                                This is something I was gonna suggest, excellent Being able to build a unit in all cities, with the Good anywhere in your civ that is.

                                Also, I tried to use two NeedsCityGood flags for one unit but it didnt work in the game (didnt cause a fault), I assume it wasnt implemented. Is this possible to implement too?
                                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

                                Working...
                                X