예제 #1
0
def parse_target_sheet(sh, tbTarget, tbCondition):
    for row in range(1, sh.nrows):

        targetId = get_str_from_sheet(sh, row, 0)
        targetFuncName = "target" + upFirstChar(targetId)

        memo = get_str_from_sheet(sh, row, 1)
        fanwei = get_str_from_sheet(sh, row, 2)
        sortMethod = get_str_from_sheet(sh, row, 3)
        selectCnt = get_int_from_sheet(sh, row, 4)
        if (selectCnt == 0):
            selectCnt = 9999

        #in buff
        inBuff = get_str_array_from_sheet(sh, row, 5)
        #not in buff
        notInBuff = get_str_array_from_sheet(sh, row, 6)

        #print(targetId, memo, fanwei, sortMethod, selectCnt, inBuff, notInBuff)

        # 解析
        sortKey = ""
        intAsc = 1

        if (len(sortMethod)):
            lstSortMethod = sortMethod.split(",")
            sortKey = lstSortMethod[0]

            if (len(lstSortMethod) > 1):
                intAsc = int(lstSortMethod[1])

        paramDefine = ""
        srcCnd = ""
        dicParam = {}

        for col in range(7, sh.ncols):
            cnd = get_str_from_sheet(sh, row, col)

            if len(cnd) == 0:
                continue

            if (cnd in tbCondition):
                srcCnd += u'''
        if ( !(%s( ai_obj, nil)) ) continue;
''' % ("cnd" + upFirstChar(cnd))
            else:
                exp = parse_expr_right(cnd, dicVar, 1, dicParam)
                paramDefine += exp[0]
                srcCnd += u'''
        if ( !(%s) ) continue;
''' % exp[1]

        src = srcTargetFunction % (memo, targetFuncName, fanwei, sortKey,
                                   intAsc, selectCnt, paramDefine + srcCnd)
        #print( src )
        tbTarget[targetId] = src
예제 #2
0
def parse_sheet(sh, dicVar):
    for row in range(11, sh.nrows):
        key = get_str_from_sheet(sh, row, 1)
        if len(key) == 0:
            continue
        dec = get_str_from_sheet(sh, row, 2)
        value = get_int_from_sheet(sh, row, 0)
        valueAndDec = {}
        valueAndDec["key"] = key
        valueAndDec["dec"] = dec
        dicVar[value] = valueAndDec
예제 #3
0
def parse_dblog_dsc(sh, dicType):
	allTypeKeys = dicType.keys()
	for row in range(1, sh.nrows):
		key = ""
		for col in range(0, sh.ncols):
			head = get_str_from_sheet(sh, 0, col)
			value = get_str_from_sheet(sh, row, col)
			if len(value) == 0: continue
			if head == u"日志动作":
				key = get_str_from_sheet(sh, row, 0)
				allFlow[key] = {}
			else:
				allFlow[key][head] = value	
예제 #4
0
def parse_sheet(sh, dicVar):
    for row in range(11, sh.nrows):
        #dec = get_str_from_sheet(sh, row, 1)
        key = get_str_from_sheet(sh, row, 4)
        if len(key) == 0:
            continue
        if key[0:3] != "ERR":
            key = PARSE.parse_c2t(key)
        dec = get_str_from_sheet(sh, row, 1)
        value = get_int_from_sheet(sh, row, 0)
        valueAndDec = {}
        valueAndDec["key"] = key
        valueAndDec["dec"] = dec
        dicVar[value] = valueAndDec
예제 #5
0
def parse_formula_sheet(sh, output_file):

    all_fun = begin
    for row in range(2, sh.nrows):
        skill_id_str = get_str_from_sheet(sh, row, 0)
        skill_name_str = get_str_from_sheet(sh, row, 1)
        skill_formula_str = get_str_from_sheet(sh, row, 2)
        fun_str = parse_function(skill_formula_str, u"技能名:" + skill_name_str,
                                 u"ser_%s" % skill_id_str, dicVar,
                                 srcSkillFormla)
        all_fun += fun_str
    #	src_file = path + "/" + skill_id_str + ".c"
    #	write_src(output_file, begin, end, fun_str, "utf-8")
    all_fun += end
    write_file(output_file, all_fun)
예제 #6
0
def parse_xls(filename, sn, output_path):
	try:
		book = xlrd.open_workbook(filename)
	except:
		msg = u"can't open file? %s"%filename
		print( msg )
		usage()
		raise

	# 遍历xls
	for x in xrange(book.nsheets):
		sh = book.sheet_by_index(x)
		sheetname = sh.name
		if sheetname == u"battle_scene":
			battle_id = common.get_str_from_sheet(sh, 0, 1);
			# 玩家入场ai_list和x,y,dir
			player_ai_list = common.get_str_array_from_sheet(sh, 1, 1);
			player_x = common.get_int_from_sheet(sh, 1, 2)
			player_y = common.get_int_from_sheet(sh, 1, 3)
			player_dir = common.get_int_from_sheet(sh, 1, 4)
			target_dir = common.get_int_from_sheet(sh, 1, 5)
			scene_id = common.get_int_from_sheet(sh, 2, 1)
			reward = common.get_str_array_from_sheet(sh, 4, 1)
			# 敌方入场数据
			scene_data, row_line = common.parse_table(sh, 5, 0)

		if sheetname == u"ships":
			# 敌方入场数据
			ships, row_line = common.parse_table(sh, 0, 0)

	# 写文件
	src = srcData % (PythonData2Lpc(player_ai_list, True, 2, 0), player_dir, target_dir, player_x, player_y, scene_id, battle_id, PythonData2Lpc(scene_data, True, 1, 1), PythonData2Lpc(ships, True, 1, 1), PythonData2Lpc(reward, True, 2, 0))
	common.write_src(output_path, begin, end, src, 'utf-8')
예제 #7
0
def parse_xls(filename, outputpath):
    try:
        book = xlrd.open_workbook(filename)
    except:
        msg = "can't open file?", filename
        usage()
        sys.exit(-1)

    # 保证先处理扩展数值表
    for x in xrange(book.nsheets):
        sh = book.sheet_by_index(x)
        if sh.name == u"变量表":
            parse_var_sheet(sh, dicVar)
            continue
    print dicVar

    for x in xrange(book.nsheets):
        sh = book.sheet_by_index(x)
        #print(sh.name, sheetname.decode("utf-8"))
        if sh.ncols < 3:
            continue
        # 判断是否奖励表
        if get_str_from_sheet(sh, 0, 4) != u"奖励表":
            continue
        parse_sheet(sh, outputpath)
        continue
