/Volumes/Plantain/MyDocuments/Projects/MacTrek/MacTrek/Data/PlayerStats.m

00001 //
00002 //  PlayerStats.m
00003 //  MacTrek
00004 //
00005 //  Created by Aqua on 23/04/2006.
00006 //  Copyright 2006 __MyCompanyName__. All rights reserved.
00007 //
00008 
00009 #import "PlayerStats.h"
00010 
00011 
00012 @implementation PlayerStats
00013 
00014 - (id) init {
00015     self = [super init];
00016     if (self != nil) {
00017         // float hours, float ratings, float defense, String name
00018         ranks = [NSArray arrayWithObjects:
00019             [[Rank alloc] initWithHours: 0 ratings:0 defense:0.0 name:@"Ensign"],
00020             [[Rank alloc] initWithHours: 0 ratings:0 defense:0.0 name:@"Ensign"],
00021             [[Rank alloc] initWithHours: 2 ratings:1 defense:0.0 name:@"Lieutenant"],
00022             [[Rank alloc] initWithHours: 4 ratings:2 defense:0.8 name:@"Lt. Cmdr."],
00023             [[Rank alloc] initWithHours: 8 ratings:3 defense:0.8 name:@"Commander"],
00024             [[Rank alloc] initWithHours:15 ratings:4 defense:0.8 name:@"Captain"],
00025             [[Rank alloc] initWithHours:20 ratings:5 defense:0.8 name:@"Flt. Capt."],
00026             [[Rank alloc] initWithHours:25 ratings:6 defense:0.8 name:@"Commodore"],
00027             [[Rank alloc] initWithHours:30 ratings:7 defense:0.8 name:@"Rear Adm."],
00028             [[Rank alloc] initWithHours:40 ratings:8 defense:0.8 name:@"Admiral"],
00029             nil];
00030         [ranks retain];
00031         
00032         // the rest
00033         maxkills = 0;                               // max kills ever
00034         kills = 0;                                      // how many kills
00035         losses = 0;                                             // times killed
00036         armsbomb = 0;                                   // armies bombed
00037         planets = 0;                                    // planets conquered
00038         tkills = 0;                                             // Kills in tournament play
00039         tlosses = 0;                                    // Losses in tournament play
00040         tarmsbomb = 0;                                  // Tournament armies bombed
00041         tplanets = 0;                                   // Tournament planets conquered
00042         tticks = 0;                                             // Tournament ticks
00043         sbkills = 0;                                    // Kills as starbase
00044         sblosses = 0;                                   // Losses as starbase
00045         sbticks = 0;                                    // Time as starbase
00046         sbmaxkills = 0;                 // Max kills as starbase
00047         st_lastlogin = 0;                               // Last time this player was played
00048         flags = 0;                                              // Misc option flags
00049         rank = [self setRankWithId:0];  // Ranking of the player
00050     }
00051     return self;
00052 }
00053 
00054 -(Rank *) rankWithId:(int)rankId {
00055     return [ranks objectAtIndex:rankId];
00056 }
00057 
00058 -(Rank *) setRankWithId:(int)rankId {
00059     rank = [ranks objectAtIndex:rankId];
00060     return rank;
00061 }
00062 
00063 -(Rank*)rank {
00064     return rank;
00065 }
00066 
00067 -(void) setFlags:(int)newFlags {
00068     flags = newFlags;
00069 }
00070 
00071 -(void) setStarbaseTicks:(int) starbaseTicks {
00072     sbticks = starbaseTicks;   
00073 }
00074 
00075 -(void) setMaxKills:(double)newMaxKills {
00076     maxkills = newMaxKills;
00077 }
00078 
00079 -(void) updateTournamentKills: (int) newTKills
00080              tournamentLosses: (int) newTLosses
00081                         kills: (int) newKills
00082                        losses: (int) newLosses
00083               tournamentTicks: (int) newTTicks
00084             tournamentPlanets: (int) newTPlanets
00085        tournamentArmiesBombed: (int) newTArmiesBombed
00086                 starbaseKills: (int) newSBKills
00087                starbaseLosses: (int) newSBLosses
00088                  armiesBombed: (int) newArmiesBombed
00089                       planets: (int) newPlanets
00090              starbaseMaxKills: (double)newSBMaxKills {
00091     
00092     tkills      = newTKills;
00093     tlosses     = newTLosses;
00094     kills       = newKills;
00095     losses      = newLosses;
00096     tticks      = newTTicks;
00097     tplanets    = newTPlanets;
00098     tarmsbomb   = newTArmiesBombed;
00099     sbkills     = newSBKills;
00100     sblosses    = newSBLosses;
00101     armsbomb    = newArmiesBombed;
00102     planets     = newPlanets;
00103     sbmaxkills  = newSBMaxKills;
00104 }
00105 
00106 - (int)kills {
00107     return kills;
00108 }
00109 
00110 - (int)losses {
00111     return losses;
00112 }
00113 - (int)maxKills {
00114     return maxkills;
00115 }
00116 - (int)tournamentKills {
00117     return tkills;
00118 }
00119 
00120 - (int)tournamentLosses {
00121     return tlosses;
00122 }
00123 
00124 - (int)starbaseKills {
00125     return sbkills;
00126 }
00127 
00128 - (int)starbaseLosses {
00129     return sblosses;
00130 }
00131 
00132 - (int)starbaseMaxKills {
00133     return sbmaxkills;
00134 }
00135 
00136 -(float) bombingRating:(Status *) sts {
00137     if(tticks <= 0 || [sts armiesBombed] <= 0) {
00138         return 0.0;
00139     }
00140     return (float)(((double)tarmsbomb * (double)[sts timeProductive]) / ((double)tticks * (double)[sts armiesBombed]));
00141 }
00142 
00143 -(float) planetRating:(Status *) sts {
00144     if(tticks <= 0 || [sts planets] <= 0) {
00145         return 0.0;
00146     }
00147     return (float)(((double)tplanets * (double)[sts timeProductive]) / ((double)tticks * (double)[sts planets]));
00148 }
00149 
00150 -(float) offenceRating:(Status *) sts{
00151     if(tticks <= 0 || [sts kills] <= 0) {
00152         return 0.0;
00153     }
00154     return (float)(((double)tkills * (double)[sts timeProductive]) / ((double)tticks * (double)[sts kills]));
00155 }
00156 
00157 -(float) defenceRating:(Status *) sts{
00158     if([sts timeProductive] <= 0) {
00159         return 0.0;
00160     }
00161     double top = (double)tticks * (double)[sts losses];
00162     if(top <= 0) {
00163         return (float)(top / (double)[sts timeProductive]);
00164     }
00165     if(tlosses <= 0) {
00166         return 1;
00167     }           
00168     return (float)(top / ((double)tlosses * (double)[sts timeProductive]));
00169 }
00170 
00171 -(float) starbaseKillsPerHour{
00172     return (sbticks == 0) ? 0.0 : (float)sbkills * 36000.0 / (float)sbticks;
00173     }
00174 
00175 -(float) starbaseDefensePerHour{
00176     return (sbticks == 0) ? 0.0 : (float)sblosses * 36000.0 / (float)sbticks;
00177 }
00178 
00179 
00180 
00181 @end

Generated on Fri Jul 28 19:15:16 2006 for MacTrek by  doxygen 1.4.7