Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Computer Forums > Software Programming
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

Software Programming Software programming talk, ask questions about computer software programming or help others

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 06-12-2007, 9:38 PM   #1
baylor
 
baylor's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default How do i change an NPC temporarily?

This is kind of a specific question but it has general implications,
so bear with me

Oh yeah, it's an object oriented programming question. Not syntax,
just design

Basic form of the question - how do you temporarily change an
attribute of an object?

The example i'm working on - a hypnotize spell in a team based game

Hypnotize takes someone one another team and makes them part of your
team for 30 seconds or two minutes or whatever

Both teams have NPC AIs. Each NPC has a pickTarget method to decide
who to attack. Assumedly, each NPC only considers attacking a foe. So
when Troll4 joins my team, my knights should not attack Troll4 and
maybe (or maybe not) Trolls 1-3 should attack Troll4

So how do i implement this?

One option is to have a class like:

Troll {
protected TeamEnum team;
public TeamEnum getTeam() { return team; }
public void setTeam(TeamEnum team) { return team; }
}

So the hypnotize spell could just call Target.setTeam(me.getTeam()).
There are two problems

First, the effect is temporary. How do we handle that? After X time
period it needs to expire and troll4 goes back to his standard team

Second, the members of his ex-team will want to treat him differently.
He shouldn't be hurt if it can be avoided since he'll eventually be
rejoining the team. So they need to know that he's only a temporary
enemy (and it should be used in chooseTarget())

The next idea i came up with was to do like mutators in Unreal. i
really like mutators. For those who don't know what they are, mutators
are ways to change code in a game. In OOP terminology, it would be
like overriding a method, but in implementation it's like the (well,
my) old days when we had to hook interrupts. The original guy gets the
call and sends an answer and then others get a chance to modify the
answer and do other stuff before the caller gets the value back

Of course, i don't know how to do that. i was thinking something like
a decorator (probably the wrong GoF pattern but i can't remember the
right one) but not sure how to implement it. Maybe force all calls to
go through the game layer (where hooks can be registered) rather than
allowing direct object calls?

What do you guys think?

-baylor
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 06-12-2007, 9:38 PM   #2
Eternal Vigilance
 
Eternal Vigilance's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default How do i change an NPC temporarily?



baylor wrote:

> This is kind of a specific question but it has general implications,
> so bear with me
>
> Oh yeah, it's an object oriented programming question. Not syntax,
> just design
>
> Basic form of the question - how do you temporarily change an
> attribute of an object?


Use node objects ' Effect' (node of a link list of n effects
attached to an object (ie-NPC)

effects can have a time limit attribute that is checked every turn to see
if it expires.
effects havean effect type that defines what the effect is
(in this case its a temporary change to a NPCs alliegence
or targeting)

effects are applied to all objects in the spell area (on casting if its an
impulse type spell)
and after an object fails the spells save, the effect is applied to
that object
(apply -- saving old values and setting the changes for the
duration)
any other spells/events that effect this spells effect you have to
have the game mechanics decide
what the outcome is (ie- releasing the last hypnotize or other
effects). A large amount
of special logic will probably be needed to resolve simultaneous
spell/event effects....


effects would have an apply call and a release call
( need to be careful not to restore values that might be changed during
duration of effect - prefer
modifying attributes +/- value and restoring the delta value..... when
effect is released)



struct EFFECT
{
EFFECT *next; // chain of effects attached to object ( or
effect freechain)
INT effecttype; // index into big giant switch() statement
of effects (or callback table ....)
LONG releasetime; // if past this time, effect calls its
release routine (if -1 then permanent effect - no time limit)
INT strength;
INT param1; // generic params for effect... may need more
or less values or a union
INT param2;
INT (__cdecl *Handler)(OBJECT *objx); // optional special
handler if not NULL call for per turn event functionality
INT oldattribute[4]; // index of attribute on 'target' --
used for restoration
DWORD oldvalue[4]; // storage of original values to undo (or
modification (daltas) to value )
};

>
>
> The example i'm working on - a hypnotize spell in a team based game
>
> Hypnotize takes someone one another team and makes them part of your
> team for 30 seconds or two minutes or whatever


>
>
> Both teams have NPC AIs. Each NPC has a pickTarget method to decide
> who to attack. Assumedly, each NPC only considers attacking a foe. So
> when Troll4 joins my team, my knights should not attack Troll4 and
> maybe (or maybe not) Trolls 1-3 should attack Troll4
>
> So how do i implement this?
>
> One option is to have a class like:
>
> Troll {
> protected TeamEnum team;
> public TeamEnum getTeam() { return team; }
> public void setTeam(TeamEnum team) { return team; }
> }
>
> So the hypnotize spell could just call Target.setTeam(me.getTeam()).
> There are two problems
>
> First, the effect is temporary. How do we handle that? After X time
> period it needs to expire and troll4 goes back to his standard team
>


an effect would modify those NPC by effecting their 'team' attribute to
be the spell casters (and save their original team value) and would
restore it
when the spells duration was up.




>
> Second, the members of his ex-team will want to treat him differently.
> He shouldn't be hurt if it can be avoided since he'll eventually be
> rejoining the team. So they need to know that he's only a temporary
> enemy (and it should be used in chooseTarget())
>


Need a modification of the targeting selector to recognize 'effected'
targets (recognition of something more than an arbitrary 'team'
attribute).
Team would be a short term alliegence (used for temporary battle
organization etc...) but a longer term association (Brotherhood of
Trolls??)
would be an underlying 'permanent' alliegence.





>
> The next idea i came up with was to do like mutators in Unreal. i
> really like mutators. For those who don't know what they are, mutators
> are ways to change code in a game. In OOP terminology, it would be
> like overriding a method, but in implementation it's like the (well,
> my) old days when we had to hook interrupts. The original guy gets the
> call and sends an answer and then others get a chance to modify the
> answer and do other stuff before the caller gets the value back
>


As long as you dont have a static list of 45 hooks to check -- and these
RPG
can get pretty fancy with all the modifiers and different attributes.
Thats why I would use (and am using in my project) link list of
effects...



>
> Of course, i don't know how to do that. i was thinking something like
> a decorator (probably the wrong GoF pattern but i can't remember the
> right one) but not sure how to implement it. Maybe force all calls to
> go through the game layer (where hooks can be registered) rather than
> allowing direct object calls?
>
> What do you guys think?
>
> -baylor


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags: , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Terraserver URL change Dave Patton GPS 1 06-12-2007 5:11 PM
change color XO News Graphics in general 1 06-11-2007 11:04 PM
change color K Graphics in general 0 06-11-2007 10:38 PM
Time for a change? PTT Building An Internet Business 1 05-29-2007 3:03 AM
change language ?? Mogens Nielsen Windows 1 05-28-2007 11:29 PM


Featured Websites




All times are GMT +1. The time now is 2:14 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98