File: Scorekeeper.py

package info (click to toggle)
fofix-dfsg 3.121-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 27,016 kB
  • ctags: 4,131
  • sloc: python: 44,002; makefile: 99; perl: 42; sh: 39
file content (320 lines) | stat: -rwxr-xr-x 12,488 bytes parent folder | download | duplicates (4)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#####################################################################
# -*- coding: iso-8859-1 -*-                                        #
#                                                                   #
# Frets on Fire                                                     #
# Copyright (C) 2006 Sami Ky�stil�                                  #
#               2008 Alarian                                        #
#               2008 myfingershurt                                  #
#               2008 Glorandwarf                                    #
#               2008 Spikehead777                                   #
#               2008 QQStarS                                        #
#               2008 Blazingamer                                    #
#               2008 evilynux <evilynux@gmail.com>                  #
#               2008 fablaculp                                      #
#               2009 akedrou                                        #
#                                                                   #
# This program is free software; you can redistribute it and/or     #
# modify it under the terms of the GNU General Public License       #
# as published by the Free Software Foundation; either version 2    #
# of the License, or (at your option) any later version.            #
#                                                                   #
# This program is distributed in the hope that it will be useful,   #
# but WITHOUT ANY WARRANTY; without even the implied warranty of    #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     #
# GNU General Public License for more details.                      #
#                                                                   #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software       #
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,        #
# MA  02110-1301, USA.                                              #
#####################################################################

import os
from Language import _
import Song
import Log
import Config

HANDICAPS = [.75, 1.0, .8, .9, .75, .8, 1.05, 1.1, 1.03, 1.02, 1.01, .95, .9, .85, .7, .95, 0.0, .5, .7, .7]
HANDICAP_NAMES = [_("Auto Kick Bass"), _("Medium Assist Mode"), _("Easy Assist Mode"), _("Jurgen Played!"), \
                  _("Effects Saved SP"), _("All Tapping"), _("HOPO Frequency: Most"), _("HOPO Frequency: Even More"), \
                  _("HOPO Frequency: More"), _("HOPO Frequency: Less"), _("HOPO Frequency: Least"), _("HOPO Disabled!"), \
                  _("Hit Window: Tightest!"), _("Hit Window: Tight!"), _("Hit Window: Wider"), _("Hit Window: Widest"), \
                  _("Two Note Chords"), _("No Fail Mode"), "Scalable Cheat", _("Sloppy Mode!")]
SCALABLE_NAMES = [_("Song Slowdown"), _("Early Hit Window Adjustment")]
SCORE_MULTIPLIER = [0, 10, 20, 30]
BASS_GROOVE_SCORE_MULTIPLIER = [0, 10, 20, 30, 40, 50]

