|
From: Geisschaes <gei...@us...> - 2005-05-29 13:17:44
|
Update of /cvsroot/macattrick/macattrick In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11784 Modified Files: Player.h Player.m World.h World.m Log Message: PlayerState object introduced. Changeable data is now stored in it. Player object uses currentState to access the data Index: World.h =================================================================== RCS file: /cvsroot/macattrick/macattrick/World.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** World.h 14 Mar 2005 19:30:52 -0000 1.2 --- World.h 29 May 2005 13:17:03 -0000 1.3 *************** *** 39,41 **** --- 39,43 ---- } - (Country*) countryWithID: (int) countryID; + + + (World*) uniqueInstance; @end Index: World.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/World.m,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** World.m 14 Mar 2005 19:30:52 -0000 1.2 --- World.m 29 May 2005 13:17:03 -0000 1.3 *************** *** 35,39 **** @implementation World ! + uniqueInstance { if(!sharedInstance) { sharedInstance = [[self alloc] init]; --- 35,39 ---- @implementation World ! + (World*) uniqueInstance { if(!sharedInstance) { sharedInstance = [[self alloc] init]; Index: Player.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/Player.m,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Player.m 7 Feb 2005 21:15:39 -0000 1.21 --- Player.m 29 May 2005 13:17:03 -0000 1.22 *************** *** 64,95 **** @implementation Player // NSCopying Protocal ! -(Player*) copyWithZone: (NSZone*) zone { Player *copy = [[Player alloc] init]; ! [copy setAge:age]; ! [copy setAggressiveness:aggressiveness]; ! [copy setCards:cards]; ! [copy setAgreeability:agreeability]; ! [copy setCountryID:countryID]; ! [copy setDefenderSkill:defenderSkill]; ! [copy setExperience:experience]; ! [copy setHonesty:honesty]; ! [copy setInjuryLevel:injuryLevel]; ! [copy setKeeperSkill:keeperSkill]; ! [copy setLeadership:leadership]; ! [copy setPassingSkill:passingSkill]; ! [copy setSetPiecesSkill:setPiecesSkill]; ! [copy setPlayerForm:playerForm]; ! [copy setPlayerID:playerID]; ! [copy setPlayerName:[playerName copy]]; ! [copy setPlaymakerSkill:playmakerSkill]; ! [copy setSalary:salary]; ! [copy setScorerSkill:scorerSkill]; ! [copy setSpecialty:specialty]; ! [copy setStaminaSkill:staminaSkill]; ! [copy setTsi:tsi]; ! [copy setWingerSkill:wingerSkill]; return copy; } --- 64,103 ---- @implementation Player + -(id) init { + self = [super init]; + if (self) { + currentState = [[PlayerState alloc] init]; + } + return self; + } + // NSCopying Protocal ! -(id) copyWithZone: (NSZone*) zone { Player *copy = [[Player alloc] init]; ! [copy setAge:[self age]]; ! [copy setAggressiveness:[self aggressiveness]]; ! [copy setCards:[self cards]]; ! [copy setAgreeability:[self agreeability]]; ! [copy setCountryID:[self countryID]]; ! [copy setDefenderSkill:[self defenderSkill]]; ! [copy setExperience:[self experience]]; ! [copy setHonesty:[self honesty]]; ! [copy setInjuryLevel:[self injuryLevel]]; ! [copy setKeeperSkill:[self keeperSkill]]; ! [copy setLeadership:[self leadership]]; ! [copy setPassingSkill:[self passingSkill]]; ! [copy setSetPiecesSkill:[self setPiecesSkill]]; ! [copy setPlayerForm:[self playerForm]]; ! [copy setPlayerID:[self playerID]]; ! [copy setPlayerName:[[self playerName] copy]]; ! [copy setPlaymakerSkill:[self playmakerSkill]]; ! [copy setSalary:[self salary]]; ! [copy setScorerSkill:[self scorerSkill]]; ! [copy setSpecialty:[self specialty]]; ! [copy setStaminaSkill:[self staminaSkill]]; ! [copy setTsi:[self tsi]]; ! [copy setWingerSkill:[self wingerSkill]]; return copy; } *************** *** 120,136 **** } ! - (int) tsi { return tsi; } - (void) setTsi: (int) newTsi { ! tsi = newTsi; } ! - (int) salary {return salary;} - (void) setSalary: (int) newSalary { ! salary = newSalary; } - (NSString *)playerName { return playerName; } - - (void)setPlayerName:(NSString *)newPlayerName { [newPlayerName retain]; --- 128,143 ---- } ! - (int) tsi { return [currentState tsi]; } - (void) setTsi: (int) newTsi { ! [currentState setTsi: newTsi]; } ! - (int) salary {return [currentState salary];} - (void) setSalary: (int) newSalary { ! [currentState setSalary: newSalary]; } - (NSString *)playerName { return playerName; } - (void)setPlayerName:(NSString *)newPlayerName { [newPlayerName retain]; *************** *** 139,179 **** } ! - (int)age { ! return age; ! } ! - (void)setAge:(int)newAge { ! if (age != newAge) { ! age = newAge; ! } } ! - (int)injuryLevel { return injuryLevel;} - (void)setInjuryLevel:(int)newInjuryLevel { ! if (injuryLevel != newInjuryLevel) { ! injuryLevel = newInjuryLevel; ! } } ! - (int) cards { return cards;} - (void) setCards: (int) newCards { ! cards = newCards; } - (BOOL) isDisqualified { ! return cards == 3; } - (NSImage*) injuryImage { ! if (injuryLevel == -1) { return [[NSImage alloc] init]; } ! else if (injuryLevel == 0) { return [[NSImage alloc] initByReferencingFile: [NSString stringWithFormat: @"%@/bruised.gif",[[NSBundle mainBundle] resourcePath]]]; } ! else if (injuryLevel <10) { ! return [[NSImage alloc] initByReferencingFile: [NSString stringWithFormat: @"%@/injured%i.gif",[[NSBundle mainBundle] resourcePath],injuryLevel]]; } else { --- 146,180 ---- } ! - (int)age { return [currentState age];} - (void)setAge:(int)newAge { ! [currentState setAge: newAge]; } ! - (int)injuryLevel { return [currentState injuryLevel];} - (void)setInjuryLevel:(int)newInjuryLevel { ! [currentState setInjuryLevel:newInjuryLevel]; } ! - (int) cards { return [currentState cards];} - (void) setCards: (int) newCards { ! [currentState setCards: newCards]; } - (BOOL) isDisqualified { ! return [currentState cards] == 3; } - (NSImage*) injuryImage { ! int level = [currentState injuryLevel]; ! if (level == -1) { return [[NSImage alloc] init]; } ! else if (level == 0) { return [[NSImage alloc] initByReferencingFile: [NSString stringWithFormat: @"%@/bruised.gif",[[NSBundle mainBundle] resourcePath]]]; } ! else if (level <10) { ! return [[NSImage alloc] initByReferencingFile: [NSString stringWithFormat: @"%@/injured%i.gif",[[NSBundle mainBundle] resourcePath],level]]; } else { *************** *** 183,198 **** - (NSImage*) cardsImage { ! if(cards == 0) { return [[NSImage alloc] init]; } ! else if (cards == 1) { return [[NSImage alloc] initByReferencingFile: [NSString stringWithFormat: @"%@/warned_1.gif",[[NSBundle mainBundle] resourcePath]]]; } ! else if (cards == 2) { return [[NSImage alloc] initByReferencingFile: [NSString stringWithFormat: @"%@/warned_2.gif",[[NSBundle mainBundle] resourcePath]]]; } ! else if (cards == 3) { return [[NSImage alloc] initByReferencingFile: [NSString stringWithFormat: @"%@/disqualified.gif",[[NSBundle mainBundle] resourcePath]]]; } } --- 184,201 ---- - (NSImage*) cardsImage { ! int myCards = [currentState cards]; ! if(myCards == 0) { return [[NSImage alloc] init]; } ! else if (myCards == 1) { return [[NSImage alloc] initByReferencingFile: [NSString stringWithFormat: @"%@/warned_1.gif",[[NSBundle mainBundle] resourcePath]]]; } ! else if (myCards == 2) { return [[NSImage alloc] initByReferencingFile: [NSString stringWithFormat: @"%@/warned_2.gif",[[NSBundle mainBundle] resourcePath]]]; } ! else if (myCards == 3) { return [[NSImage alloc] initByReferencingFile: [NSString stringWithFormat: @"%@/disqualified.gif",[[NSBundle mainBundle] resourcePath]]]; } + return nil; } *************** *** 223,232 **** ! - (int)experience {return experience;} - (void)setExperience:(int)newExperience { ! if (experience != newExperience) { ! experience = newExperience; ! } } --- 226,233 ---- ! - (int)experience {return [currentState experience];} - (void)setExperience:(int)newExperience { ! [currentState setExperience: newExperience]; } *************** *** 239,327 **** } ! - (int)playerForm {return playerForm;} - (void)setPlayerForm:(int)newPlayerForm { ! if (playerForm != newPlayerForm) { ! playerForm = newPlayerForm; ! } } ! - (int)staminaSkill {return staminaSkill;} - (void)setStaminaSkill:(int)newStaminaSkill { ! if (staminaSkill != newStaminaSkill) { ! staminaSkill = newStaminaSkill; ! ! } } ! - (int)keeperSkill {return keeperSkill; ! } - (void)setKeeperSkill:(int)newKeeperSkill { ! if (keeperSkill != newKeeperSkill) { ! keeperSkill = newKeeperSkill; ! ! } } ! - (int)playmakerSkill {return playmakerSkill;} - (void)setPlaymakerSkill:(int)newPlaymakerSkill { ! if (playmakerSkill != newPlaymakerSkill) { ! playmakerSkill = newPlaymakerSkill; ! ! } } ! - (int)scorerSkill {return scorerSkill;} - (void)setScorerSkill:(int)newScorerSkill { ! if (scorerSkill != newScorerSkill) { ! scorerSkill = newScorerSkill; ! ! } } ! - (int)passingSkill {return passingSkill;} - (void)setPassingSkill:(int)newPassingSkill { ! if (passingSkill != newPassingSkill) { ! passingSkill = newPassingSkill; ! } } ! - (int)wingerSkill { return wingerSkill;} - (void)setWingerSkill:(int)newWingerSkill { ! if (wingerSkill != newWingerSkill) { ! wingerSkill = newWingerSkill; ! } } ! - (int)defenderSkill {return defenderSkill;} - (void)setDefenderSkill:(int)newDefenderSkill { ! if (defenderSkill != newDefenderSkill) { ! defenderSkill = newDefenderSkill; ! } } ! - (int)setPiecesSkill { return setPiecesSkill;} - (void)setSetPiecesSkill:(int)newSetPiecesSkill { ! if (setPiecesSkill != newSetPiecesSkill) { ! setPiecesSkill = newSetPiecesSkill; ! } } -(double)teamCaptain { ! return (2*[self leadership] + [self experience])/3.0; } // overall skill accessor ! - (void)setStaminaSkill: (int) newStaminaSkill keeperSkill: (int) newKeeperSkill playmakerSkill: (int) newPlaymakerSkill scorerSkill: (int) newScorerSkill passingSkill: (int) newPassingSkill wingerSkill: (int) newWingerSkill --- 240,305 ---- } ! - (int)playerForm {return [currentState playerForm];} - (void)setPlayerForm:(int)newPlayerForm { ! [currentState setPlayerForm: newPlayerForm]; } ! - (int)staminaSkill {return [currentState staminaSkill];} - (void)setStaminaSkill:(int)newStaminaSkill { ! [currentState setStaminaSkill:newStaminaSkill]; } ! - (int)keeperSkill {return [currentState keeperSkill];} - (void)setKeeperSkill:(int)newKeeperSkill { ! [currentState setKeeperSkill:newKeeperSkill]; } ! - (int)playmakerSkill {return [currentState playmakerSkill];} - (void)setPlaymakerSkill:(int)newPlaymakerSkill { ! [currentState setPlaymakerSkill: newPlaymakerSkill]; } ! - (int)scorerSkill {return [currentState scorerSkill];} - (void)setScorerSkill:(int)newScorerSkill { ! [currentState setScorerSkill:newScorerSkill]; } ! - (int)passingSkill {return [currentState passingSkill];} - (void)setPassingSkill:(int)newPassingSkill { ! [currentState setPassingSkill: newPassingSkill]; } ! - (int)wingerSkill { return [currentState wingerSkill];} - (void)setWingerSkill:(int)newWingerSkill { ! [currentState setWingerSkill:newWingerSkill]; } ! - (int)defenderSkill {return [currentState defenderSkill];} - (void)setDefenderSkill:(int)newDefenderSkill { ! [currentState setDefenderSkill: newDefenderSkill]; } ! - (int)setPiecesSkill { return [currentState setPiecesSkill];} - (void)setSetPiecesSkill:(int)newSetPiecesSkill { ! [currentState setSetPiecesSkill: newSetPiecesSkill]; } -(double)teamCaptain { ! return (2*[self leadership] + [currentState experience])/3.0; } // overall skill accessor ! /*- (void)setStaminaSkill: (int) newStaminaSkill keeperSkill: (int) newKeeperSkill playmakerSkill: (int) newPlaymakerSkill scorerSkill: (int) newScorerSkill passingSkill: (int) newPassingSkill wingerSkill: (int) newWingerSkill *************** *** 351,355 **** setPiecesSkill = newSetPiecesSkill; } ! } -(void) setValue:(id)value forUndefinedKey: (id) key { --- 329,333 ---- setPiecesSkill = newSetPiecesSkill; } ! }*/ -(void) setValue:(id)value forUndefinedKey: (id) key { *************** *** 358,369 **** - (double) calculatePositionValue: (Position*) position { ! //(playerForm * 0.075 + 0.4) ! return (((playerForm * [position playerFormRate] * 0.125 + 0.4) * (staminaSkill * [position staminaRate] + keeperSkill * [position keeperRate] ! + playmakerSkill * [position playmakingRate] + scorerSkill * [position scorerRate] ! + passingSkill * [position passingRate] + wingerSkill * [position wingerRate] ! + defenderSkill * [position defenderRate] + setPiecesSkill * [position setPiecesRate])) + log10(experience) * [position experienceRate] * 2); } -(Position*) bestPosition { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; --- 336,351 ---- - (double) calculatePositionValue: (Position*) position { ! return [self calculatePositionValue:position withinState: currentState]; } + - (double) calculatePositionValue: (Position*) position withinState: (PlayerState*) state{ + //(playerForm * 0.075 + 0.4) + return ((([state playerForm] * [position playerFormRate] * 0.125 + 0.4) * ([state staminaSkill] * [position staminaRate] + [state keeperSkill] * [position keeperRate] + + [state playmakerSkill] * [position playmakingRate] + [state scorerSkill] * [position scorerRate] + + [state passingSkill] * [position passingRate] + [state wingerSkill] * [position wingerRate] + + [state defenderSkill] * [position defenderRate] + [state setPiecesSkill] * [position setPiecesRate])) + log10([state experience]) * [position experienceRate] * 2); + } + -(Position*) bestPosition { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; *************** *** 437,440 **** --- 419,423 ---- } - (void)dealloc { + [currentState release]; [playerName release]; [super dealloc]; Index: Player.h =================================================================== RCS file: /cvsroot/macattrick/macattrick/Player.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Player.h 27 Apr 2005 19:36:38 -0000 1.17 --- Player.h 29 May 2005 13:16:55 -0000 1.18 *************** *** 30,49 **** #import <Foundation/Foundation.h> #import "Position.h" @interface Player : NSObject <NSCopying> { int playerID; NSString *playerName; int countryID; ! int tsi; ! int salary; ! int age; ! int injuryLevel; ! int cards; int specialty; int agreeability; int aggressiveness; int honesty; int experience; - int leadership; int playerForm; int staminaSkill; --- 30,52 ---- #import <Foundation/Foundation.h> #import "Position.h" + #import "PlayerState.h" @interface Player : NSObject <NSCopying> { int playerID; NSString *playerName; + PlayerState *currentState; int countryID; ! int leadership; int specialty; int agreeability; int aggressiveness; int honesty; + + /* int tsi; + int salary; + int age; + int injuryLevel; + int cards; int experience; int playerForm; int staminaSkill; *************** *** 54,58 **** int wingerSkill; int defenderSkill; ! int setPiecesSkill; } --- 57,61 ---- int wingerSkill; int defenderSkill; ! int setPiecesSkill;*/ } *************** *** 64,68 **** - (int) playerID; - (NSString *) playerName; ! - (NSString*) countryFlagPath; - (int) countryID; - (NSString*) countryName; --- 67,71 ---- - (int) playerID; - (NSString *) playerName; ! - (NSImage*) countryFlag ; - (int) countryID; - (NSString*) countryName; *************** *** 70,73 **** --- 73,77 ---- - (int) salary; - (int) age; + - (int) leadership; - (int) injuryLevel; *************** *** 89,94 **** 5 Head specialist */ - (int) specialty; - (int) experience; - - (int) leadership; - (int) playerForm; - (int) staminaSkill; --- 93,99 ---- 5 Head specialist */ - (int) specialty; + + - (int) experience; - (int) playerForm; - (int) staminaSkill; *************** *** 102,105 **** --- 107,111 ---- + -(double)teamCaptain; *************** *** 111,114 **** --- 117,121 ---- - (double)calculatePositionValue: (Position*)position; + - (double) calculatePositionValue: (Position*) position withinState: (PlayerState*) state; -(Position*) bestPosition; |