Announcement

Collapse
No announcement yet.

E's Source Code attempts

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

  • #31
    Originally posted by Martin Gühmann
    So g represents a good but of what type is this g? It shouldn't be a problem to guess if you know what type the argument of HasResource is of.
    Not sure what you mean by "what type is this g" Not sure what you mean by "type." but g looks like a numeric value for the good so it matches the good number in the array of all goods of the game. And g passes that number to see if the city has that good. Hasesource looks like it just passes g and tels whether or not (true or false) if the city is collecting or that resource.

    So I think I have to do something that checks true or false if he unit has the NeedsCity Good than it checks if true or false if the good is collecting it. I dig more but my try retyping the code and trying to compile it. I may get lucky.
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • #32
      I messed with some code and had to monkey with the lines. And getting the true and false took a second or two. But I tested it on the warrior and it works EXCEPT that it only checks if there is a good yes or no. Not a specific good. So I feel a lot closer. How can I make it a specific good? I don'tthink there is a function to draw a specific good out...


      Code:
      //Added by E -  If Unit needs a city good it checks if the city has the resource
      	if(rec->GetNeedsCityGood() > 0) {
      		sint32 g;
      		bool found = false;
      		for(g = 0; g < g_theResourceDB->NumRecords(); g++) {
      			if(IsLocalResource(g)) {
      				if(HasResource(g) == TRUE &&	
      					rec->GetNeedsCityGoodIndex()) 
      					found = true;
      				break;
      			}
      		}
      				if(!found)
      				return FALSE;
      	}
      and here's the citydata.cpp.
      Attached Files
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • #33
        Well E you didn't tell me about your design decision, whether you want it so that the mod can only specify one good per unit or multiple ones per unit. And if multiple ones per unit whether the player needs them all in the list or only one of them.

        Second design decision. Actual you already told me that the unit should be allowed to build if the city collects the good or if it receives the good via trade.

        Does HasResource tell you whether the city collects the good or receives it via trade?

        What does tell you IsLocalResource about a certain kind of good?

        Originally posted by E
        Not sure what you mean by "what type is this g" Not sure what you mean by "type." but g looks like a numeric value for the good so it matches the good number in the array of all goods of the game.
        Actual I asked you about the type of g like I asked for the return type of the HasResource method before. In your last code fragment you posted it is for instance a sint32 or in other words it is a signed long int. And you are right it is in the end a plain number that you can use to access a good in the Resource database, and all other data structures whose elements represents certain bits of information about goods and contain usually as much elements as the resource database.

        So how many elements contain the following data structures:

        Resources m_collectingResources;
        Resources m_sellingResources;
        Resources m_buyingResources;

        I you don't know the answer take a look into the constructor of CityData.

        And of course what represent these data structures, or better the data contained.

        Originally posted by E
        And g passes that number to see if the city has that good. Hasesource looks like it just passes g and tels whether or not (true or false) if the city is collecting or that resource.
        Rethink the statement about the HasResource.

        Originally posted by E
        So I think I have to do something that checks true or false if he unit has the NeedsCity Good than it checks if true or false if the good is collecting it. I dig more but my try retyping the code and trying to compile it. I may get lucky.
        It's more simple.

        Code:
        if(HasResource(g) == TRUE &&
        That's very bad code, HasResource(g) returns already TRUE or FALSE, no need to check it again.

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

        Comment


        • #34
          Originally posted by Martin Gühmann
          Well E you didn't tell me about your design decision, whether you want it so that the mod can only specify one good per unit or multiple ones per unit. And if multiple ones per unit whether the player needs them all in the list or only one of them.
          Really, for modders sake we ought to do all three but name them different things. But for now I'll try one good per unit.


          Second design decision. Actual you already told me that the unit should be allowed to build if the city collects the good or if it receives the good via trade.

          Does HasResource tell you whether the city collects the good or receives it via trade?

          What does tell you IsLocalResource about a certain kind of good?
          HasResource says collectinggood is great so I think it includes trade or both. IsLocal is only for cities that have it in the radius. atleast as I understand it.


          Actual I asked you about the type of g like I asked for the return type of the HasResource method before. In your last code fragment you posted it is for instance a sint32 or in other words it is a signed long int. And you are right it is in the end a plain number that you can use to access a good in the Resource database, and all other data structures whose elements represents certain bits of information about goods and contain usually as much elements as the resource database.

          So how many elements contain the following data structures:

          Resources m_collectingResources;
          Resources m_sellingResources;
          Resources m_buyingResources;

          I you don't know the answer take a look into the constructor of CityData.

          And of course what represent these data structures, or better the data contained.

          Rethink the statement about the HasResource.



          It's more simple.

          Code:
          if(HasResource(g) == TRUE &&
          That's very bad code, HasResource(g) returns already TRUE or FALSE, no need to check it again.

          -Martin
          i'll take a look at it. I think I know what I have to do, just didnt have the chance to do it yet. Whats hard though is that when you use terms like constructor etc I look them up in my dummies book and the code there is similar but different from the ctp2. its the hard part of having a "crawl" book and look at a "running" code and I still barely got to "walking." My definition understanding is seriously lacking but I kind of unerstand howthings plug together.

          but hell I was thrilled that I got the code partly working and I think I know what I have to do to get it working.
          Formerly known as "E" on Apolyton

          See me at Civfanatics.com

          Comment


          • #35
            Originally posted by E
            Really, for modders sake we ought to do all three but name them different things. But for now I'll try one good per unit.
            Well that implies now some major design changes to your code. However what happens if you reduce the other two multiple things to one good meaning that the list only contains one good?

            Originally posted by E
            HasResource says collectinggood is great so I think it includes trade or both. IsLocal is only for cities that have it in the radius. atleast as I understand it.
            You are right about IsLocalResource, but look closer on HasResource, the names inside that function are obvious.

            Originally posted by E
            i'll take a look at it. I think I know what I have to do, just didnt have the chance to do it yet. Whats hard though is that when you use terms like constructor etc I look them up in my dummies book and the code there is similar but different from the ctp2.
            Well you have to get the terms constructor and destructor. Basically a constructor fills the object with values and finds and allocates free memory for its members. A destructor frees heap memory. That's necessary otherwise this memory on the heap is lost to the program. That's called a memory leak.

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

            Comment


            • #36
              Well my idea worked and the code now limits it to specific good.

              Code:
              //Added by E -  If Unit needs a city good it checks if the city has the resource
              	if(rec->GetNeedsCityGood() > 0) {
              		sint32 g;
              		bool found = false;
              		for(g = 0; g < g_theResourceDB->NumRecords(); g++) {
              			if(IsLocalResource(g)) {
              				if(HasResource(g) && rec->GetNeedsCityGoodIndex()== g) 
              					found = true;
              				break;
              			}
              		}
              				if(!found)
              				return FALSE;
              	}
              But I I think because of the LocalRsource part when I trade it, the city can no longer produce it and the receiving city cant. Not exactly what I want but its useful because perhaps in a agame you have to choose between building sophisticated units (or buildings) or selling it for profit. I think Oil could be used for that.
              Last edited by Ekmek; August 6, 2005, 01:33.
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • #37
                Well, E, your code is slow. It contains a lot of unnecessary stuff and actual it doesn't do what it was intended to do.

                Again you told me that it was supposed to allow to build the unit in question if the city collects the good in question or received it via trade. So you want to check all the goods collected in the city radius. And all goods that the city is buying.

                Then again you didn't answer these question:

                Originally posted by Martin Gühmann
                So how many elements contain the following data structures:

                Resources m_collectingResources;
                Resources m_sellingResources;
                Resources m_buyingResources;
                Originally posted by Martin Gühmann
                And of course what represent these data structures, or better the data contained.
                Originally posted by Martin Gühmann
                Well that implies now some major design changes to your code. However what happens if you reduce the other two multiple things to one good meaning that the list only contains one good?
                Originally posted by E
                But I I think because of the LocalRsource part when I trade it, the city can no longer produce it and the receiving city cant.
                That's wrong and you already answered the question about what you tell you the IsLocalResource method.

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

                Comment


                • #38
                  Yeah, I knew the buyresources was the problem but I was looking for code that lets me do a HasrEsource or isLocalResource for m_buyingresources. I figure I have to do a || or thing for it too.
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • #39
                    Originally posted by E
                    Yeah, I knew the buyresources was the problem but I was looking for code that lets me do a HasrEsource or isLocalResource for m_buyingresources. I figure I have to do a || or thing for it too.
                    Actual you want to combine those Resources that are collected inside the city radius and that are received via trade. It shouldn't so difficuilt to put the pieces of the puzzle together.

                    And before I forget it: Answer the questions in my last post, or don't you want to do some progress?

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

                    Comment


                    • #40
                      So how many elements contain the following data structures:

                      Resources m_collectingResources;
                      Resources m_sellingResources;
                      Resources m_buyingResources;
                      elements? not sure what you mean, do mean functions? all we have is IsLocalResource and HasResource. I did try to create:
                      Code:
                      //this city is buying some sint32 resource added by E 9-Aug-05
                      BOOL CityData::IsBuyingResource(sint32 resource) const
                      {
                      	return m_buyingResources[resource] > 0;
                      }
                      It didnt work because I got:
                      Code:
                      F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4850) : error C2039: 'IsBuyingResource' : is not a member of 'CityData'
                              F:\SVN-Code\trunk\ctp2_code\gs\gameobj\citydata.h(147) : see declaration of 'CityData'
                      F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4851) : error C2270: 'IsBuyingResource' : modifiers not allowed on nonmember functions
                      F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4852) : error C2065: 'm_buyingResources' : undeclared identifier
                      F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4852) : error C2109: subscript requires array or pointer type
                      I guess I have to do something with the sellingto code there but then I get into the whole identifying the city issue which I think is not what I need.


                      Originally posted by Martin Gühmann
                      And of course what represent these data structures, or better the data contained.
                      IsLocalResource appears to test if its collecting a resource in the cityradius. HasREsource check if it is collectingmore of a resource than its selling. So it looks likeit checks if it is NOT selling the resource that IsLocal.


                      Originally posted by Martin Gühmann
                      Well that implies now some major design changes to your code. However what happens if you reduce the other two multiple things to one good meaning that the list only contains one good?
                      NOt sure what you are implying here...Are you saying what I specify for the Unit affects how the NeedsCityGood works? Or are saying that since I said all three are whats preferred, I was only meaning in time we may not want to limit how resources are utilized to build things. Mainly since the discussion is pretty diverse on it. But for now I'll settle with whats in the radius and if its buying the resource.
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • #41
                        Originally posted by E
                        elements? not sure what you mean, do mean functions? all we have is IsLocalResource and HasResource.
                        I told you to take a close look on the Resource class, it contains a member called m_supply. That's an array of integers. To figure out how many elements it contains I told you to take a look on the CityData constructor. A constructor is this special function that has the name of the class, and the destructor by the way is a function with the same name but with a ~ in front it.

                        In the CityData constructor you can see that the members of type Resource are initialized with g_theResourceDB->NumRecords(), that means that the number of elements you have wrapped in these objects are equal to the number of records you have in the ResourceDB for each good one element.

                        Now you have to understand with these elements represent. So check the resource class. Espeacilly these add methods.

                        Originally posted by E
                        I did try to create:

                        Code:
                        //this city is buying some sint32 resource added by E 9-Aug-05
                        BOOL CityData::IsBuyingResource(sint32 resource) const
                        {
                        	return m_buyingResources[resource] > 0;
                        }
                        It didnt work because I got:
                        Code:
                        F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4850) : error C2039: 'IsBuyingResource' : is not a member of 'CityData'
                                F:\SVN-Code\trunk\ctp2_code\gs\gameobj\citydata.h(147) : see declaration of 'CityData'
                        F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4851) : error C2270: 'IsBuyingResource' : modifiers not allowed on nonmember functions
                        F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4852) : error C2065: 'm_buyingResources' : undeclared identifier
                        F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4852) : error C2109: subscript requires array or pointer type
                        I guess I have to do something with the sellingto code there but then I get into the whole identifying the city issue which I think is not what I need.
                        Obviously you did not modify CtiyData.h. But however you don't need to add such a method, because you can use m_buyingResources, m_sellingResources, m_collectingResources

                        Originally posted by E
                        IsLocalResource appears to test if its collecting a resource in the cityradius. HasREsource check if it is collectingmore of a resource than its selling. So it looks likeit checks if it is NOT selling the resource that IsLocal.
                        I think this is right but for clearity I reword it. It checks whether the good in question is in the city radius and that the city does not sell it.

                        Originally posted by E
                        NOt sure what you are implying here...Are you saying what I specify for the Unit affects how the NeedsCityGood works? Or are saying that since I said all three are whats preferred, I was only meaning in time we may not want to limit how resources are utilized to build things. Mainly since the discussion is pretty diverse on it. But for now I'll settle with whats in the radius and if its buying the resource.
                        I gave you three possibilities:

                        First the only one good choice.
                        Second the at least one of good choice.
                        Third the all good choice.

                        The first possibility contain only one good:

                        First case:

                        good1

                        The last two posibilities consits of lists of goods:

                        Second case:

                        good1
                        ||good2
                        ||good3
                        ||good4

                        Third case:

                        good1
                        &&good2
                        &&good3
                        &&good4

                        So again what happens if you reduce the list in case 2 and 3 to just one element, so that only the first element of these list is left for instance?

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

                        Comment


                        • #42
                          Well E, I think you need again some push, otherwise you will answer in a month when I will have forgotten what you were trying to do here.

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

                          Comment


                          • #43
                            Sorry, the last week I havent been able to do much on my home computer. All apolyton contact has been at work
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • #44
                              Martin,

                              I'm kind of stumped I tried:
                              Code:
                              				if(HasResource(g) || (m_buyingResources[g] ) && rec->GetNeedsCityGoodIndex()== g)
                              AND...
                              Code:
                              				if(HasResource(g) || (m_buyingResources[g] > 0) && rec->GetNeedsCityGoodIndex()== g)
                              I based my stuff off of HasResource used the m_collectingresource[resource] and although it compiles when I try to trade with a city the city cant build the Unit.
                              Formerly known as "E" on Apolyton

                              See me at Civfanatics.com

                              Comment


                              • #45
                                E, come on, you should answer my question first.

                                [SIZE]Originally posted by E[/SIZE]
                                I gave you three possibilities:

                                First the only one good choice.
                                Second the at least one of good choice.
                                Third the all good choice.

                                The first possibility contain only one good:

                                First case:

                                good1

                                The last two posibilities consits of lists of goods:

                                Second case:

                                good1
                                ||good2
                                ||good3
                                ||good4

                                Third case:

                                good1
                                &&good2
                                &&good3
                                &&good4

                                So again what happens if you reduce the list in case 2 and 3 to just one element, so that only the first element of these list is left for instance?
                                That shouldn't be too difficuilt now. Or are you affraid that the answer could reduce a little bit your work, E?

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

                                Comment

                                Working...
                                X