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
#!/usr/bin/python
# -*- coding: GBK -*-
#---------------------------------------------------------------------
#
#---------------------------------------------------------------------
##@package SubjectLib
# @todo: ´ðÌâ¶ÁÌâ¹ÜÀíÆ÷
#
# @author: panwei
# @date 2011-03-31
# @version 1.0
#
#ΪÁ˱ÜÃâÈ¡µ½ÏàͬÌâÄ¿µÄÇé¿ö:
#Ìâ¿â·ÖΪ: Ô­Ê¼Ìâ¿âºÍ¶¯Ì¬Ìâ¿â, Ô­Ê¼Ìâ¿â¶ÁÈ¡ÌâÄ¿,
#
#1. ¶¯Ì¬Ìâ¿â ¸ù¾ÝԭʼÌâ¿âÉú³ÉËæ»úÌâ¿â
#2. Ìâ¿â´Ó¶¯Ì¬Ìâ¿âÀïÃæÈ¡
#3. Ã¿È¡Ò»Ìâ, ´Ó¶¯Ì¬Ìâ¿âÖÐɾ³ýÕâÒ»Ìâ
#4. Èç¹û¶¯Ì¬Ìâ¿âÈ¡ÍêÁË, ÔòÖØÐÂÉú³É¶¯Ì¬Ìâ¿â
#---------------------------------------------------------------------
"""Version = 2011-03-31 17:30"""
#---------------------------------------------------------------------
import ReadChConfig
import ChConfig
import GameWorld
import copy
import random
#---------------------------------------------------------------------
#¹Ì̬Ìâ¿â
__AllSubject = {}
#¶¯Ì¬Ìâ¿â
__DelicacySuject = {}
#---------------------------------------------------------------------
## Ëæ»ú»ñµÃÒ»µÀÌâÄ¿
#  @param examType ´ðÌâÀàÐÍDef_Game_Exam_Type
#  @return Ôª×é(ID: [ÌâÄ¿ÊôÐÔ])
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def GetSubject(examType):
    global __DelicacySuject
    
    if len(__AllSubject) == 0:
        __ReloadExamSubject()
        
    #µÚÒ»´Î¼ÓÔØÌâÄ¿,³õʼ»¯
    if len(__DelicacySuject) == 0:
        __DelicacySuject = copy.deepcopy(__AllSubject)
 
    #»ñµÃÌâ¿â
    sujectDict = __DelicacySuject.get(examType)
    #ÅׯúÒì³£
    if sujectDict == None:
        GameWorld.ErrLog("»ñÈ¡Ìâ¿âÒì³£ examType = %s"%(examType))
        return []
    
    #ÎÞÌâÄ¿ÁË,ÖØÐ¼ÓÔØÔ­Ê¼Ìâ¿â
    if len(sujectDict) == 0:
        __DelicacySuject = copy.deepcopy(__AllSubject)
    
    #»ñµÃÌâ¿â
    sujectDict = __DelicacySuject.get(examType)
    
    if len(sujectDict) == 0:
        GameWorld.ErrLog("Ìâ¿âÒì³£ examType = %s, ÎÞÌâÄ¿"%(examType))
        return []
    
    #Ëæ»úÕÒÒ»¸öÌâÄ¿, ²¢´ÓÁÙʱÌâ¿âÖÐɾ³ý
    randNum = random.choice(sujectDict.keys())
    randSubjectList = [randNum, sujectDict[randNum]]
    sujectDict.pop(randNum)
    
    return randSubjectList
#---------------------------------------------------------------------
##ÖØÐ¼ÓÔØÌâ¿â
# @param ÎÞ²ÎÊý
# @return None
# @remarks 
def __ReloadExamSubject():
    global __AllSubject
    
    for examType, examName in ChConfig.Def_ExamSubjectNameDict.items():
        __AllSubject.update({examType : ReadChConfig.GetEvalChConfig(examName)})
    
    return