예제 #8
0
def parse_status_sheet(sh, dicVar):
    idCol = 0
    headRow = 1
    for row in range(2, sh.nrows):
        status = get_str_from_sheet(sh, row, idCol)
        print status
        srcStatus = u"""
#include <fight.h>

inherit STAUTS_BASE;

#include <var_prop.h>
#include <user_key.h>

// 状态ID
RESET_ONUPDATE_VAR(StatusId, "%s")

""" % (status)
        for col in range(1, sh.ncols):
            headMemo = get_str_from_sheet(sh, 0, col)
            head = get_str_from_sheet(sh, 1, col)
            type = parseStatusTable[head]["type"]
            name = parseStatusTable[head]["value_name"]
            templete = parseStatusTable[head]["templete"]

            srcStatus += GetSrcByType(headMemo, type, name, sh, row, col,
                                      templete)

            if (head == "status_name"):
                value = get_str_from_sheet(sh, row, col)
                statusName2Id[value] = status

        if (status in statusRelation):
            #状态关系表
            #ExcludeStatus
            #OverwriteStatus
            srcStatus += u"""
// 排斥状态
RESET_ONUPDATE_VAR(ExcludeStatus, %s)
""" % (PythonData2Lpc(statusRelation[status]["exclude"]))
            srcStatus += u"""
// 覆盖状态
RESET_ONUPDATE_VAR(OverwriteStatus, %s)
""" % (PythonData2Lpc(statusRelation[status]["overwrite"]))
        statusFile = "module/fight/status/%s.c" % status

        write_src(statusFile, begin, end, srcStatus, u"utf-8")
예제 #9
0
def parse_var_sheet(sh, dicVar):
    for row in range(1, sh.nrows):
        key = ""
        for col in range(0, sh.ncols):
            head = get_str_from_sheet(sh, 0, col)

            if head == u"策划用名":
                key = get_str_from_sheet(sh, row, col)
                dicVar[key] = {}
            else:
                if head == u"程序变量获取":
                    get_var = get_str_from_sheet(sh, row, col)
                    dicVar[key]["get_func"] = get_var
                elif head == u"程序变量设置":
                    set_var = get_str_from_sheet(sh, row, col)
                    dicVar[key]["set_func"] = set_var
                elif head == u"变量名":
                    name = get_str_from_sheet(sh, row, col)
                    dicVar[key]["var_name"] = name
                elif head == u"备注":
                    desc = get_str_from_sheet(sh, row, col)
                    dicVar[key]["var_desc"] = desc
                elif head == u"更改变量类型":
                    var_type = get_str_from_sheet(sh, row, col)
                    dicVar[key]["var_type"] = var_type
                else:
                    continue
예제 #10
0
def parse_status_relation_sheet(sh, dicVar):
    headRow = 2
    headCol = 2
    for row in range(3, sh.nrows):
        for col in range(3, sh.ncols):
            relation = get_int_from_sheet(sh, row, col)
            if (relation == 0):
                continue
            status = get_str_from_sheet(sh, row, headCol)
            targetStatus = get_str_from_sheet(sh, headRow, col)

            if status not in statusRelation:
                statusRelation[status] = {
                    "exclude": [],
                    "overwrite": [],
                }
            if (relation == 1):
                statusRelation[status]["exclude"].append(targetStatus)
            if (relation == 2):
                statusRelation[status]["overwrite"].append(targetStatus)
예제 #11
0
def parse_condition_sheet(sh, tbCondition):
    # cnd_hpmax_50
    for row in range(1, sh.nrows):
        # 条件id
        conditionId = get_str_from_sheet(sh, row, 0)

        if conditionId == "":
            continue

        cndFuncName = "cnd" + upFirstChar(conditionId)

        # 条件备注
        conditionMemo = get_str_from_sheet(sh, row, 1)

        paramDefine = ""
        cnds = ""

        dicParam = {}

        for col in range(2, sh.ncols):
            cnd = (get_str_from_sheet(sh, row, col))
            if (len(cnd) == 0):
                continue
            exp = parse_expr_right(cnd, dicVar, 0, dicParam)
            #print("exp[0]", exp[0])
            #print("exp[1]", exp[1])
            paramDefine += exp[0]
            cnds += '''
    // %s
    if ( !(%s) ) return 0;
''' % (cnd, exp[1])

        conditionSrc = srcConditionFunction % (conditionMemo, cndFuncName,
                                               paramDefine + cnds)

        #print( conditionId, conditionMemo )
        #print( conditionSrc )

        tbCondition[conditionId] = conditionSrc
예제 #12
0
def parse_type_sheet(sh, sheetName, dicType):
	dicType[sheetName] = {}
	subType2Type[sheetName] = {}
	typeDict = {}
	for row in range(1, sh.nrows):
		key = ""
		for col in range(0, sh.ncols):
			head = get_str_from_sheet(sh, 0, col)
			value = get_str_from_sheet(sh, row, col)
			if head == "Name":
				key = get_str_from_sheet(sh, row, 0)
				if len(key) == 0: continue
				typeDict[key] = {};
			else:
				#print head
				typeDict[key][head] = value
				#记录自定义类型的数据类型
				#if head == "Type" and not typeDict.has_key(head):
				#	typeDict[head] = value
				if head == "Type" and not subType2Type[sheetName].has_key(head):
					subType2Type[sheetName][head] = value

	dicType[sheetName] = typeDict 
예제 #13
0
def parse_formula_sheet(sh, output_file):

    print(dicVar)
    all_fun = begin
    for row in range(3, sh.nrows):
        skill_id_str = get_str_from_sheet(sh, row, 0)
        #skill_name_str = get_str_from_sheet(sh, row, 1)
        skill_formula_str = get_str_from_sheet(sh, row, 1)
        print(skill_id_str, skill_formula_str)
        #fun_str = parse_function(skill_formula_str, u"技能ID:"+skill_id_str, u"param_%s" % skill_id_str, dicVar, srcSkillFormla)
        #print( fun_str );

        expSrc = parse_expr_right(skill_formula_str, dicVar, 0, {})

        fun_str = srcSkillFormla % (skill_id_str, skill_id_str,
                                    skill_formula_str, expSrc[1])
        print(fun_str)

        all_fun += fun_str
    write_src(output_file, begin, end, all_fun, "utf-8")

    all_fun += end
    write_file(output_file, all_fun)
