![]() |
|
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. |
| |||||||
| Software Programming Software programming talk, ask questions about computer software programming or help others |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| 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 | |||
| | #2 | ||
| 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 | |||
| Featured Websites | ||||
|
![]() |
| Tags: change, npc, temporarily |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
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 | ||||
|