Help with setflag

Want to discuss changes to the UOX3 source code? Got a code-snippet you'd like to post? Anything related to coding/programming goes here!
Post Reply
Saint
UOX3 Apprentice
Posts: 162
Joined: Sun Feb 11, 2007 6:05 pm
Has thanked: 0
Been thanked: 0

Help with setflag

Post by Saint »

I've created two new functions SetFlagGoodGuy and SetFlagBadGuy in the same area as SetFlagBlue, etc..

now, these other functions both return a number, but I don't know how that relates to anything. I've created custom flags and I want to attach those to these new functions so that they may be displayed. I've made the necesarry changes in UpdateFlag().

Any other places I'll have to make changes? Also do I have to worry about the behavior for these flags? They are designed to just operate as if the flag owners were regular Blue people.
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

Not really understanding what you're trying to ask here. I'm guessing you made 2 new flag states (0x10 and 0x20), one for good, one for bad. Have you created two new IsSomething() funcs as well? eg IsInnocent, IsNeutral, etc, like just above SetFlagBlue. Because you'll need them to access later.

But yes, you're adding flags, so you're going to have to add logic in a number of spots. Your flags won't piggy back on any others, so anywhere that deals with flag logic (do a find in files for something like "IsInnocent"), you'll have to add your own custom code, I'm sure. A quick glance through sees things like:

* WillResultInCriminal
* HandleFieldEffects
* AttackTarget
* HandleHealerAI
* callGuards
* criminal
* FlagColour
* PlayerAttack
* spell checks galore
* almost anything in ai.cpp

and you'd want to look at adding properties to the JS engine to expose it. Look for all references to CCP_MURDERER to start with.

But why do you think you need more flags? Is there perhaps another way you can achieve what you want?
Saint
UOX3 Apprentice
Posts: 162
Joined: Sun Feb 11, 2007 6:05 pm
Has thanked: 0
Been thanked: 0

Post by Saint »

Why can't the flag states piggy back? They already have the same exact functionality as an existing state.

How about if I just modified the "SetFlagBlue" flag to take an extra parameter (karma) so it can further specify which color to flag the name?

It's not that I need more flags, it's just that I want to make use of blue and red names. See I have changed the code so everyone is pretty much either green, gray, orange or beige. Friends, Neutrals, Criminal/Enemy, Animals.

Now I just want to make it so people with higher karma have blue names and people with lower karma have red names.
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

Because not all states are potentially combinable. You can't be innocent and a murderer, or innocent and a criminal. Though perhaps there should be room for being both criminal and a murderer (though I think murderer tends to take precedence).

Effective display colour in that regard is done via CChar::FlagColour. You'll see orange/green based on guild/racial enemies, ofr instance, as well as blue/grey/red based on innocence, criminality and murder, for instance. If you manipulate that function, then it should display blue/red names differently, though obviously doesn't alter the server rulesets with regards to attacking and so forth. But it'll alter the name and highlight display, I should think.
Saint
UOX3 Apprentice
Posts: 162
Joined: Sun Feb 11, 2007 6:05 pm
Has thanked: 0
Been thanked: 0

Post by Saint »

Maarc wrote:Because not all states are potentially combinable. You can't be innocent and a murderer, or innocent and a criminal. Though perhaps there should be room for being both criminal and a murderer (though I think murderer tends to take precedence).
I don't see how this is relevant though. No states are being combined. The system is entirely cosmetic. People with Blue names, Gray Names, and Red Names still highlight blue.

I'm having trouble figuring out what is the exact function which is the final step for applying the color to the name from where all flagging must pass through, since that's where I want to run the check. From what you were saying it sounds like the actually flagging of color is done in a bunch of different places and has no one universal method location. But if FlagColor is the mother of all flagging, then I suppose I would have to make it look something like this:

Code: Select all

FlagColors CChar::FlagColour( CChar *toCompare )
{               
        FlagColors retVal = FC_INNOCENT;
           
     
        GUILDRELATION gComp        = GR_UNKNOWN;
        SI08 rComp                   = 0;
        SIl6 nCurKarma               = toCompare->GetKarma();            
   
        if( ValidateObject( toCompare ) )
        {       
                if( !IsIncognito() )
                {
                        gComp   = GuildSys->Compare( this, toCompare );
                        rComp   = Races->Compare( this, toCompare );
                }
        }       
                
        if( IsInvulnerable() )
                retVal = FC_INVULNERABLE;
        else if( IsMurderer() )
                retVal = FC_MURDERER;
        else if( IsCriminal() )
                retVal = FC_CRIMINAL;
        else if( IsNeutral() )
                retVal = FC_NEUTRAL;
        else if( rComp != 0 || gComp != GR_UNKNOWN ) 
        {       
                if( gComp == GR_ALLY || gComp == GR_SAME || rComp > 0 )
                        retVal = FC_FRIEND;
                else if( gComp == GR_WAR || rComp < 0 )
                        retVal = FC_ENEMY;
        }       
              //else if( gComp == GR_WAR || rComp <0> 10000)


       if(retVal == FC_INNOCENT){
         if(nCurKarma > 10000)
            retVal = FC_GOOD;
        else if (nCurKarma < -10000)
            retVal = FC_BAD;
       else
            retVal = FC_INNOCENT;
}
        return retVal;
}                
*Forums are a bit buggy with posting code for some reason
Saint
UOX3 Apprentice
Posts: 162
Joined: Sun Feb 11, 2007 6:05 pm
Has thanked: 0
Been thanked: 0

