示例#1
0
文件: team.c 项目: rubenmit/hw
flib_team *flib_team_copy(const flib_team *team) {
    flib_team *result = NULL;
    if(team) {
        flib_team *tmpTeam = flib_calloc(1, sizeof(flib_team));
        if(tmpTeam) {
            bool error = false;

            for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
                tmpTeam->hogs[i].name = strdupWithError(team->hogs[i].name, &error);
                tmpTeam->hogs[i].hat = strdupWithError(team->hogs[i].hat, &error);
                tmpTeam->hogs[i].rounds = team->hogs[i].rounds;
                tmpTeam->hogs[i].kills = team->hogs[i].kills;
                tmpTeam->hogs[i].deaths = team->hogs[i].deaths;
                tmpTeam->hogs[i].suicides = team->hogs[i].suicides;
                tmpTeam->hogs[i].difficulty = team->hogs[i].difficulty;
                tmpTeam->hogs[i].initialHealth = team->hogs[i].initialHealth;
                tmpTeam->hogs[i].weaponset = flib_weaponset_copy(team->hogs[i].weaponset);
                if(team->hogs[i].weaponset && !tmpTeam->hogs[i].weaponset) {
                    error = true;
                }
            }

            tmpTeam->name = strdupWithError(team->name, &error);
            tmpTeam->grave = strdupWithError(team->grave, &error);
            tmpTeam->fort = strdupWithError(team->fort, &error);
            tmpTeam->voicepack = strdupWithError(team->voicepack, &error);
            tmpTeam->flag = strdupWithError(team->flag, &error);
            tmpTeam->ownerName = strdupWithError(team->ownerName, &error);

            tmpTeam->bindingCount = team->bindingCount;
            if(team->bindings) {
                tmpTeam->bindings = flib_calloc(team->bindingCount, sizeof(flib_binding));
                if(tmpTeam->bindings) {
                    for(int i=0; i<tmpTeam->bindingCount; i++) {
                        tmpTeam->bindings[i].action = strdupWithError(team->bindings[i].action, &error);
                        tmpTeam->bindings[i].binding = strdupWithError(team->bindings[i].binding, &error);
                    }
                } else {
                    error = true;
                }
            }

            tmpTeam->rounds = team->rounds;
            tmpTeam->wins = team->wins;
            tmpTeam->campaignProgress = team->campaignProgress;

            tmpTeam->colorIndex = team->colorIndex;
            tmpTeam->hogsInGame = team->hogsInGame;
            tmpTeam->remoteDriven = team->remoteDriven;

            if(!error) {
                result = tmpTeam;
                tmpTeam = 0;
            }
        }
        flib_team_destroy(tmpTeam);
    }
    return result;
}
示例#2
0
void flib_teamlist_destroy(flib_teamlist *list) {
	if(list) {
		for(int i=0; i<list->teamCount; i++) {
			flib_team_destroy(list->teams[i]);
		}
		free(list->teams);
		free(list);
	}
}
示例#3
0
void flib_teamlist_clear(flib_teamlist *list) {
	if(!log_badargs_if(list==NULL)) {
		for(int i=0; i<list->teamCount; i++) {
			flib_team_destroy(list->teams[i]);
		}
		free(list->teams);
		list->teams = NULL;
		list->teamCount = 0;
	}
}
示例#4
0
文件: netprotocol.c 项目: CaF2/hw
flib_team *flib_team_from_netmsg(char **parts) {
    flib_team *result = NULL;
    flib_team *tmpTeam = flib_calloc(1, sizeof(flib_team));
    if(tmpTeam) {
        if(!fillTeamFromMsg(tmpTeam, parts)) {
            result = tmpTeam;
            tmpTeam = NULL;
        } else {
            flib_log_e("Error parsing team from net.");
        }
    }
    flib_team_destroy(tmpTeam);
    return result;
}
示例#5
0
int flib_teamlist_delete(flib_teamlist *list, const char *name) {
	int result = -1;
	if(!log_badargs_if2(list==NULL, name==NULL)) {
		int itemid = findTeam(list, name);
		if(itemid>=0) {
			flib_team *team = list->teams[itemid];
			if(!deleteTeam(&list->teams, &list->teamCount, itemid)) {
				flib_team_destroy(team);
				result = 0;
			}
		}
	}
	return result;
}
示例#6
0
flib_teamlist *flib_teamlist_copy(flib_teamlist *list) {
	if(!list) {
		return NULL;
	}
	flib_teamlist *result = flib_teamlist_create();
	if(result) {
		bool error = false;
		for(int i=0; !error && i<list->teamCount; i++) {
			flib_team *teamcopy = flib_team_copy(list->teams[i]);
			if(!teamcopy || flib_teamlist_insert(result, teamcopy, i)) {
				flib_team_destroy(teamcopy);
				error = true;
			}
		}
		if(error) {
			flib_teamlist_destroy(result);
			result = NULL;
		}
	}
	return result;
}
示例#7
0
文件: team.c 项目: rubenmit/hw
static flib_team *from_ini_handleError(flib_team *result, flib_ini *settingfile) {
    flib_ini_destroy(settingfile);
    flib_team_destroy(result);
    return NULL;
}