예제 #14
0
def GetSrcByType(headMemo, type, name, sh, row, col, templete):
    src = ""
    if (type == "int"):
        value = get_int_from_sheet(sh, row, col)
        src = templete % (headMemo, name, PythonData2Lpc(value))
    elif (type == "str"):
        value = get_str_from_sheet(sh, row, col)
        src = templete % (headMemo, name, PythonData2Lpc(value))
    elif type == "str_array":
        value = get_str_array_from_sheet(sh, row, col)
        src = templete % (headMemo, name, PythonData2Lpc(value))
    elif type == "status_array":
        tmp = get_str_array_from_sheet(sh, row, col)
        for idx in range(len(tmp)):
            if (tmp[idx] in statusName2Id):
                tmp[idx] = statusName2Id[tmp[idx]]
        value = tmp
        src = templete % (headMemo, name, PythonData2Lpc(value))
    elif type == "macro":
        value = get_str_from_sheet(sh, row, col)
        if (len(value) == 0):
            return src
        src = templete % (headMemo, name, value)
        print("xxxxxxx: src = ", src)
    elif type == "function":
        value = get_str_from_sheet(sh, row, col)
        if (len(value)):
            #print(value)
            #print( dicVar )
            src = parse_function(value, headMemo, name, dicVar, templete)
    else:
        value = get_str_from_sheet(sh, row, col)
        src = templete % (headMemo, name, PythonData2Lpc(value))

    #srcSkill += templete%headMemo, name, PythonData2Lpc(value))
    return src
예제 #15
0
def parse_fuben_sheet(sh, path, tbAttr ):
	for row in range(0, sh.nrows):
		head = get_str_from_sheet(sh, row, 0)
		#print(head)
		if (len(head) == 0):
			continue;

		if head not in dicParseTable:
			continue;

		parseInfo = dicParseTable[head]
		if parseInfo == u"pass":
			continue

		#print( parseInfo )
		result = parseInfo[0](sh, row, 0)
		#print(result)
		tbAttr[parseInfo[1]] = { "data":result[0], "memo":head }
		row = result[1]
		#tbAttr.append( (passInfo[1], )

	srcAttr = u''
	for attrName in tbAttr:
		attrData = tbAttr[attrName]
		if ( attrName != u"FubenDispatch" ):
			srcAttr += (u'''
// %s
RESET_ONUPDATE_VAR( %s, %s )'''%(attrData["memo"], attrName, PythonData2Lpc(attrData["data"], True)))
		else:
			srcAttr += (u'''
// %s
mapping mpFubenDispatch = %s;
mapping GetFubenDispatch()
{
	return mpFubenDispatch;
}
'''%(attrData["memo"], PythonData2Lpc(attrData["data"], True)))
			

	src = srcFubenTemplete % srcAttr

	#print( src )
	#print( path + "../scene" )
	#print(tbAttr)
	fubenId = tbAttr[u"FubenId"]["data"];
	srcFile = path + "/../fuben/" + fubenId + ".c"
	#print( srcFile )
	write_src(srcFile, begin, end, src, "utf-8")
예제 #16
0
def parse_table( sh, curLine, startCol ):
	tb = {}
	row = curLine + 2
	if row >= sh.nrows:
		return tb, row;
	head = get_str_from_sheet( sh, row, startCol )
	while len(head) > 0:
		keyNameType = get_str_from_sheet( sh, curLine+1, startCol)
		tmp = headExp.match( keyNameType )
		var_name = tmp.group("var_name")
		var_type = tmp.group("var_type")

		if var_type == "int":
			key = get_int_from_sheet( sh, row, startCol)
		else:
			key = get_str_from_sheet( sh, row, startCol)

		curData = {}
		
		for col in xrange( startCol + 1, sh.ncols):
			nameType = get_str_from_sheet( sh, curLine+1, col)
			print(nameType)
			tmp = headExp.match( nameType )
			var_name = tmp.group("var_name")
			var_type = tmp.group("var_type")

			if var_type == "int":
				value = get_int_from_sheet( sh, row, col)
			else:
				value = get_str_from_sheet( sh, row, col)

			curData[var_name] = value

		print( curData )
		tb[key] = curData


		row = row + 1
		if row >= sh.nrows:
			break
		head = get_str_from_sheet( sh, row, startCol )

	return tb, row
예제 #17
0
def parse_string_array(sh, curLine, col):
    strValue = get_str_from_sheet(sh, curLine, col + 1)
    strArray = strValue.split(",")
    return strArray, curLine
예제 #18
0
def parse_string(sh, curLine, col):
    strValue = get_str_from_sheet(sh, curLine, col + 1)
    return strValue, curLine
예제 #19
0
def parse_enter_pos(sh, curLine, col):
    enterPos = get_str_from_sheet(sh, curLine, col + 1)
    return eval("[" + enterPos + "]"), curLine
