?? item_gen.c
字號:
/*********************************************** * 失奶 丞寧岳″ **********************************************/#include "version.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <strings.h>#include <errno.h>#include <ctype.h>#include <math.h>#include "configfile.h"#include "util.h"#include "buf.h"#include "char.h"#include "item.h"#include "item_gen.h"#include "enemy.h"#include "log.h"#include "saacproto_cli.h"#include "family.h"#include "magic_base.h"#define DEBUGPRINT 0#define DEBUGPRINT_DETAIL 0// shan begin#define FOOD_HP_RATE 200#define FOOD_MP_RATE 200#define FOOD_SUCCESS_RATE 150#define FOOD_TURN_ADDPOINT 1// shan endstatic int ITEM_getTableNum( int num);/* 豳箋及襖及MAX襖 */#define ITEM_ATOMIND_MAX 1000// shan add#define ITEM_ATOMIND_FM_MAX 4000#define ITEM_RANDRANGEDOM 1000#ifdef _MERGE_NEW_8 // 1st#define ITEM_RANDRANGEDOM_BASE 600#else#define ITEM_RANDRANGEDOM_BASE 0#endif// shan add#define ITEM_FM_RANDRANGEDOM 4000/*********************************************** * (ITEM_GEN_RAND_MIN/1000) * ITEN_GEN_SEARCH_MIN * - (ITEM_GEN_RAND_MAX/1000) * ITEN_GEN_SEARCH_MAX * 仇木分仃及汔及豳箋及 區毛潸曰丹月儀卞卅月[ **********************************************//* 豳箋及襖 及仿件母丞汔及 劑午 ㄠㄟㄟㄟ坌 */#define ITEM_GEN_RAND_MIN 700#define ITEM_GEN_RAND_MAX 1200/* 失奶 丞毛腹綢允月豳箋及襖及汔及 劑午 及 (double) */#define ITEN_GEN_SEARCH_MIN (0.7)#define ITEN_GEN_SEARCH_MAX (1.10)static struct tagItemSearchRangeTable { double searchmin; double searchmax;}ItemSearchTable[2] = {// { 0.7, 1.1},// shan add// { 0.7, 1.3},// { 0.5, 1.5} { 0.8, 1.2}, { 0.7, 1.3} };static struct tagItemRandRangeTable { int randmin; int randmax;}ItemRandTable[2] = {// { 700, 1200}, { 700, 1300}, { 900, 1100}};#define ITEM_GEN_RATE 0.7static struct _tagItemRandRangeTableForItem { int num; /* 豳箋及備仿件弁及湘 襖 */ int minnum; /* 仿件弁 潸曰丹月襖及Min */ int maxnum; /* 仿件弁 潸曰丹月襖及MAX num +戚及仿件弁及犒*ITEM_GEN_RATE) */ double rate; /* maxnum / num*/}ItemRandTableForItem[] = { { 10, 0,0,0 }, { 30, 0,0,0 }, { 65, 0,0,0 }, { 125, 0,0,0 }, { 205, 0,0,0 }, { 305, 0,0,0 }, { 425, 0,0,0 }, { 565, 0,0,0 }, { 725, 0,0,0 }, { 905, 0,0,0 }, { 1125, 0,0,0 }, // shan add { 1354, 0,0,0 }, { 1594, 0,0,0 }, { 1825, 0,0,0 }, { 2105, 0,0,0 }, { 2405, 0,0,0 }, { 2725, 0,0,0 }, { 3065, 0,0,0 }, { 3425, 0,0,0 }, { 3805, 0,0,0 }};#define ATOM_LEVEL_MAX 16struct item_atom{ char name[32]; unsigned int name_hash; int magicflg;};struct item_atom *item_atoms;int item_atoms_size;#define MAX_ITEM_ATOMS_SIZE 256struct item_ingindtable { double data[MAX_ITEM_ATOMS_SIZE]; int index; int num;};static int ITEM_getAtomIndexByName( char *nm ) // 從素材名稱取得素材index{ int i; unsigned int h = hashpjw( nm ); for( i = 0; i < item_atoms_size; i ++ ){ if( item_atoms[i].name_hash == h && strcmp( item_atoms[i].name, nm) == 0 ){ return i; } } return -1;}#ifdef _ITEMTBL_STAICextern ITEM_table ITEM_tbl[28000];#elseextern ITEM_table *ITEM_tbl;#endifstruct ingcache{ int use;#define MAXING_ONE 5 int inguse; int canmergefrom; int canmergeto; int hitnum; int ingind[MAXING_ONE]; int ingval[MAXING_ONE];};int ITEM_initRandTable( void){ int i; for( i = 0; i < arraysizeof( ItemRandTableForItem); i ++) { if( i == 0 ) ItemRandTableForItem[i].minnum = 0; else { ItemRandTableForItem[i].minnum = ItemRandTableForItem[i-1].maxnum+1; } if( i + 1 != arraysizeof( ItemRandTableForItem)) { ItemRandTableForItem[i].maxnum = ItemRandTableForItem[i].num + (ItemRandTableForItem[i+1].num - ItemRandTableForItem[i].num) *ITEM_GEN_RATE; } else { // shan add ItemRandTableForItem[i].maxnum = 4000; //ItemRandTableForItem[i].maxnum = 1000; } ItemRandTableForItem[i].rate = ItemRandTableForItem[i].maxnum / (double)ItemRandTableForItem[i].num; } /*for( i = 0; i < arraysizeof( ItemRandTableForItem); i ++) { print( "\ntable num:[%d] min:[%d] max:[%d] rate:[%3.3f] ", ItemRandTableForItem[i].num, ItemRandTableForItem[i].minnum, ItemRandTableForItem[i].maxnum, ItemRandTableForItem[i].rate); }*/ return TRUE;}static struct ingcache *icache;int icache_num;#ifdef _IMPOROVE_ITEMTABLEint ADD_ICACHE_INGRED( int ItemID){ char *itemarg; int i, nk=0; for( i=0; i<5; i++){ itemarg = ITEMTBL_getChar( ItemID, ITEM_INGNAME0+i);//成分名 if( itemarg == NULL ) continue; if( itemarg[0] ){ icache[ItemID].ingind[nk] = ITEM_getAtomIndexByName( itemarg); if( icache[ItemID].ingind[nk] < 0 ){ print( "fuck ing[%s][%d] for %d %s\n", itemarg, ITEMTBL_getInt( ItemID, ITEM_INGVALUE0+i), ITEMTBL_getInt( ItemID, ITEM_ID), ITEMTBL_getChar( ItemID, ITEM_NAME) ); }else { icache[ItemID].ingval[nk] = ITEMTBL_getInt( ItemID, ITEM_INGVALUE0+i); nk++; } } } return nk;}int ITEM_initItemIngCache( void ){ int i; print ( "初始化物品緩沖: 最大ID數:%d\n", ITEM_getItemMaxIdNum( ) ); icache_num = ITEM_getMaxitemtblsFromTransList( ); icache = allocateMemory( sizeof( struct ingcache ) * icache_num ); if( icache == NULL ){ print( "初始化物品緩沖: 沒有物品\n" ); return FALSE; } print( "初始化物品緩沖: 讀取物品數=%d\n", icache_num); remove( "icache.txt"); memset( icache, 0, icache_num * sizeof( struct ingcache) ); for( i=0; i<icache_num; i++){ if( ITEM_CHECKITEMTABLE( i) ){ icache[i].inguse = ADD_ICACHE_INGRED( i); if( icache[i].inguse == 0 ){ if( ITEMTBL_getInt( i, ITEM_CANMERGEFROM ) == TRUE || ITEMTBL_getInt( i, ITEM_CANMERGETO ) == TRUE ){ print( "道具 沒設定成份:%d %d %s\n", i, ITEMTBL_getInt( i, ITEM_ID), ITEMTBL_getChar( i, ITEM_NAME) ); } }else{ FILE *fp; icache[i].use = 1; icache[i].canmergefrom = ITEMTBL_getInt( i, ITEM_CANMERGEFROM ); icache[i].canmergeto = ITEMTBL_getInt( i, ITEM_CANMERGETO ); if( (fp = fopen( "icache.txt", "a+")) != NULL ){ fprintf( fp, "icache %4d %4d [%s] \t- %s %s %s %s %s\n", i, ITEMTBL_getInt( i, ITEM_ID), ITEMTBL_getChar( i, ITEM_NAME), ITEMTBL_getChar( i, ITEM_INGNAME0), ITEMTBL_getChar( i, ITEM_INGNAME1), ITEMTBL_getChar( i, ITEM_INGNAME2), ITEMTBL_getChar( i, ITEM_INGNAME3), ITEMTBL_getChar( i, ITEM_INGNAME4) ); fclose( fp); }else { print("Can't a+ %s!!\n", "icache.txt"); } } } } return TRUE;}#elseint ITEM_initItemIngCache( void ){ int i; print ( "\n初始化物品緩沖: 物品最大數:%d ", ITEM_getItemMaxIdNum() ); icache_num = ITEM_getItemMaxIdNum( ); print(" 緩沖數:%d ", icache_num); icache = allocateMemory( sizeof( struct ingcache ) * icache_num ); if( icache == NULL ){ print( "初始化物品緩沖: 沒有物品\n" ); return FALSE; } remove( "old_icache.txt"); memset( icache, 0, icache_num * sizeof( struct ingcache) ); for( i=0; i<icache_num; i++){ if( ITEM_tbl[i].use ){ //new int k=0;#define ADD_ICACHE_INGRED( nm, vl ) if( ITEM_tbl[i].itm.string[nm].string[0] ){icache[i].ingind[k] = ITEM_getAtomIndexByName(ITEM_tbl[i].itm.string[nm].string );if( icache[i].ingind[k] < 0 ){print( "fuck ing[%s][%d] for %d %s\n", ITEM_tbl[i].itm.string[nm].string,ITEM_tbl[i].itm.data[vl], ITEM_tbl[i].itm.data[ITEM_ID], ITEM_tbl[i].itm.string[ITEM_NAME].string );}else {icache[i].ingval[k] = ITEM_tbl[i].itm.data[vl];k++;}} ADD_ICACHE_INGRED( ITEM_INGNAME0, ITEM_INGVALUE0 ); ADD_ICACHE_INGRED( ITEM_INGNAME1, ITEM_INGVALUE1 ); ADD_ICACHE_INGRED( ITEM_INGNAME2, ITEM_INGVALUE2 ); ADD_ICACHE_INGRED( ITEM_INGNAME3, ITEM_INGVALUE3 ); ADD_ICACHE_INGRED( ITEM_INGNAME4, ITEM_INGVALUE4 ); icache[i].inguse = k; if( k == 0 ){ if( ITEM_tbl[i].itm.data[ITEM_CANMERGEFROM] == TRUE || //new ITEM_tbl[i].itm.data[ITEM_CANMERGETO] == TRUE){//new print( "ID%d (%s)尚未設定成分\n", ITEM_tbl[i].itm.data[ITEM_ID], //new ITEM_tbl[i].itm.string[ITEM_NAME].string ); //new } }else{ FILE *fp; icache[i].use = 1; icache[i].canmergefrom = ITEM_tbl[i].itm.data[ITEM_CANMERGEFROM]; //new icache[i].canmergeto = ITEM_tbl[i].itm.data[ITEM_CANMERGETO]; //new if( (fp = fopen( "old_icache.txt", "a+")) != NULL ){ fprintf( fp, "icache %4d %4d [%s] \t- %s %s %s %s %s\n", i, ITEMTBL_getInt( i, ITEM_ID), ITEMTBL_getChar( i, ITEM_NAME), ITEMTBL_getChar( i, ITEM_INGNAME0), ITEMTBL_getChar( i, ITEM_INGNAME1), ITEMTBL_getChar( i, ITEM_INGNAME2), ITEMTBL_getChar( i, ITEM_INGNAME3), ITEMTBL_getChar( i, ITEM_INGNAME4) ); fclose( fp); } } } } return TRUE;}#endifint ITEM_initItemAtom( char *fn ){ FILE *fp; int count=0; fp = fopen( fn , "r" ); if( fp == NULL ){ print( "打開文件失敗 %s\n", fn ); return FALSE; } fseek( fp, 0, SEEK_SET ); while(1){ char line[16384]; if( fgets( line, sizeof( line ), fp ) == NULL )break; if( line[0] != '#' && line[0] != '\n' )count++; } print( "初始化物品成份: 總數 %d \n", count ); if( count == 0 ){ print( "初始化物品成份: 無法正確設置物品成份. 異常中斷.\n" ); return FALSE; } /* malloc. */ item_atoms = ( struct item_atom * ) allocateMemory( count * sizeof( struct item_atom )); if( item_atoms == NULL ){ print( "分配內存失敗\n" ); return FALSE; } memset( item_atoms, 0 , count * sizeof( struct item_atom)); fseek( fp , 0 , SEEK_SET ); count = 0; while(1){ char line[16384], tk[1024]; if( fgets( line, sizeof( line ) , fp ) == NULL )break; /* chop */ line[strlen(line)-1]=0; /* 爾羹卞煙讓及 蟆互 賄匹反中勻化中化} 公木分仃互 邰 */ getStringFromIndexWithDelim( line, "," , 1 , tk, sizeof( tk )); snprintf( item_atoms[count].name, sizeof( item_atoms[count].name ), "%s", tk ); item_atoms[count].name_hash = hashpjw( tk ); getStringFromIndexWithDelim( line, "," , 2 , tk, sizeof( tk )); item_atoms[count].magicflg = isstring1or0( tk); // CoolFish: 2001/6/28 // print( "atom [%s][%d] %d\n", item_atoms[count].name, // item_atoms[count].magicflg, count ); count++; } fclose(fp); if( count >= MAX_ITEM_ATOMS_SIZE ){ print( "初始化物品成份: 物品成份太多了\n" ); return FALSE; } item_atoms_size = count; print( "初始化物品成份: 讀取 %d 物品成份...", count ); return TRUE;}/* 剄醒及伊□玄 base 互 100 匹 min 互 0.7 匹 max 互 1.3 分勻兇日} 70 ~ 130 卞剽域卞坌 允月[午曰丐尹內剽域[ 剽域元扎卅仁仄兇曰允月井手仄木卅中及匹} 失奶 丞毀迕伙□民件午仄化仇仇卞爛聒允月 by ringo 1999Oct1 1000坌及min_rate,max_rate匹健丹[ double 支float 反]支支仇仄中及匹銀歹卅中[ */static intITEM_randRange( int base, int min_rate , int max_rate ){ int minnum; int maxnum; int range;#ifdef _MERGE_LOG print("\n物品隊列(基本:%d, 最小價格%d, 最大價格:%d) ", base, min_rate, max_rate);#endif if( min_rate > max_rate) { int tmp; tmp = min_rate; min_rate = max_rate; max_rate = tmp; } minnum = rint((double)base / ITEM_RANDRANGEDOM * min_rate); maxnum = rint((double)base / ITEM_RANDRANGEDOM * max_rate); range = ( maxnum - minnum ); if( min_rate == max_rate && min_rate == 0 ) return 0; if( range == 0 ) return base; if( range < 0 ) return 0;#ifdef _MERGE_LOG print("\n最後下限:%d 最後上限:%d ", minnum, minnum+range);#endif return minnum + RAND( 0, range);}typedef int (*FUNC)( const void *, const void * );static int cmprutine( double *p1, double *p2){ if( *p1 < *p2 ) return -1; if( *p1 > *p2 ) return 1; return 0;}/* * 嫖中及卞丐歹六月 * 忒曰襖反 互中仁勾卞卅勻兇井[ * 寧歹六月蟆卞]末□玄仄化岈屯化] * table卞梯勻兇 坌]簫仄化中仁[ */static void ITEM_simplify_atoms( struct item_ingindtable *inds, int num, int *retinds, int *retvals, int petindex, int alchemist){ //int newinds[MAX_ITEM_ATOMS_SIZE];
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -