[PATCH] Some resource meters not working

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

[PATCH] Some resource meters not working

#1 Post by Vezzra »

Problem: In recent builds some resource meters didn't work as expected anymore. A look at the log files revealed that the expressions "Target.Population" and "Target.Owner" in the content scripts threw errors and couldn't be evaluated correctly (in case of "Target.Population" that meant it always yielded 0).

Turned out that ValueRef::Variable objects with m_property_name starting with "Target." had a m_ref_type of NON_OBJECT_REFERENCE. If I understand the code correctly, this should be EFFECT_TARGET_REFERENCE instead.

Looking further into the matter, I finally came across this piece of code:

Code: Select all

ValueRef::Variable<T>::Variable(const std::vector<adobe::name_t>& property_name) :
    m_ref_type(),
    m_property_name(property_name.begin(), property_name.end())
{
    assert(!property_name.empty());
    adobe::name_t ref_type_name = property_name.front();
    if (ref_type_name == CurrentTurn_name) {
        m_ref_type = NON_OBJECT_REFERENCE;
    } else if (ref_type_name == Source_name) {
        m_ref_type = SOURCE_REFERENCE;
    } else if (ref_type_name == Value_name || ref_type_name == Value_name) {
        m_ref_type = EFFECT_TARGET_REFERENCE;
    } else if (ref_type_name == LocalCandidate_name) {
        m_ref_type = CONDITION_LOCAL_CANDIDATE_REFERENCE;
    } else if (ref_type_name == RootCandidate_name) {
        m_ref_type = CONDITION_ROOT_CANDIDATE_REFERENCE;
    }
}
Which seems to be the ctor of the ValueRef::Variable class. Especially this line of code caught my attention:

Code: Select all

    } else if (ref_type_name == Value_name || ref_type_name == Value_name) {
        m_ref_type = EFFECT_TARGET_REFERENCE;
With my limited C++ skills and practically complete lack of knowledge of the FO code, I can't be 100% sure, but I *think* that that should be:

Code: Select all

    } else if (ref_type_name == Value_name || ref_type_name == Target_name) {
        m_ref_type = EFFECT_TARGET_REFERENCE;
Otherwise m_ref_type won't get properly set to EFFECT_TARGET_REFERENCE when ref_type_name is "Target", and that leads to "Target." expressions not being evaluated as they should, thus breaking all resource meters that depend on them. And probably break other things too, but the issue with the resource meters was immediately obvious.

After I applied that fix and rebuild FO, resource meters were working fine again, so it looks like I got that right. I hope I could help a bit with this fix :wink:

Patch is attached.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]


neuro
Space Squid
Posts: 74
Joined: Sun Mar 07, 2010 10:17 pm

Re: [PATCH] Some resource meters not working

#2 Post by neuro »

Awesome explanation and fix. Hope it gets incorporated.

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: [PATCH] Some resource meters not working

#3 Post by Vezzra »

neuro wrote:Awesome explanation and fix. Hope it gets incorporated.
Thanks! :D

Fix has already been committed to SVN (rev 4509).

Post Reply