예제 #20
0
def parse_ai_sheet(sh, path, tbCondition, tbTarget):
    srcCnd = ""

    for cndId in tbCondition:
        srcTmp = tbCondition[cndId]
        srcCnd += srcTmp

    srcTarget = ""
    for targetId in tbTarget:
        srcTmp = tbTarget[targetId]
        srcTarget += srcTmp

    for row in range(1, sh.nrows):
        #srcAITemplete
        aiId = get_str_from_sheet(sh, row, 0)
        if aiId == "":
            continue
        # 1 ai memo
        memo = get_str_from_sheet(sh, row, 1)
        # 2 ai class name
        aiClsName = "ClsAI" + upFirstChar(aiId)
        # 3 base attr funcs
        #   id
        funcId = srcStrData % (u"AI ID", "AIId", aiId)
        srcBaseAttrFuncs = funcId
        #   时机
        opportunity = get_str_from_sheet(sh, row, 2)
        if opportunity not in dicOpportunity:
            print(u"ERROR:unknow opportunity:" + opportunity)
            strOpportunity = "ERROR:" + opportunity
        else:
            strOpportunity = "@@" + dicOpportunity[opportunity]

        funcOpportunity = srcData % (u"AI时机", "Opportunity",
                                     PythonData2Lpc(strOpportunity))

        srcBaseAttrFuncs += funcOpportunity
        #   优先级别
        priority = get_int_from_sheet(sh, row, 3)
        funcPriority = srcIntData % (u"AI优先级别", "Priority", priority)
        srcBaseAttrFuncs += funcPriority

        # 停止标记
        stop_other_flg = get_int_from_sheet(sh, row, 4)
        funcStopOtherFlg = srcIntData % (u"AI停止标记", "StopOtherFlg",
                                         stop_other_flg)
        srcBaseAttrFuncs += funcStopOtherFlg

        # 删除标记
        delete_other_flg = get_int_from_sheet(sh, row, 5)
        funcDeleteOtherFlg = srcIntData % (u"AI删除标记", "DeleteOtherFlg",
                                           delete_other_flg)
        srcBaseAttrFuncs += funcDeleteOtherFlg

        lstTarget = []
        lstCnd = []

        # 4 cnd funcs
        cnd = get_str_from_sheet(sh, row, 6)
        conditionSrc = ""
        if (len(cnd)):

            # 处理条件
            if (cnd in tbCondition):
                cndFunName = "cnd" + upFirstChar(cnd)
                srcTmp = u'''\treturn %s(mpAI, 0)''' % cndFunName
                lstCnd.append(cnd)
            else:
                dicParam = {}
                exp = parse_expr_right(cnd, dicVar, 0, dicParam)
                #print("xxxxxxxxxxxxxx", cnd, exp)
                srcTmp = u'''\t%s\n\treturn (%s)''' % (exp[0], exp[1])

            conditionSrc = srcCheckConditionFunction % (srcTmp)

            #srcCnd += conditionSrc

        lstAct = []
        tbActionFuncs = {}
        index = 0
        for col in range(7, sh.ncols, 3):
            # 5 target funcs
            target = get_str_from_sheet(sh, row, col)
            # 6 act funcs
            action = get_str_from_sheet(sh, row, col + 1)
            if (len(action) == 0):
                continue
            # 7 actions
            action_content = get_str_from_sheet(sh, row, col + 2)

            # {"delay", "SELF", { 6000, }},
            tmpAction = [
                dicAction[action],
                "",
                [],
            ]
            if (target in tbTarget):
                tmpAction[1] = "@@target" + upFirstChar(target)
            else:
                tmpAction[1] = target

            #TODO:parse action functions
            params = parse_action_function(aiId, index, action, action_content,
                                           tbActionFuncs)
            tmpAction[2] = params

            lstAct.append(tmpAction)
            index += 1

        srcActFuncs = ""
        for actFunctionName in tbActionFuncs:
            srcActFuncs += tbActionFuncs[actFunctionName]

        dictTargetMethod = {}
        for targetMethod in tbTarget.keys():
            dictTargetMethod[targetMethod] = "@@target" + upFirstChar(
                targetMethod)

        aiSrc = srcAITemplete % (memo, srcBaseAttrFuncs, srcCnd + conditionSrc,
                                 srcTarget, srcActFuncs,
                                 PythonData2Lpc(lstAct, True, 1, 1),
                                 PythonData2Lpc(dictTargetMethod, True, 1, 1))

        ai_str = ("/" + aiId + ".c").encode(sys.getfilesystemencoding())
        #print(aiSrc)
        #print(path + ai_str)
        #print(begin)
        #print(end)
        write_src(path + ai_str, begin, end, aiSrc, "utf-8")
        print(">>> [I] ai success write to " + path + ai_str)
예제 #21
0
def parse_sheet(sh, outputpath):
    headRow = 10
    startRow = 11

    for row in xrange(startRow, sh.nrows):
        itemid = get_int_from_sheet(sh, row, 0)
        if (itemid == 0):
            continue

        itemData = {}
        for col in xrange(1, sh.ncols):
            head = get_str_from_sheet(sh, headRow, col)
            if (len(head) == 0):
                continue

            tmp = parse_head.match(head)

            if (tmp == None):
                #print("ERROR:HEAD %s", head)
                #print(tmp)
                continue

            var = tmp.group("var")
            varType = tmp.group("type")

            if (varType == 'int'):
                data = get_int_from_sheet(sh, row, col)
                if data == 0 and var != "type":
                    continue
            elif (varType == 'str'):
                data = get_str_from_sheet(sh, row, col)
                if data == "":
                    continue
            elif (varType == 'macro'):
                data = "@@%s" % get_str_from_sheet(sh, row, col)
            elif (varType == 'str_array'):
                data = get_str_array_from_sheet(sh, row, col)
                if len(data) == 0:
                    continue
            elif (varType == 'map'):
                data = parse_map(get_str_from_sheet(sh, row, col))
            elif varType == 'formula':
                sNote = get_str_from_sheet(sh, headRow - 2, col)
                data = parse_formula(get_str_from_sheet(sh, row, col), sNote)
            itemData[var] = data

        #print( itemid, itemData )
        itemType = ("%s" % itemData["server_item_base"])

        itemBase = PythonData2Lpc(itemType)
        #print( itemType, itemBase )

        # 处理各种类型的特殊参数
        if (itemBase == ITEM_BASE_EXP_BOOK):
            exp = int(itemData["args"])
            itemData["exp"] = exp
        elif (itemBase == ITEM_BASE_GIFT):
            rewards = itemData["args"].split(",")
            itemData["rewards"] = rewards
        elif (itemBase == ITEM_BASE_SKILL_BOOK):
            skillIdStrs = itemData["args"].split(",")
            skillIds = []
            for var in skillIdStrs:
                skillIds += [int(var)]
            itemData["skillIds"] = skillIds
        elif (itemBase == ITEM_BASE_BAWOU_BOX):
            rewards = itemData["args"].split(",")
            itemData["rewards"] = rewards

        srcAttr = u""
        for var in itemData.keys():

            if var not in ParseVarTable:
                continue
            info = ParseVarTable[var]

            data = itemData[var]

            if info[0] == u"attr":
                srcTmp = u'''
RESET_ONUPDATE_VAR(%s, %s)
''' % (info[1], PythonData2Lpc(data))

                srcAttr += srcTmp
            elif info[0] == u"func":
                srcTmp = u'''
%s %s()
{
	return %s;
}

''' % (info[2], info[1], PythonData2Lpc(data))

                srcAttr += srcTmp
            elif info[0] == u"formula":
                if data:
                    srcTmp = info[1] % (data)
                    srcAttr += srcTmp

        src = SRC_ITEM_TEMPLATE % (itemBase, srcAttr)

        #print(src)
        filename = "%s/%d.c" % (outputpath, itemid)
        #print( filename )
        write_src(filename, begin, end, src, "utf-8")