Post by Saint »

By the way where is FC_INNOCENT itself defined?
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

If all you want to do, and nothing else, is change the text of the single click on a person, effectively, that's simple enough. CPISingleClick::Handle() calls CSocket::ShowCharName()

Code: Select all

	toAdd.Colour( GetFlagColour( mChar, i ) );
That's it. Either change CSocket::GetFlagColour() (which calls CChar::FlagColour()), or hack your values in there.

The point is, though, those states are relevant. Flag colour only returns colour information based on server flag status: eg are they a criminal?

The purpose of GetFlagColour/FlagColour is to return the text colour for their name, as well as the colour they will highlight, because they're identical in nature, really.

But if you don't want them to highlight differently and just have different coloured names, that's all you have to do. Line 1558 of cSocket.cpp.

As far as FC_INNOCENT goes, it's an enum of our own in enums.h:

Code: Select all

enum FlagColors
{
	FC_INNOCENT = 1,
	FC_FRIEND,
	FC_NEUTRAL,
	FC_CRIMINAL,
	FC_ENEMY,
	FC_MURDERER,
	FC_INVULNERABLE
};

Saint
UOX3 Apprentice
Posts: 162
Joined: Sun Feb 11, 2007 6:05 pm
Has thanked: 0
Been thanked: 0

Post by Saint »

Code: Select all

if(retVal == FC_INNOCENT){ 
         if(nCurKarma >= 10000) 
            retVal = FC_GOOD; 
        else if (nCurKarma <= -10000) 
            retVal = FC_BAD; 
}
Something is wrong with this conditional, the Karma isn't evaluating correctly.. I've already tested with other simple values and the flagging works. nCurKarma is type SI16; is comparing it to 10000 a valid comparison?
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

SI16 can be -32768 to 32767, so those numbers are well within range.
Saint
UOX3 Apprentice
Posts: 162
Joined: Sun Feb 11, 2007 6:05 pm
Has thanked: 0
Been thanked: 0

Post by Saint »

giwo wrote:SI16 can be -32768 to 32767, so those numbers are well within range.
I figured.

What file is the GetKarma() function in? Maybe there's an issue or something.

nCurKarma = toCompare->GetKarma();


Also... Karma only goes as high as 32,767?
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

An IDE is your friend :)

Code: Select all

SI16 CBaseObject::GetKarma( void ) const
{
	return karma;
}
cBaseObject.cpp, line 2029

It's a simple retrieval, nothing more. The issue is more likely either Karma(), which is calculation upon killing. But even more so, I suspect it's just the numbers you chose. We cap at -10000 and 10000, because that's the numbers that the UO client uses. -10000 is the lowest it can be for evil people, 10000 is the highest. So the classic old "Lord" titles are there. But that's best of the best, and worst of the worst :) 0 is the neutral balance point, with roughly 1000 being the guard area, I think, before you wander into dangerous (plus or minus).

I just don't think, unless they're at max/min karma, you'll find players with karma that high/low.
Saint
UOX3 Apprentice
Posts: 162
Joined: Sun Feb 11, 2007 6:05 pm
Has thanked: 0
Been thanked: 0

Post by Saint »

Ah, interesting.

Is there a list of all the titles and the karma requirements?

Also, what about fame? How exactly does it work?


Actually can you tell me where the script with the function that handles title changes is?


I need an IDE, all I got is VIM.
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

The fame titles are in titles definition files, under [FAME]. What fame and karma level maps to what title is controlled through getFameTitle() in cPlayerAction.cpp. The Fame() and Karma() functions deal with what you gain/lose when you kill someone.
Saint
UOX3 Apprentice
Posts: 162
Joined: Sun Feb 11, 2007 6:05 pm
Has thanked: 0
Been thanked: 0

Post by Saint »

Could it be possible that cChar.cpp is not finding the GetKarma Function for some reason?

I've tested the conditional using a random number generator. Half the time, people will come up with blue names, and the other half they come up with red names. So there's definately no problem with the actual flags.


I've included cBaseObject.h into cChar.cpp
Saint
UOX3 Apprentice
Posts: 162
Joined: Sun Feb 11, 2007 6:05 pm
Has thanked: 0
Been thanked: 0

Post by Saint »

Oh god, I've discovered the problem. toCompare doesn't refer to the object that is recieving the flag, it is referring to the person who is viewing the flag.

That means this script will make all innocents have blue names if YOUR karma is over 1000, or red names if your karma is under -1000.

Obviously, I need a way to reference the actual NPC, I guess this isn't the method I'm looking for
Saint
UOX3 Apprentice
Posts: 162
Joined: Sun Feb 11, 2007 6:05 pm
Has thanked: 0
Been thanked: 0

Post by Saint »

finally got it to work

Image

hooray,

now I just hope there are no unforseen consequences
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

Ah, yup, that'd do it alright :) You have to refer to the right objects.

As far as repurcussions, all you're doing is recolouring names. The fact that they all show as blue otherwise means the rep flagging's still fine. It just means you can't trust the colour of the name to determine if you can attack them :)
Post Reply