class ScoreCard(object):
  def __init__(self, instrument, coOpType = False):
    self.coOpType = coOpType
    logClassInits = Config.get("game", "log_class_inits")
    if logClassInits == 1:
      Log.debug("ScoreCard class init...")
    self.starScoring = Config.get("game", "star_scoring")
    self.updateOnScore = Config.get("game", "star_score_updates")
    self.avMult = 0.0
    self.hitAccuracy = 0.0
    self.score  = 0
    if instrument == [5]:
      self.baseScore = 0
    else:
      self.baseScore = 50
    self.notesHit = 0
    self.percNotesHit = 0
    self.notesMissed = 0
    self.instrument = instrument # 0 = Guitar, 2 = Bass, 4 = Drum
    self.bassGrooveEnabled = False
    self.hiStreak = 0
    self._streak  = 0
    self.cheats = []
    self.scalable = []
    self.earlyHitWindowSizeHandicap = 1.0
    self.handicap = 0
    self.longHandicap  = ""
    self.handicapValue = 100.0
    self.totalStreakNotes = 0
    self.totalNotes = 0
    self.totalPercNotes = 0
    self.cheatsApply = False
    self.stars = 0
    self.partialStars = 0
    self.starRatio = 0.0
    self.star = [0 for i in range(7)]
    if self.starScoring == 1: #GH-style (mult thresholds, hit threshold for 5/6 stars)
      self.star[5] = 2.8
      self.star[4] = 2.0
      self.star[3] = 1.2
      self.star[2] = 0.4
      self.star[1] = 0.2 #akedrou - GH may start with 1 star, but why do we need to?
      self.star[0] = 0.0
    elif self.starScoring > 1: #RB-style (mult thresholds, optional 100% gold star)
      if self.starScoring == 4:
        if self.instrument[0] == Song.BASS_PART and not self.coOpType:
          self.star[6] = 6.78
          self.star[5] = 4.62
          self.star[4] = 2.77
          self.star[3] = 0.90
          self.star[2] = 0.50
          self.star[1] = 0.21
          self.star[0] = 0.0
        else:
          if self.instrument[0] == Song.DRUM_PART and not self.coOpType:
            self.star[6] = 4.29
          elif self.instrument[0] == Song.VOCAL_PART and not self.coOpType:
            self.star[6] = 4.18
          else:
            self.star[6] = 4.52
          self.star[5] = 3.08
          self.star[4] = 1.85
          self.star[3] = 0.77
          self.star[2] = 0.46
          self.star[1] = 0.21
          self.star[0] = 0.0
      else:
        self.star[5] = 3.0
        self.star[4] = 2.0
        self.star[3] = 1.0
        self.star[2] = 0.5
        self.star[1] = 0.25
        self.star[0] = 0.0
        if self.coOpType:
          self.star[6] = 4.8
        elif self.instrument[0] == Song.BASS_PART: # bass
          self.star[6] = 4.8
        elif self.instrument[0] == Song.DRUM_PART: # drum
          self.star[6] = 4.65
        else:
          self.star[6] = 5.3
    else: #hit accuracy thresholds
      self.star[6] = 100
      self.star[5] = 95
      self.star[4] = 75
      self.star[3] = 50
      self.star[2] = 30
      self.star[1] = 10
      self.star[0] = 0
    
    self.endingScore = 0    #MFH
    self.endingStreakBroken = False   #MFH
    self.endingAwarded = False    #MFH
    self.lastNoteEvent = None    #MFH
    self.lastNoteTime  = 0.0
    self.freestyleWasJustActive = False  #MFH

  
  def reset(self):
    self.avMult = 0.0
    self.hitAccuracy = 0.0
    self.score  = 0
    self.notesHit = 0
    self.notesMissed = 0
    self.hiStreak = 0
    self._streak = 0
    self.cheats = []
    self.handicap = 0
    self.longHandicap  = ""
    self.handicapValue = 100.0
    self.cheatsApply = False
    self.stars = 0
    self.partialStars = 0
    self.starRatio = 0.0
    self.endingScore = 0    #MFH
    self.endingStreakBroken = False   #MFH
    self.endingAwarded = False    #MFH
    self.freestyleWasJustActive = False  #MFH

  def getStarScores(self, tempExtraScore = 0):
    oldStar = self.stars
    if self.updateOnScore == 1 and self.instrument[0] != Song.VOCAL_PART:
      avMult = float(self.score+tempExtraScore) / float(self.totalNotes * self.baseScore)
    else:
      avMult = self.avMult
    if self.starScoring == 1: #GH-style
      if self.hitAccuracy == 100.0 and self.hiStreak == self.totalStreakNotes and not self.cheatsApply:
        self.stars = 7
        self.partialStars = 0
        self.starRatio = 0
        return 7
      if self.hitAccuracy == 100.0 and not self.cheatsApply:
        self.stars = 6
        self.partialStars = 0
        self.starRatio = 0
        return 6
      elif (self.hitAccuracy >= 90.0 and not self.cheatsApply) or avMult >= self.star[5]:
        self.stars = 5
        self.partialStars = 0
        self.starRatio = 0
        return 5
      else:
        for i in range(4, -1, -1):
          if avMult >= self.star[i]:
            part = avMult - self.star[i]
            partPct = part / (self.star[i+1] - self.star[i])
            partStar = int(8*partPct)
            partStar = min(partStar, 7) #catches 99.very9%, just in case
            self.stars = i
            self.partialStars = partStar
            self.starRatio = partPct
            return i
    elif self.starScoring >= 2: #RB-style and RB+GH (and RB2)
      hundredGold = True
      if self.starScoring == 2: 
        hundredGold = False
      if hundredGold and self.hitAccuracy == 1.0 and self.hiStreak == self.totalStreakNotes and not self.cheatsApply:
        self.stars = 7
        self.partialStars = 0
        self.starRatio = 0
        return 7
      if (self.hitAccuracy == 1.0 and hundredGold) or avMult > self.star[6]:
        self.stars = 6
        self.partialStars = 0
        self.starRatio = 0
        return 6
      elif avMult >= self.star[5]:
        self.stars = 5
        self.partialStars = 0
        self.starRatio = 0
        return 5
      else:
        for i in range(4, -1, -1):
          if avMult >= self.star[i]:
            part = avMult - self.star[i]
            partPct = part / (self.star[i+1] - self.star[i])
            partStar = int(8*partPct)
            partStar = min(partStar, 7) #catches 99.very9%, just in case
            self.stars = i
            self.partialStars = partStar
            self.starRatio = partPct
            return i
    else: #FoF
      if self.hitAccuracy == 1.0 and self.hiStreak == self.totalStreakNotes and not self.cheatsApply:
        self.stars = 7
        self.partialStars = 0
        self.starRatio = 0
        return 7
      if self.hitAccuracy == self.star[6]:
        self.stars = 6
        self.partialStars = 0
        self.starRatio = 0
        return 6
      elif self.hitAccuracy >= self.star[5]:
        self.stars = 5
        self.partialStars = 0
        self.starRatio = 0
        return 5
      else:
        for i in range(4, -1, -1):
          if self.hitAccuracy >= self.star[i]:
            part = self.hitAccuracy - self.star[i]
            partPct = part / (self.star[i+1] - self.star[i])
            partStar = int(8*partPct)
            partStar = min(partStar, 7) #catches 99.very9%, just in case
            self.stars = i
            self.partialStars = partStar
            self.starRatio = partPct
            return i

  def updateAvMult(self):
    try:
      self.hitAccuracy = (float(self.notesHit) / float(self.totalStreakNotes) ) * 100.0
    except ZeroDivisionError:
      self.hitAccuracy = 0.0
    try:
      if self.instrument[0] == Song.VOCAL_PART and not self.coOpType:
        self.avMult = float(self.score)/float(self.baseScore)
      else:
        self.avMult      = self.score/float(self.totalNotes*self.baseScore)
    except ZeroDivisionError:
      self.avMult      = 1.0
  
  def updateHandicapValue(self):
    self.handicapValue = 100.0
    slowdown = Config.get("audio","speed_factor")
    earlyHitHandicap      = 1.0 #self.earlyHitWindowSizeHandicap #akedrou - replace when implementing handicap.
    for j in range(len(HANDICAPS)):
      if (self.handicap>>j)&1 == 1:
        if j == 1: #scalable
          if slowdown != 1:
            if slowdown < 1:
              cut = (100.0**slowdown)/100.0
            else:
              cut = (100.0*slowdown)/100.0
            self.handicapValue *= cut
          if earlyHitHandicap != 1.0:
            self.handicapValue *= earlyHitHandicap
        else:
          self.handicapValue *= HANDICAPS[j]
  
  def getStreak(self):
    return self._streak
    
  def setStreak(self, value):
    self._streak = value
    self.hiStreak = max(self._streak, self.hiStreak)
  
  streak = property(getStreak, setStreak)
  
  def addScore(self, score):
    self.score += score * self.getScoreMultiplier()

  def addEndingScore(self):
    self.score += self.endingScore

  def getScoreMultiplier(self):
    if self.instrument == [Song.BASS_PART] and self.bassGrooveEnabled:    #myfingershurt: bass groove
      try:
        return BASS_GROOVE_SCORE_MULTIPLIER.index((self.streak / 10) * 10) + 1
      except ValueError:
        return len(BASS_GROOVE_SCORE_MULTIPLIER)
    elif self.instrument == [Song.VOCAL_PART]:
      return min(self.streak + 1, 4)
    else:
      try:
        return SCORE_MULTIPLIER.index((self.streak / 10) * 10) + 1
      except ValueError:
        return len(SCORE_MULTIPLIER)

class Rockmeter:
  pass # future breaking out of rockmeter can likely go here. Scorekeeper seems fitting.