예제 #22
0
def parse_sailor_sheet(sh, dicVar, output_path):
    startRow = get_int_from_sheet(sh, 3, 1) - 1
    headRow = startRow - 1
    print("startRow = %d" % startRow)
    print("headRow = %d" % headRow)

    #表添加了新的列,这个变量要改
    #endCol = 27
    endCol = sh.ncols

    for row in range(startRow, sh.nrows):
        baseSrcLst = []
        fightValueSrcLst = []
        sailorTmpSrcLst = []
        sailorBaseSrcLst = []
        sailorTrainSrcLst = []
        upstarUpgradeSailorLst = []
        upgradeSailorLst = []
        sailorInvestLst = []
        attrLst = []
        reviseAttrLst = []
        commonLst = []
        sailorId = get_str_from_sheet(sh, row, 0)
        for col in range(0, endCol):
            head = get_str_from_sheet(sh, headRow, col)
            if (len(head) == 0):
                continue
            data = get_str_from_sheet(sh, row, col)
            if (len(data) == 0):
                continue

            #print( "[%s]=%s"%(head, data) )
            if (head == u"formula"):
                note = get_str_from_sheet(sh, headRow - 2, col)
                # TODO:打断公式取左值,看看是那种类型的变量
                eqCharIdx = data.find(u"=")
                lrSplit = re.compile(u'[==]{1}')

                if eqCharIdx != -1:
                    lvalue = data[0:eqCharIdx]
                    lvalue = lvalue.strip()

                src = parse_function(data, note, "", dicVar, "\t// %s%s%s")
                print(src)
                if dicVar[lvalue]["var_type"] == u"战斗数值":
                    fightValueSrcLst.append(src)
                elif dicVar[lvalue]["var_type"] == u"水手临时数值":
                    sailorTmpSrcLst.append(src)
                elif dicVar[lvalue]["var_type"] == u"船只基础数值":
                    baseSrcLst.append(src)
                elif dicVar[lvalue]["var_type"] == u"水手基础属性值":
                    sailorBaseSrcLst.append(src)
                elif dicVar[lvalue]["var_type"] == u"水手洗练属性值":
                    sailorTrainSrcLst.append(src)
                elif dicVar[lvalue]["var_type"] == u"水手升星属性值":
                    upstarUpgradeSailorLst.append(src)
                elif dicVar[lvalue]["var_type"] == u"水手升级属性值":
                    upgradeSailorLst.append(src)
                elif dicVar[lvalue]["var_type"] == u"水手投资获得经验值":
                    sailorInvestLst.append(src)
                elif dicVar[lvalue]["var_type"] == u"公用":
                    commonLst.append(src)
                continue

            tmp = headExp.match(head)
            if tmp == None:
                continue

            var_name = tmp.group("var_name")
            var_type = tmp.group("var_type")

            if var_type == "int":
                var = int(data)
                srcAttr = attrSrc % (var_name, PythonData2Lpc(var))
                attrLst.append(srcAttr)
            if var_type == "float":
                var = float(data)
                srcAttr = attrSrc % (var_name, PythonData2Lpc(var))
                attrLst.append(srcAttr)
            if var_type == "string":
                var = data
                srcAttr = attrSrc % (var_name, PythonData2Lpc(var))
                attrLst.append(srcAttr)
            if var_type == "array":
                var = []
                tmpLst = data.split(",")
                for tmp in tmpLst:
                    var.append(int(tmp))
                srcAttr = attrSrc % (var_name, PythonData2Lpc(var))
                attrLst.append(srcAttr)
            if var_type == "special":
                var = []
                tmpLst = data.split(";")
                for st in tmpLst:
                    tm = st.split(",")
                    tmp1 = []
                    for tmp in tm:
                        tmp1.append(int(tmp))
                    var.append(tmp1)
                srcAttr = attrSrc % (var_name, PythonData2Lpc(var))
                attrLst.append(srcAttr)

            if var_type == "intermediate":
                #reviseVar = int(data)/100.0
                reviseVar = int(data)
                reviseAttr = attrReviseSrc % (var_name,
                                              PythonData2Lpc(reviseVar))
                reviseAttrLst.append(reviseAttr)

            if var_type == "dir":
                var = []
                tmpLst = data.split(";")
                for st in tmpLst:
                    tm = st.split(",")
                    tmp1 = []
                    for tmp in tm:
                        tmp1.append(tmp)
                    var.append(tmp1)
                srcAttr = attrSrc % (var_name, PythonData2Lpc(var))
                attrLst.append(srcAttr)

            if var_type == "dir_map":
                var = []
                tmpLst = data.split(";")
                for st in tmpLst:
                    tm = st.split(",")
                    tmp1 = []
                    for tmp in tm:
                        tmp1.append(int(tmp))
                    var.append(tmp1)
                srcAttr = attrSrc % (var_name, PythonData2Lpc(var))
                attrLst.append(srcAttr)
            if var_type == "map":
                var = parse_map(data)
                srcAttr = attrSrc % (var_name, PythonData2Lpc(var))
                attrLst.append(srcAttr)

        if sailorId != "":
            filename = "%s/%s.c" % (output_path, sailorId)
            filecontent = srcSailorTemplete % (
                u"\n".join(attrLst), u"\n".join(reviseAttrLst),
                u"\n".join(sailorInvestLst), u"\n".join(commonLst),
                u"\n".join(sailorBaseSrcLst), u"\n".join(sailorTrainSrcLst),
                u"\n".join(upstarUpgradeSailorLst),
                u"\n".join(upgradeSailorLst), u"\n".join(sailorTmpSrcLst),
                u"\n".join(baseSrcLst), u"\n".join(fightValueSrcLst))

            print(filecontent)
            try:
                src_data = open(filename, "rb").read()
                if len(src_data) == 0:
                    src_data = begin + "\n\n" + end
            except IOError:
                src_data = begin + "\n\n" + end

            tmp = p.sub(begin + "\n" + filecontent + "\n" + end, src_data)

            write_file(filename, tmp)
예제 #23
0
def parse_sheet(sh, outputpath):
    # 读取奖励表
    print sh.name

    startRow = get_int_from_sheet(sh, 3, 1) - 1
    rRewardId = get_str_from_sheet(sh, 0, 5)
    rType = get_str_from_sheet(sh, 4, 4)

    endRow = sh.nrows

    srcAttr = u""

    srcAttr += u'''
RESET_ONUPDATE_VAR(Id, %s)
''' % PythonData2Lpc(rRewardId)
    srcAttr += u'''
RESET_ONUPDATE_VAR(Type, TB_TYPE_%s)
''' % rType

    srcFunction = u""

    rewardData = {}
    for row in range(startRow, endRow):
        #序号	类型	名字	类型ID	数量	概率	商会公告   公告	   说明
        #reward_no(str)	type(str)		id(int)	cnt(int)	rate(int)		memo(str)
        #reward_no(str)	type(str)		id(int)	cnt(int)	rate(int)	group_gonggao(str)   gonggao(str)	memo(str)    condition(str)
        no = get_str_from_sheet(sh, row, 0)
        rTypeName = get_str_from_sheet(sh, row, 1)
        rType = get_str_from_sheet(sh, row, 2)
        rName = get_str_from_sheet(sh, row, 3)
        rId = get_str_from_sheet(sh, row, 4)
        if (rId != "" and not rId.isdigit()):
            funcName = u"CalcId%s" % no
            expTmp = parse_expr_right(rId, dicVar, 0, {})
            srcTmp = srcFuncTemplete % ("奖励ID计算函数,只为公会红包准备", funcName,
                                        expTmp[1])

            srcFunction += srcTmp

            rId = "@@%s" % funcName
        else:
            if (rId == ""):
                rId = 0
            else:
                rId = int(rId)

        rAmount = get_str_from_sheet(sh, row, 5)
        rRate = get_int_from_sheet(sh, row, 6)

        # 商会公告(目前应该没用)
        rGroupGonggao = get_str_array_from_sheet(sh, row, 7)
        if (len(rGroupGonggao) > 0):
            rGroupGonggao[0] = int(rGroupGonggao[0])

        # 公告 = 世界公告;商会公告;系统提示
        rGonggao = get_str_from_sheet(sh, row, 8)
        gonggaos = []
        if (len(rGonggao) > 0):
            gonggaos = rGonggao.split(";")
            if (len(gonggaos) != 3):
                raise Exception("奖励公告格式错误")
            i = 0
            for gonggao in gonggaos:
                gonggaos[i] = gonggao.split(",")
                if len(gonggao) > 0:
                    gonggaos[i] = gonggao.split(",")
                    gonggaos[i][0] = int(gonggaos[i][0])
                else:
                    gonggaos[i] = []
                i += 1

        rMemo = get_str_from_sheet(sh, row, 10)
        rArgs = get_map_from_sheet(sh, row, 9)
        rCnd = ""

        if (rAmount != "" and not rAmount.isdigit()):
            funcName = u"CalcAmount%s" % no
            expTmp = parse_expr_right(rAmount, dicVar, 0, {})
            srcTmp = srcFuncTemplete % ("奖励数量计算函数", funcName, expTmp[1])

            srcFunction += srcTmp

            rAmount = "@@%s" % funcName
        else:
            if (rAmount == ""):
                rAmount = 0
            else:
                rAmount = int(rAmount)

        if (sh.ncols > 11):
            rCnd = get_str_from_sheet(sh, row, 11)
            if (len(rCnd)):
                funcName = u"Condition%s" % no

                expTmp = parse_expr_right(rCnd, dicVar, 0, {})
                srcTmp = srcFuncTemplete % (u"条件函数", funcName, expTmp[1])

                srcFunction += srcTmp

                rCnd = "@@%s" % funcName

        rewardData[no] = (rType, rName, rId, rAmount, rRate, gonggaos, rMemo,
                          rCnd, rGroupGonggao, rArgs)

    srcAll = strRewardTemplete % (srcAttr, srcFunction,
                                  PythonData2Lpc(rewardData, True, 2, 2))

    print(srcAll)
    output_file = outputpath + "%s.c" % rRewardId
    print(output_file)
    write_src(output_file, begin, end, srcAll, "utf-8")
