Advertisement
Guest User

Daegaladh

a guest
Jun 26th, 2012
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Index: status.c
  3. ===================================================================
  4. --- status.c    (revision 16347)
  5. +++ status.c    (working copy)
  6. @@ -49,10 +49,9 @@
  7.  };
  8.  
  9.  static int max_weight_base[CLASS_COUNT];
  10. -static int hp_coefficient[CLASS_COUNT];
  11. -static int hp_coefficient2[CLASS_COUNT];
  12. -static int hp_sigma_val[CLASS_COUNT][MAX_LEVEL+1];
  13. -static int sp_coefficient[CLASS_COUNT];
  14. +static unsigned int hp_table[CLASS_COUNT][MAX_LEVEL];
  15. +static unsigned int sp_table[CLASS_COUNT][MAX_LEVEL];
  16. +static unsigned int max_level[CLASS_COUNT];
  17.  static int aspd_base[CLASS_COUNT][MAX_WEAPON_TYPE];    //[blackhole89]
  18.  
  19.  // bonus values and upgrade chances for refining equipment
  20. @@ -2150,39 +2149,12 @@
  21.     return 1;
  22.  }
  23.  
  24. -/// Helper function for status_base_pc_maxhp(), used to pre-calculate the hp_sigma_val[] array
  25. -static void status_calc_sigma(void)
  26. -{
  27. -   int i,j;
  28. -
  29. -   for(i = 0; i < CLASS_COUNT; i++)
  30. -   {
  31. -       unsigned int k = 0;
  32. -       hp_sigma_val[i][0] = hp_sigma_val[i][1] = 0;
  33. -       for(j = 2; j <= MAX_LEVEL; j++)
  34. -       {
  35. -           k += (hp_coefficient[i]*j + 50) / 100;
  36. -           hp_sigma_val[i][j] = k;
  37. -           if (k >= INT_MAX)
  38. -               break; //Overflow protection. [Skotlex]
  39. -       }
  40. -       for(; j <= MAX_LEVEL; j++)
  41. -           hp_sigma_val[i][j] = INT_MAX;
  42. -   }
  43. -}
  44. -
  45. -/// Calculates base MaxHP value according to class and base level
  46. -/// The recursive equation used to calculate level bonus is (using integer operations)
  47. -///    f(0) = 35 | f(x+1) = f(x) + A + (x + B)*C/D
  48. -/// which reduces to something close to
  49. -///    f(x) = 35 + x*(A + B*C/D) + sum(i=2..x){ i*C/D }
  50. +//Calculate maxHP from tables
  51.  static unsigned int status_base_pc_maxhp(struct map_session_data* sd, struct status_data* status)
  52.  {
  53. -   unsigned int val = pc_class2idx(sd->status.class_);
  54. -   val = 35 + sd->status.base_level*hp_coefficient2[val]/100 + hp_sigma_val[val][sd->status.base_level];
  55. +   unsigned int val;
  56. +   val = hp_table[pc_class2idx(sd->status.class_)][sd->status.base_level-1];
  57.  
  58. -   if((sd->class_&MAPID_UPPERMASK) == MAPID_NINJA || (sd->class_&MAPID_UPPERMASK) == MAPID_GUNSLINGER)
  59. -       val += 100; //Since their HP can't be approximated well enough without this.
  60.     if((sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON && sd->status.base_level >= 90 && pc_famerank(sd->status.char_id, MAPID_TAEKWON))
  61.         val *= 3; //Triple max HP for top ranking Taekwons over level 90.
  62.     if((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->status.base_level >= 99)
  63. @@ -2197,11 +2169,11 @@
  64.     return val;
  65.  }
  66.  
  67. +//Calculate maxSP from tables
  68.  static unsigned int status_base_pc_maxsp(struct map_session_data* sd, struct status_data *status)
  69.  {
  70.     unsigned int val;
  71. -
  72. -   val = 10 + sd->status.base_level*sp_coefficient[pc_class2idx(sd->status.class_)]/100;
  73. +   val = sp_table[pc_class2idx(sd->status.class_)][sd->status.base_level-1];
  74.     val += val * status->int_/100;
  75.  
  76.     if (sd->class_&JOBL_UPPER)
  77. @@ -10385,7 +10357,7 @@
  78.  
  79.  /*------------------------------------------
  80.   * DB reading.
  81. - * job_db1.txt    - weight, hp, sp, aspd
  82. + * job_db1.txt    - weight, aspd
  83.   * job_db2.txt    - job level stat bonuses
  84.   * size_fix.txt   - size adjustment table for weapons
  85.   * refine_db.txt  - refining data table
  86. @@ -10411,7 +10383,7 @@
  87.  #endif
  88.  
  89.  static bool status_readdb_job1(char* fields[], int columns, int current)
  90. -{// Job-specific values (weight, HP, SP, ASPD)
  91. +{// Job-specific values (weight, ASPD)
  92.     int idx, class_;
  93.     unsigned int i;
  94.  
  95. @@ -10425,13 +10397,10 @@
  96.     idx = pc_class2idx(class_);
  97.  
  98.     max_weight_base[idx] = atoi(fields[1]);
  99. -   hp_coefficient[idx]  = atoi(fields[2]);
  100. -   hp_coefficient2[idx] = atoi(fields[3]);
  101. -   sp_coefficient[idx]  = atoi(fields[4]);
  102.  
  103.     for(i = 0; i < MAX_WEAPON_TYPE; i++)
  104.     {
  105. -       aspd_base[idx][i] = atoi(fields[i+5]);
  106. +       aspd_base[idx][i] = atoi(fields[i+2]);
  107.     }
  108.     return true;
  109.  }
  110. @@ -10504,15 +10473,14 @@
  111.  int status_readdb(void)
  112.  {
  113.     int i, j;
  114. +   FILE *fp;
  115. +   char line[25000];
  116.  
  117.     // initialize databases to default
  118.     //
  119.  
  120.     // job_db1.txt
  121.     memset(max_weight_base, 0, sizeof(max_weight_base));
  122. -   memset(hp_coefficient, 0, sizeof(hp_coefficient));
  123. -   memset(hp_coefficient2, 0, sizeof(hp_coefficient2));
  124. -   memset(sp_coefficient, 0, sizeof(sp_coefficient));
  125.     memset(aspd_base, 0, sizeof(aspd_base));
  126.  #ifdef RENEWAL
  127.     memset(re_job_db, 0, sizeof(re_job_db));
  128. @@ -10539,7 +10507,7 @@
  129.     // read databases
  130.     //
  131.  
  132. -   sv_readdb(db_path, "job_db1.txt",   ',', 5+MAX_WEAPON_TYPE, 5+MAX_WEAPON_TYPE, -1,                            &status_readdb_job1);
  133. +   sv_readdb(db_path, "job_db1.txt",   ',', 2+MAX_WEAPON_TYPE, 2+MAX_WEAPON_TYPE, -1,                            &status_readdb_job1);
  134.     sv_readdb(db_path, "job_db2.txt",   ',', 1,                 1+MAX_LEVEL,       -1,                            &status_readdb_job2);
  135.     sv_readdb(db_path, "size_fix.txt",  ',', MAX_WEAPON_TYPE,   MAX_WEAPON_TYPE,    ARRAYLENGTH(atkmods),         &status_readdb_sizefix);
  136.  #ifdef RENEWAL
  137. @@ -10547,6 +10515,142 @@
  138.  #endif
  139.     sv_readdb(db_path, DBPATH"refine_db.txt", ',', 4+MAX_REFINE, 4+MAX_REFINE, ARRAYLENGTH(refine_info), &status_readdb_refine);
  140.  
  141. +   // job_maxhp.txt
  142. +   memset(hp_table,0,sizeof(hp_table));
  143. +   memset(max_level,0,sizeof(max_level));
  144. +   sprintf(line, "%s/job_maxhp.txt", db_path);
  145. +   fp=fopen(line, "r");
  146. +   if(fp==NULL){
  147. +       ShowError("can't read %s\n", line);
  148. +       return 1;
  149. +   }
  150. +   while(fgets(line, sizeof(line), fp))
  151. +   {
  152. +       int jobs[CLASS_COUNT], job_count, job, job_id;
  153. +       unsigned int ui,maxlv;
  154. +       char *split[3];
  155. +       if(line[0]=='/' && line[1]=='/')
  156. +           continue;
  157. +       if (pc_split_str(line,split,3) < 3)
  158. +           continue;
  159. +      
  160. +       job_count = pc_split_atoi(split[1],jobs,':',CLASS_COUNT);
  161. +       if (job_count < 1)
  162. +           continue;
  163. +       job_id = jobs[0];
  164. +       if (!pcdb_checkid(job_id)) {
  165. +           ShowError("status_readdb: Invalid job ID %d.\n", job_id);
  166. +           continue;
  167. +       }
  168. +       maxlv = atoi(split[0]);
  169. +       if (maxlv > MAX_LEVEL) {
  170. +           ShowWarning("status_readdb: Specified max level %u for job %d is beyond server's limit (%u).\n ", maxlv, job_id, MAX_LEVEL);
  171. +           maxlv = MAX_LEVEL;
  172. +       }
  173. +      
  174. +       job = jobs[0] = pc_class2idx(job_id);
  175. +       max_level[job] = pc_split_atoui(split[2], hp_table[job],',',maxlv)+1;
  176. +       while ((ui = max_level[job]) >= 2 && hp_table[job][ui-2] <= 0)
  177. +           max_level[job]--;
  178. +       if (max_level[job] < maxlv) {
  179. +           ShowWarning("status_readdb: Specified max %u for job %d, but that job's hp table only goes up to level %u.\n", maxlv, job_id, max_level[job]);
  180. +           ShowInfo("Filling the missing values with the last hp entry.\n");
  181. +           ui = (max_level[job] <= 2? 0: max_level[job]-2);
  182. +           for (; ui+2 < maxlv; ui++)
  183. +               hp_table[job][ui] = hp_table[job][ui-1];
  184. +           max_level[job] = maxlv;
  185. +       }
  186. +
  187. +       for (i = 1; i < job_count; i++) {
  188. +           job_id = jobs[i];
  189. +           if (!pcdb_checkid(job_id)) {
  190. +               ShowError("status_readdb: Invalid job ID %d.\n", job_id);
  191. +               continue;
  192. +           }
  193. +           job = pc_class2idx(job_id);
  194. +           memcpy(hp_table[job], hp_table[jobs[0]], sizeof(hp_table[0]));
  195. +           max_level[job] = maxlv;
  196. +       }
  197. +   }
  198. +   fclose(fp);
  199. +   for (i = 0; i < JOB_MAX; i++) {
  200. +       if (!pcdb_checkid(i)) continue;
  201. +       if (i == JOB_WEDDING || i == JOB_XMAS || i == JOB_SUMMER)
  202. +           continue;
  203. +       j = pc_class2idx(i);
  204. +       if (!max_level[j])
  205. +           ShowWarning("Class %s (%d) does not has a base hp table.\n", job_name(i), i);
  206. +   }
  207. +   ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","job_maxhp.txt");
  208. +
  209. +   // job_maxsp.txt
  210. +   memset(sp_table,0,sizeof(sp_table));
  211. +   memset(max_level,0,sizeof(max_level));
  212. +   sprintf(line, "%s/job_maxsp.txt", db_path);
  213. +   fp=fopen(line, "r");
  214. +   if(fp==NULL){
  215. +       ShowError("can't read %s\n", line);
  216. +       return 1;
  217. +   }
  218. +   while(fgets(line, sizeof(line), fp))
  219. +   {
  220. +       int jobs[CLASS_COUNT], job_count, job, job_id;
  221. +       unsigned int ui,maxlv;
  222. +       char *split[3];
  223. +       if(line[0]=='/' && line[1]=='/')
  224. +           continue;
  225. +       if (pc_split_str(line,split,3) < 3)
  226. +           continue;
  227. +      
  228. +       job_count = pc_split_atoi(split[1],jobs,':',CLASS_COUNT);
  229. +       if (job_count < 1)
  230. +           continue;
  231. +       job_id = jobs[0];
  232. +       if (!pcdb_checkid(job_id)) {
  233. +           ShowError("status_readdb: Invalid job ID %d.\n", job_id);
  234. +           continue;
  235. +       }
  236. +       maxlv = atoi(split[0]);
  237. +       if (maxlv > MAX_LEVEL) {
  238. +           ShowWarning("status_readdb: Specified max level %u for job %d is beyond server's limit (%u).\n ", maxlv, job_id, MAX_LEVEL);
  239. +           maxlv = MAX_LEVEL;
  240. +       }
  241. +      
  242. +       job = jobs[0] = pc_class2idx(job_id);
  243. +       max_level[job] = pc_split_atoui(split[2], sp_table[job],',',maxlv)+1;
  244. +       while ((ui = max_level[job]) >= 2 && sp_table[job][ui-2] <= 0)
  245. +           max_level[job]--;
  246. +       if (max_level[job] < maxlv) {
  247. +           ShowWarning("status_readdb: Specified max %u for job %d, but that job's sp table only goes up to level %u.\n", maxlv, job_id, max_level[job]);
  248. +           ShowInfo("Filling the missing values with the last sp entry.\n");
  249. +           ui = (max_level[job] <= 2? 0: max_level[job]-2);
  250. +           for (; ui+2 < maxlv; ui++)
  251. +               sp_table[job][ui] = sp_table[job][ui-1];
  252. +           max_level[job] = maxlv;
  253. +       }
  254. +
  255. +       for (i = 1; i < job_count; i++) {
  256. +           job_id = jobs[i];
  257. +           if (!pcdb_checkid(job_id)) {
  258. +               ShowError("status_readdb: Invalid job ID %d.\n", job_id);
  259. +               continue;
  260. +           }
  261. +           job = pc_class2idx(job_id);
  262. +           memcpy(sp_table[job], sp_table[jobs[0]], sizeof(sp_table[0]));
  263. +           max_level[job] = maxlv;
  264. +       }
  265. +   }
  266. +   fclose(fp);
  267. +   for (i = 0; i < JOB_MAX; i++) {
  268. +       if (!pcdb_checkid(i)) continue;
  269. +       if (i == JOB_WEDDING || i == JOB_XMAS || i == JOB_SUMMER)
  270. +           continue;
  271. +       j = pc_class2idx(i);
  272. +       if (!max_level[j])
  273. +           ShowWarning("Class %s (%d) does not has a base sp table.\n", job_name(i), i);
  274. +   }
  275. +   ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","job_maxsp.txt");
  276. +
  277.     return 0;
  278.  }
  279.  
  280. @@ -10561,7 +10665,6 @@
  281.     initChangeTables();
  282.     initDummyData();
  283.     status_readdb();
  284. -   status_calc_sigma();
  285.     natural_heal_prev_tick = gettick();
  286.     sc_data_ers = ers_new(sizeof(struct status_change_entry));
  287.     add_timer_interval(natural_heal_prev_tick + NATURAL_HEAL_INTERVAL, status_natural_heal_timer, 0, 0, NATURAL_HEAL_INTERVAL);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement