[SDK MODCOMP] Food From Animals

I found a bug in this mod. When you have no cities (for example, right at the start of the game, or when playing with the require complete kill option) and kill a creature that would provide food, the game crashes completely and sends you immediately back to the desktop.

I am currently working on fixing this issue.
 
I found a bug in this mod. When you have no cities (for example, right at the start of the game, or when playing with the require complete kill option) and kill a creature that would provide food, the game crashes completely and sends you immediately back to the desktop.

I am currently working on fixing this issue.

Yeah, I realized this might happen. It's a pretty easy fix.
 
Ok, I have solved the problem and it works properly now.

The issue was caused by findCity function returning NULL if no city of the proper specifications can be found. In order to resolve it, the following code needs to be changed:

Code:
           /*** FOODFROMANIMALS 8/14/07 by DPII START ***/
            if (!pDefender->isBarbarian())
            {
                pNearestCity = GC.getMapINLINE().findCity(getX_INLINE(), getY_INLINE(), pDefender->getOwnerINLINE(), NO_TEAM, true, false);
                    for (iI = 0; iI < NUM_YIELD_TYPES; iI++)
                    {
                        if (GC.getUnitInfo(getUnitType()).getYieldFromKill(iI) > 0)
                        {
                            iYield = GC.getUnitInfo(getUnitType()).getYieldFromKill((YieldTypes)iI);
                            switch ((YieldTypes)iI)
                            {
                            case YIELD_FOOD:
                                pNearestCity->changeFood(iYield);
                                break;

                            case YIELD_PRODUCTION:
                                pNearestCity->changeProduction(iYield);
                                break;
                            }
                            szBuffer = gDLL->getText("TXT_KEY_MISC_YIELD_FROM_UNIT", GC.getUnitInfo(pDefender->getUnitType()).getTextKeyWide(), iYield, GC.getYieldInfo((YieldTypes)iI).getChar(), pNearestCity->getNameKey());
                            gDLL->getInterfaceIFace()->addMessage(pNearestCity->getOwnerINLINE(), false, GC.getEVENT_MESSAGE_TIME(), szBuffer,  ARTFILEMGR.getInterfaceArtInfo("WORLDBUILDER_CITY_EDIT")->getPath(), MESSAGE_TYPE_INFO, NULL, (ColorTypes)GC.getInfoTypeForString("COLOR_WHITE"), pDefender->getX_INLINE(), pDefender->getY_INLINE(), true, true);
                        }
                    }
            }
            /*** FOODFROMANIMALS END ***/

You should add conditional statements to catch if a NULL is returned, like this:

Code:
           /*** FOODFROMANIMALS 8/14/07 by DPII START ***/
            if (!pDefender->isBarbarian())
            {
                pNearestCity = GC.getMapINLINE().findCity(getX_INLINE(), getY_INLINE(), pDefender->getOwnerINLINE(), NO_TEAM, true, false);
[B]                if(pNearestCity != NULL)
                {
[/B]                    for (iI = 0; iI < NUM_YIELD_TYPES; iI++)
                    {
                        if (GC.getUnitInfo(getUnitType()).getYieldFromKill(iI) > 0)
                        {
                            iYield = GC.getUnitInfo(getUnitType()).getYieldFromKill((YieldTypes)iI);
                            switch ((YieldTypes)iI)
                            {
                            case YIELD_FOOD:
                                pNearestCity->changeFood(iYield);
                                break;

                            case YIELD_PRODUCTION:
                                pNearestCity->changeProduction(iYield);
                                break;
                            }
                            szBuffer = gDLL->getText("TXT_KEY_MISC_YIELD_FROM_UNIT", GC.getUnitInfo(pDefender->getUnitType()).getTextKeyWide(), iYield, GC.getYieldInfo((YieldTypes)iI).getChar(), pNearestCity->getNameKey());
                            gDLL->getInterfaceIFace()->addMessage(pNearestCity->getOwnerINLINE(), false, GC.getEVENT_MESSAGE_TIME(), szBuffer,  ARTFILEMGR.getInterfaceArtInfo("WORLDBUILDER_CITY_EDIT")->getPath(), MESSAGE_TYPE_INFO, NULL, (ColorTypes)GC.getInfoTypeForString("COLOR_WHITE"), pDefender->getX_INLINE(), pDefender->getY_INLINE(), true, true);
                        }
                    }
[B]                }[/B]
            }
            /*** FOODFROMANIMALS END ***/

The same should then be done further down in the CvUnit::updateCombat() function, but you can figure that out. It's basically exactly the same thing.
 
Yep. That's what I've done for my future pillage mod that works similar to this. I didn't think it would be a big issue for this since you'd probably found your first city before you killed any animals, but better to be safe than sorry. Good catch.
 
Usually it does work that way, but in my Mod it takes a while before you found a city, hence why it came up. ^_^ No biggie though, its fixed now :)
 
New Version!

Additions & Changes:
Updated to BtS 3.13
Added Commerces from kills.
Now allows yields/commerces from shot down Air Units.

Now you can feed your R&D people secrets towards building your own versions of the enemy's latest death machines when you manage to kill one of the beasts in the field! Reverse engineer your way to victory!

Gain intelligence on your enemies by interrogating their captured soldiers.

Sell off parts of your enemy's wrecked vehicles for parts.
 
Hey Dom, please check your private messages. :)
 
So, anyone got an old copy of this laying around, or know of a Mod which incorporated it? Very interesting idea, and I would rather not have to build it up on my own completely, not quite comfortable with adding Child Values in XML yet.
 
Quite a useful modcomp, I hadn't realized that the functionality extended beyond animals. I guess I should have checked out this thread earlier. :p

I think the addition of a tech-based change to kill yields and commerces would make this truly rock. So for example, after researching Military Tradition you might gain +1 culture from all kills, or Military Science might result in kills worth +1 science and/or espionage.

Personally, I'd like to use this modcomp in a scenario I'm working on so I could award extra culture from kills to represent ritualized warfare and the sacrifice of captured enemies, but I'd really like such bonuses to be awarded to to players after they research certain techs, rather than across the board from the get-go or as exclusive to civs with certain traits. If it wouldn't be too difficult and you're willing, I'd appreciate it if you'd add some kind of function along those lines. I think it could prove useful to more modders than just me.

Thanks. :D
 
Not a bad idea to use it based on techs.. wouldn't be too difficult to add that functionality. Also wouldn't be too difficult to add it based on civics or even events. The values are already stored in the CvPlayer class, so you'd just have to add new XML tags (and the SDK code to read them obviously) to make this work.
 
The values are already stored in the CvPlayer class, so you'd just have to add new XML tags (and the SDK code to read them obviously) to make this work.

I hope you're speaking in the general 'you' and not the specific, because I don't know the first thing about manipulating the SDK, and unfortunately I don't have the time or probably the skill to learn how. If I tried to do it myself, I imagine I'd end up with enough compounded bugs, errors, and frustration to seriously break something, possibly the game or my computer, possibly a blood vessel in my brain. :crazyeye:

EDIT: In the meantime I guess I'll dl the existing modcomp (when it's re-uploaded, I guess) and use the current functions, but I'll keep an eye open for a version with expanded functionality, if do decide to make one.
 
Actually once it is re-uploaded and I play with it you can SORT OF do that with the changes I will be making. I want these fields in PromotionInfos instead of UnitInfos for my uses :) Should be pretty easy to move it from the one area to the other, and once loaded up for Promotions you can just have the Tech provide a Free Promotion to all units to accomplish your goal.

EDIT: By the way DPII, I love your Dynamic UU's Modcomp :) Already imported that one for devious future uses :) Just have to figure out how to make it assign UUs properly for Unitclasses with a default Unit of NONE...
 
So does it come with roaming bison, caribou, and wildebeest units that pillage farms, but don't attack other units? Or perhaps Mammoths and Musk Oxen?
 
There are no new units. This is largely due to the lack of graphics available... but I also was not intending this as a stand-alone feature. It's for people to make changes to their own mods.
 
Actually once it is re-uploaded and I play with it you can SORT OF do that with the changes I will be making. I want these fields in PromotionInfos instead of UnitInfos for my uses :) Should be pretty easy to move it from the one area to the other, and once loaded up for Promotions you can just have the Tech provide a Free Promotion to all units to accomplish your goal.

Promotions, eh? Sounds intriguing, and opens up the possibilities quite a bit, since by vanilla the game can assign promotions to units in a variety of ways (free promotions from buildings, traits, etc.)

Is there really existing XML that can have a tech provide a free promotion to all units? I'd never had the occasion to do that before, but if it's possible it could prove quite useful along with the changes you've described above.
 
There isn't a direct way to implement the promotion via Tech which I know of, but you could make an event which requires that Tech and has a -1 Weight which provides the promotion to all units.

DP, do you still have this available to re-upload, or should I just try doing it from scratch?
 
Back
Top Bottom