예제 #24
0
def parse_xls(filename, parseAIFlg):

    ai_path = "data/ai/"

    try:
        # 打开excel文件
        book = xlrd.open_workbook(filename)
    except:
        msg = "can't open file?", filename
        print(msg, )
        usage()

        raise

    # 先处理变量表
    for x in xrange(book.nsheets):
        sh = book.sheet_by_index(x)
        sheetname = sh.name
        if sheetname == u"服务器端变量表":
            parse_var_sheet(sh, dicVar)
            break

    tbCondition = {}
    tbTarget = {}

    if parseAIFlg == u"1":
        #处理条件表
        for x in xrange(book.nsheets):
            sh = book.sheet_by_index(x)
            sheetname = sh.name
            if sheetname == u"条件":
                parse_condition_sheet(sh, tbCondition)
                break

        #解析目标
        for x in xrange(book.nsheets):
            sh = book.sheet_by_index(x)
            sheetname = sh.name
            if sheetname == u"目标":
                parse_target_sheet(sh, tbTarget, tbCondition)
                break

        #解析AI
        for x in xrange(book.nsheets):
            sh = book.sheet_by_index(x)
            sheetname = sh.name
            if sheetname == u"AI":
                #暂时屏蔽AI
                parse_ai_sheet(sh, ai_path, tbCondition, tbTarget)
                break

    formula = None
    hasPlot = False
    cehuaDecideWin = 0
    #for x in xrange(book.nsheets):
    #	sh = book.sheet_by_index(x)
    #	if sh.name == shname:
    #		tbAttr = {};
    #		#parse_fuben_sheet(sh, ai_path, tbAttr )
    # 遍历xls
    for x in xrange(book.nsheets):
        sh = book.sheet_by_index(x)
        sheetname = sh.name
        if sheetname == u"battle_scene":
            battle_id = common.get_str_from_sheet(sh, 0, 1)
            battle_type = common.get_str_from_sheet(sh, 0, 3)
            # 策划决定战斗胜利
            cehuaDecideWin = common.get_int_from_sheet(sh, 0, 5)
            # 玩家入场ai_list和x,y,dir
            player_ai_list = common.get_str_array_from_sheet(sh, 1, 1)
            player_x = common.get_int_from_sheet(sh, 1, 2)
            player_y = common.get_int_from_sheet(sh, 1, 3)
            player_dir = common.get_int_from_sheet(sh, 1, 4)
            target_dir = common.get_int_from_sheet(sh, 1, 5)
            scene_id = common.get_int_from_sheet(sh, 2, 1)
            # 场景AI
            scene_ai_list = common.get_str_array_from_sheet(sh, 2, 3)
            # 战斗时长
            fight_timeout = common.get_int_from_sheet(sh, 2, 5)
            reward = common.get_str_array_from_sheet(sh, 4, 1)
            level_type = common.get_int_from_sheet(sh, 4, 3)
            # 敌方入场数据
            scene_data, row_line = common.parse_table(sh, 5, 0)
            print "row_line:", row_line
            if (row_line == sh.nrows):
                continue
            # 公式数据
            srcTmp = common.get_str_from_sheet(sh, row_line, 0)

            # 寻找公式
            while srcTmp != u"公式" and row_line < sh.nrows:
                srcTmp = common.get_str_from_sheet(sh, row_line, 0)
                row_line = row_line + 1

            if (row_line == sh.nrows):
                continue
            # 公式数据
            formula, row_line = common.parse_table(sh, row_line, 0)

        if sheetname == u"ships":
            # 敌方入场数据
            ships, row_line = common.parse_table(sh, 0, 0)
        if sheetname == u"plot":
            hasPlot = True

    if (hasPlot):
        plotId = int(battle_id)
    else:
        plotId = 0

    if not scene_data:
        return

    srcAttribute = u''
    lstAttribute = []
    if player_ai_list and (len(player_ai_list) >= 1):
        lstAttribute.append(("str_array", u"玩家AI", "AI", player_ai_list))
    if scene_ai_list and (len(scene_ai_list) >= 1):
        lstAttribute.append(("str_array", u"场景AI", "SceneAI", scene_ai_list))
    # fight_timeout
    # FightTimeout
    if fight_timeout and ((fight_timeout) >= 60):
        lstAttribute.append(("int", u"战斗时长", "FightTimeout", fight_timeout))
    lstAttribute.append(("int", u"玩家X", "UserX", player_x))
    lstAttribute.append(("int", u"玩家Y", "UserY", player_y))
    lstAttribute.append(("int", u"玩家Dir", "UserDir", player_dir))
    lstAttribute.append(("int", u"舰队Dir", "FleetDir", target_dir))
    lstAttribute.append(("int", u"地图ID", "SceneId", scene_id))
    lstAttribute.append(("int", u"策划决定战斗胜利", "CehuaDecideWin", cehuaDecideWin))
    if level_type:
        lstAttribute.append(("int", u"等级类型", "LevelType", level_type))
    if reward and (len(reward) >= 1):
        lstAttribute.append(("str_array", u"奖励", "Reward", reward))

    if hasPlot:
        lstAttribute.append(("int", u"剧情ID", "PlotId", plotId))
    for attr in lstAttribute:
        type = attr[0]
        memo = attr[1]
        param = attr[2]
        value = attr[3]
        srcTmp = u''
        if type == "int":
            srcTmp = srcIntData % (memo, param, value)
        elif type == "str_array":
            srcTmp = srcData % (memo, param, PythonData2Lpc(value))

        srcAttribute += srcTmp

    baseName = dicBase[battle_type]
    srcFunctions = u""
    formulaResult = {}
    if formula:
        for k, v in formula.items():
            formula_name = "formula_%s" % k
            dicParam = {}
            exp = parse_expr_right(v["formula"], dicVar, 0, dicParam)
            #srcFunc = parse_function( v["formula"], formula_name, formula_name, dicVar, srcFormulaFunction )
            srcFunc = srcFormulaFunction % (v["memo"], formula_name, exp[0],
                                            v["formula"], exp[1])
            srcFunctions += srcFunc
            formulaResult[k] = u"@@%s" % formula_name

    for k, v in ships.items():
        for fk, fn in formulaResult.items():
            if v.has_key(fk):
                v[fk] = fn
    srcSceneData = srcSceneDataTemplete % (PythonData2Lpc(
        scene_data, True, 1, 1))
    srcShipData = srcShipDataTemplete % (PythonData2Lpc(ships, True, 1, 1))
    srcFightData = srcFightDataTemplete % (
        baseName, srcAttribute, srcFunctions, srcSceneData, srcShipData)

    srcPath = (dicFilePath[battle_type]) % (battle_id)

    print formula
    #TODO:输出scene_data,ships
    write_src(srcPath, begin, end, srcFightData, "utf-8")
    add_to_file("tmp/update_file.txt", srcPath)
예제 #25
0
def parse_skill_sheet(sh, output_path):
    #print( "xxxxxxxxxxxxxxxxxxxx\n", statusName2Id )
    statusStartCol = 26
    statusColCnt = 13
    # 导技能表
    # parseSkillTable
    for row in range(3, sh.nrows):
        skillId = get_str_from_sheet(sh, row, 0)
        srcSkill = u"""
#include <fight.h>

inherit SKILL_BASE;

#include <var_prop.h>
#include <user_key.h>
#include <skill.h>

"""
        skillFile = "module/skill/" + skillId + ".c"
        for col in range(0, statusStartCol - 1):
            headMemo = get_str_from_sheet(sh, 1, col)
            head = get_str_from_sheet(sh, 2, col)
            if (head not in parseSkillTable):
                continue
            type = parseSkillTable[head]["type"]
            name = parseSkillTable[head]["value_name"]

            templete = parseSkillTable[head]["templete"]
            print(headMemo, type, name, sh, row, col, templete)
            srcSkill += GetSrcByType(headMemo, type, name, sh, row, col,
                                     templete)

        statusIdx = 0
        allStatus = []
        # TODO:操作区解析
        for col in range(statusStartCol, sh.ncols, statusColCnt):
            head = get_str_from_sheet(sh, 2, col)

            # TODO:根据列名逐个获取内容

            curCol = col
            # 无法完整的读出一个状态
            if curCol + statusColCnt > sh.ncols:
                break
            # pre_actions
            curCol = curCol + 1
            # scope
            value = get_str_from_sheet(sh, row, curCol)
            print(head, value)

            if len(value) == 0:
                continue
            status = {}

            print(curCol, value)
            status["@@SCOPE"] = "@@" + value
            # sort_method
            curCol = curCol + 1
            value = get_str_from_sheet(sh, row, curCol)
            if (len(value) > 0):
                status["@@SORT_METHOD"] = "@@" + value
            # select_cnt
            curCol = curCol + 1
            value = get_str_from_sheet(sh, row, curCol)
            if "=" not in value:
                print row, col, value
                value = get_int_from_sheet(sh, row, curCol)
                status["@@SELECT_CNT"] = value
            else:
                funcName = "StatusSelectCnt%d" % (statusIdx)
                statusSelectCnt = parse_function(value, u"状态选择数量", funcName,
                                                 dicVar, srcSelectCntTemplete)
                srcSkill += statusSelectCnt
                status["@@SELECT_CNT"] = "@@" + funcName

            # TargetUnselectMain
            curCol = curCol + 1
            tmp = get_str_array_from_sheet(sh, row, curCol)
            for idx in range(len(tmp)):
                if (tmp[idx] in statusName2Id):
                    tmp[idx] = statusName2Id[tmp[idx]]
            value = tmp
            status["@@UNSELECT_MAIN"] = value
            # effect_name
            curCol = curCol + 1
            # effect_type
            curCol = curCol + 1
            # effect_time
            curCol = curCol + 1
            # StatusAdd
            curCol = curCol + 1
            value = get_str_from_sheet(sh, row, curCol)
            if (value in statusName2Id):
                value = statusName2Id[value]
            status["@@STATUS_ADD"] = value
            # status_duration
            curCol = curCol + 1
            value = get_str_from_sheet(sh, row, curCol)
            if (len(value) > 0):
                if "=" in value:
                    funcName = "StatusDuration%d" % (statusIdx)
                    statusDuration = parse_function(value, u"状态持续时间", funcName,
                                                    dicVar,
                                                    srcStatusRateTemplete)
                    srcSkill += statusDuration
                    status["@@STATUS_DURATION"] = "@@" + funcName
                elif "+" in value:
                    funcName = "StatusDuration%d" % (statusIdx)
                    statusDuration = parse_function(value, u"状态持续时间", funcName,
                                                    dicVar,
                                                    srcStatusDurationTemplete)
                    srcSkill += statusDuration
                    status["@@STATUS_DURATION"] = "@@" + funcName
                elif "/" in value:
                    funcName = "StatusDuration%d" % (statusIdx)
                    statusDuration = parse_function(value, u"状态持续时间", funcName,
                                                    dicVar,
                                                    srcStatusDurationTemplete)
                    srcSkill += statusDuration
                    status["@@STATUS_DURATION"] = "@@" + funcName
                else:
                    print value
                    status["@@STATUS_DURATION"] = get_int_from_sheet(
                        sh, row, curCol)
            # status_break
            curCol = curCol + 1
            value = get_str_from_sheet(sh, row, curCol)
            if (len(value) > 0):
                funcName = "StatusBreak%d" % (statusIdx)
                value = formla_int_to_float(value)
                statusBreak = parse_function(value, u"状态心跳时间", funcName,
                                             dicVar, srcStatusBreakTemplete)
                srcSkill += statusBreak
                status["@@STATUS_BREAK"] = "@@" + funcName
            # 命中率公式
            curCol = curCol + 1
            # skillSimpleFuncTemplete
            value = get_str_from_sheet(sh, row, curCol)
            funcName = "StatusRate%d" % (statusIdx)
            status["@@STATUS_RATE"] = "@@" + funcName
            # 生成函数,加入技能表中去
            statusRate = parse_function(value, u"状态命中", funcName, dicVar,
                                        srcStatusRateTemplete)
            srcSkill += statusRate
            # 处理过程
            curCol = curCol + 1
            value = get_str_from_sheet(sh, row, curCol)
            funcName = "StatusCalc%d" % (statusIdx)
            status["@@STATUS_CALCULATE"] = "@@" + funcName
            statusCalc = parse_function(value, u"状态结算", funcName, dicVar,
                                        srcStatusCalcTemplete)
            srcSkill += statusCalc

            print(status)
            allStatus.append(status)
            # 状态操作区+1
            statusIdx = statusIdx + 1

        # status
        srcSkill += u"""
mapping* allStatus = %s;
mapping* GetAllStatus()
{
    return allStatus;
}
""" % (PythonData2Lpc(allStatus, True, 0))

        # 非操作区的处理
        write_src(skillFile, begin, end, srcSkill, u"utf-8")

    pass
예제 #26
0
def parse_sailor_sheet(sh, output_path):
    startRow = get_int_from_sheet(sh, 3, 1) - 1
    headRow = startRow - 1
    print("startRow = %d" % startRow)
    print("headRow = %d" % headRow)

    for row in range(startRow, sh.nrows):
        roleId = get_str_from_sheet(sh, row, 0)
        baseVarList = []
        baseSrcLst = []
        intermediateList = []
        eliteSrcLst = []
        for col in range(0, sh.ncols):
            head = get_str_from_sheet(sh, headRow, col)
            if (len(head) == 0):
                continue
            data = get_str_from_sheet(sh, row, col)
            if (len(data) == 0):
                continue

            if (head == u"formula"):
                note = get_str_from_sheet(sh, headRow - 2, col)
                # TODO:打断公式取左值,看看是那种类型的变量
                eqCharIdx = data.find(u"=")
                #lrSplit = re.compile(u'[==]{1}')

                if eqCharIdx != -1:
                    lvalue = data[0:eqCharIdx]
                    lvalue = lvalue.strip()

                src = parse_function(data, note, "", dicVar, "\t// %s%s%s")
                if dicVar[lvalue]["var_type"] == u"人物基本属性":
                    baseSrcLst.append(src)
                if dicVar[lvalue]["var_type"] == u"人物精英属性":
                    eliteSrcLst.append(src)

                continue

            tmp = headExp.match(head)
            if tmp == None:
                continue

            var_name = tmp.group("var_name")
            var_type = tmp.group("var_type")

            baseFlag = 0
            intermediateFlag = 0
            intermediateVar = ""
            baseVar = ""
            if var_type == "intermediate":
                intermediateFlag = 1
                intermediateVar = int(data) / 100.0
            if var_type == "int":
                baseFlag = 1
                baseVar = int(data)
            if var_type == "string":
                baseFlag = 1
                baseVar = data
            if var_type == "array":
                baseFlag = 1
                baseVar = []
                tmpLst = data.split(",")
                for tmp in tmpLst:
                    baseVar.append(int(tmp))

            srcAttr = attrSrc % (var_name, PythonData2Lpc(baseVar))
            srcIntermediate = intermediateSrc % (
                var_name, PythonData2Lpc(intermediateVar))

            if baseFlag:
                baseVarList.append(srcAttr)
            if intermediateFlag:
                intermediateList.append(srcIntermediate)

        if roleId != "":
            filename = "%s/%s.c" % (output_path, roleId)
            filecontent = srcSailorTemplete % (
                u"\n".join(baseVarList),
                u"\n".join(intermediateList),
                u"\n".join(baseSrcLst),
                u"\n".join(eliteSrcLst),
            )
            try:
                src_data = open(filename, "rb").read()
                if len(src_data) == 0:
                    src_data = begin + "\n\n" + end
            except IOError:
                src_data = begin + "\n\n" + end

            tmp = p.sub(begin + "\n" + filecontent + "\n" + end, src_data)

            write_file(filename, tmp)