11#include "dataalloc.hpp"
14#include "editloop3.hpp"
16#include "framevu1.hpp"
17#include "mainselect.hpp"
39 {ITEM_PRICKLY, 25.0f},
40 {ITEM_THROBBING_CHERRY, 25.0f},
41 {ITEM_GOOEY_PEACH, 25.0f},
42 {ITEM_BOMB_NUTS, 25.0f},
43 {ITEM_POISONOUS_APPLE, 25.0f},
44 {ITEM_MELLOW_BANANA, 25.0f},
46 {ITEM_POTATO_CAKE, 25.0f},
49 {ITEM_PETITE_FISH, 40.0f},
52int draw_under_water = 1;
53float distp = 1.6666666f;
79sceVu0FVECTOR point[24];
80sceVu0FVECTOR old_p[24];
81sceVu0FVECTOR velo[24];
82sceVu0FVECTOR hookp[3];
83sceVu0FVECTOR hookop[3];
84sceVu0FVECTOR hookv[3];
87sceVu0FVECTOR ukiop[4];
91sceVu0FVECTOR fishhook;
94static void GetHookPos(
float *position);
97 LoadFile(
"chara/fishing.pak", read_buffer, NULL);
99 HookFrame = LoadMDSFile(GetPackFile(read_buffer,
"hari.mds", NULL), alloc, 0, NULL, NULL);
100 UkiFrame = LoadMDSFile(GetPackFile(read_buffer,
"uki.mds", NULL), alloc, 0, NULL, NULL);
104 if (UkiFrame != NULL) {
105 UkiFrame->SetAttr(attr, 1, 0x200);
108 cpoly = (
CCPoly *) alloc->Alloc(0x1800);
117 draw_under_water = 1;
120 draw_under_water = 0;
123 Fish =
new ((u_long128 *) alloc->Alloc(0xD8C))
CFish[6];
147 case ED_TIME_EVENING:
153 case ED_TIME_MORNING:
159 LoadFile(
"chara/f00s.chr", read_buffer, NULL);
161 for (
int i = 0; i < FishNum; i++) {
163 int rand_value = rand();
167 switch ((
int) (3.99999f * rnd())) {
184 int roll = 100.0f * rnd();
188 }
else if (roll < 70) {
190 }
else if (roll < 80) {
192 }
else if (roll < 100) {
199 if (rand_value % rare_interval == 0) {
200 if (rand() % 5 == 0) {
208 if (rand_value == 0) {
212 if (rand_value == 1) {
216 if (rand_value == 2) {
223 int roll = rand_value % 100;
227 }
else if (roll < 40) {
229 }
else if (roll < 60) {
231 }
else if (roll < 80) {
240 if (rand_value % rare_interval == 0) {
241 if (rand() % 5 == 0) {
247 int roll = rand_value % 100;
251 }
else if (roll < 70) {
253 }
else if (roll < 100) {
263 static int fish_type[5][8] = {
264 {1, 2, 6, 7, 1, 2, 6, 7},
265 {1, 4, 9, 10, 1, 4, 9, 10},
266 {2, 4, 6, 5, 17, 2, 4, 6},
267 {0, 3, 11, 12, 13, 0, 3, 11},
270 kind = fish_type[spot][i % 5];
274 LoadFish(&Fish[i], kind, slot, alloc, loaded);
283void FishingLoadEsa(
int item_no,
CFrameVu1 *frame,
int slot) {
285 EdGetItem(esa_info[esa_type].item_no, 1, -1);
292 for (
int i = 0; i < 13; i++) {
293 if (item_no == esa_info[i].item_no) {
300void FishingDeleteEsa() {
305int FishingGetEsaItemNo() {
310 return esa_info[esa_type].
item_no;
335 EdGetItem(esa_info[esa_type].item_no, 1, -1);
338 for (
int i = 0; i < 6; i++) {
345void FishingSetWaterLevel(
float water_level,
float ground_level) {
346 WaterLevel = water_level;
347 GroundLevel = ground_level;
348 FishingSetGroundLevel(ground_level, ground_level);
351void FishingSetGroundLevel(
float uki_height,
float hook_height) {
352 UkiGroundLevel = uki_height;
353 HookGroundLevel = hook_height;
356float FishingGetWaterLevel() {
360void FishingSetCPoly(
CCPoly *polys,
int count) {
361 for (
int i = 0; i < count; i++) {
362 memcpy(&cpoly[i], &polys[i],
sizeof(
CCPoly));
368void FishingSetRect(
CBoxVu0 bounds) {
369 memcpy(&fishing_rect, &bounds,
sizeof(
CBoxVu0));
372int FishingPickUpPoly(
CCPoly *polys) {
373 sceVu0FVECTOR corner[8];
374 sceVu0FVECTOR bound[2];
376 sceVu0CopyVector(bound[0], fishing_rect.
min);
377 sceVu0CopyVector(bound[1], fishing_rect.
max);
379 for (
int i = 0; i < 8; i++) {
381 corner[i][0] = bound[(i & 1) != 0][0];
382 corner[i][1] = bound[(i & 2) != 0][1];
383 corner[i][2] = bound[(i & 4) != 0][2];
397 for (
int i = 0; i < 8; i++) {
399 memset(poly, 0,
sizeof(
CCPoly));
401 for (
int j = 0; j < 3; j++) {
402 sceVu0CopyVector(poly->
vertex[j], corner[face[i][j]]);
411void FishingInitFish(
CBoxVu0 bounds) {
412 sceVu0FVECTOR position;
418 memcpy(&fish_rect, &bounds,
sizeof(
CBoxVu0));
420 for (
int i = 0; i < FishNum; i++) {
421 position[0] = 0.5f * (bounds.
max[0] + bounds.
min[0]);
422 position[1] = WaterLevel - 12.0f;
423 position[2] = 0.5f * (bounds.
max[2] + bounds.
min[2]);
429int FishingFishStatus(
int *fish_no) {
438 for (
int i = 0; i < 6; i++) {
439 if (fish_no != NULL) {
448 if (fish->
action == FISH_ACTION_EAT_FOOD) {
449 status = FISH_ACTION_EAT_FOOD;
455 if (fish->
action == FISH_ACTION_BITE_HOOK) {
456 return FISH_ACTION_BITE_HOOK;
459 if (fish->
action == FISH_ACTION_BATTLE) {
460 return FISH_ACTION_BATTLE;
467void FishingBattleFish(
int fish_no) {
470 if (fish_no >= 0 && fish_no < 6) {
471 CFish *fish = &Fish[fish_no];
473 if (fish->
action == FISH_ACTION_BITE_HOOK) {
480int FishingFishKind(
int fish_no) {
482 if (fish_no < 0 && fish_no >= 6) {
489void FishingBattleToAngleFish(u_int *pack,
CDataAlloc2<1> *alloc) {
490 AngleFish = BattleFish;
493 if (AngleFish != NULL) {
496 model->
LoadPackData2(pack,
"info.cfg", alloc, fish_texb + 1, alloc, 0);
500 CFish *fish = AngleFish;
505char fishing_err_format[] __attribute__((section(
".rodata"))) =
"err %d\n";
507CFish *FishingGetBattleFish() {
511void FishingAngleFish(
int fish_no) {
514 if (fish_no >= 0 && fish_no < 6) {
515 CFish *fish = &Fish[fish_no];
517 if (fish->
action == FISH_ACTION_BITE_HOOK) {
520 fish = &Fish[fish_no];
526int FishingGetAngleFishSize(
int *size,
int *fp) {
527 if (AngleFish == NULL) {
531 float length = AngleFish->
size;
532 *size = length * 10.0f;
533 *fp = AngleFish->
GetFP();
537void FishingInitFishStatus() {
539 for (
int i = 0; i < 6; i++) {
540 CFish *fish = &Fish[i];
541 fish->
action = FISH_ACTION_NONE;
548void FishingDeleteAngleFish() {
549 if (AngleFish != NULL) {
554void FishingStepFish() {
564 if (AngleFish != NULL) {
569 for (
int i = 0; i < 6; i++) {
570 if (esa_type < 0 || EsaFrame == NULL) {
574 float radius = esa_info[esa_type].
radius;
590void FishingDrawFish() {
595 if (AngleFish != NULL) {
596 TexManager.ReloadTexture(GetVif1Packet(), fish_texb + 1);
598 sceVu0FVECTOR position = {0.0f, 0.0f, 0.0f, 0.0f};
599 sceVu0FVECTOR rotation = {-1.57f, 1.57f, 0.0f, 0.0f};
605 TexManager.ReloadTexture(GetVif1Packet(), fish_texb);
607 if (draw_under_water) {
608 for (
int i = 0; i < 6; i++) {
622static void GetHookPos(
float *position) {
623 sceVu0CopyVector(position, hookp[0]);
629static int hook_link[3][2] = {
638static int uki_link[6][2] = {
647void FishLineInit(
float *position) {
654 sceVu0FVECTOR zero = {0.0f, 0.0f, 0.0f, 0.0f};
655 sceVu0CopyVector(rod_top, position);
656 sceVu0CopyVector(p, position);
659 for (i = 0; i < 24; i++) {
660 sceVu0CopyVector(point[i], p);
661 sceVu0CopyVector(old_p[i], p);
662 sceVu0CopyVector(velo[i], zero);
666 for (i = 0; i < 3; i++) {
667 sceVu0CopyVector(hookp[i], point[23]);
670 for (i = 1; i < 3; i++) {
677 for (i = 0; i < 3; i++) {
678 sceVu0CopyVector(hookop[i], hookp[i]);
679 sceVu0CopyVector(hookv[i], zero);
682 for (i = 0; i < 3; i++) {
683 hook_dist[i] = DistVector(hookp[hook_link[i][0]], hookp[hook_link[i][1]]);
686 for (i = 0; i < 4; i++) {
687 sceVu0CopyVector(ukip[i], point[18]);
690 for (i = 1; i < 4; i++) {
691 ukip[i][1] -= 0.866f;
694 ukip[1][2] += 1.005f;
695 ukip[2][0] += 0.866f;
697 ukip[3][0] -= 0.866f;
700 for (i = 0; i < 4; i++) {
701 sceVu0CopyVector(ukiop[i], ukip[i]);
702 sceVu0CopyVector(ukiv[i], zero);
705 for (i = 0; i < 6; i++) {
706 uki_dist[i] = DistVector(ukip[uki_link[i][0]], ukip[uki_link[i][1]]);
710void FishLineSetUki(
float *position,
float rate) {
711 sceVu0FVECTOR offset;
718 sceVu0SubVector(offset, position, ukip[0]);
719 sceVu0ScaleVector(offset, offset, rate);
720 sceVu0AddVector(uki, ukip[0], offset);
724void FishLineSetHook(
float *position,
float rate) {
725 sceVu0FVECTOR offset;
732 sceVu0SubVector(offset, position, hookp[0]);
733 sceVu0ScaleVector(offset, offset, rate);
734 sceVu0AddVector(fishhook, hookp[0], offset);
738void FishPullHook(
float tension) {
742void FishLineGetUki(
float *position) {
743 sceVu0CopyVector(position, point[18]);
746void FishLineGetHook(
float *position) {
747 sceVu0CopyVector(position, point[23]);
750int FishingCheckUkiHook() {
751 sceVu0FVECTOR uki_pos;
752 sceVu0FVECTOR hook_pos;
755 FishLineGetUki(uki_pos);
756 FishLineGetHook(hook_pos);
758 for (
int i = 0; i < 3; i++) {
759 if (fishing_rect.
max[i] < uki_pos[i]) {
763 if (fishing_rect.
max[i] < hook_pos[i]) {
767 if (fishing_rect.
min[i] > uki_pos[i]) {
771 if (fishing_rect.
min[i] > hook_pos[i]) {
776 water = 5.0f + FishingGetWaterLevel();
778 if (hook_pos[1] > water) {
782 if (uki_pos[1] > water) {
789void FishLineStep(
float *rod_position,
float *unused) {
790 sceVu0FVECTOR hook_from;
791 sceVu0FVECTOR hook_to;
792 sceVu0FVECTOR uki_from;
793 sceVu0FVECTOR uki_to;
795 sceVu0FVECTOR normal;
805 sceVu0CopyVector(hook_from, point[23]);
806 sceVu0CopyVector(hook_to, point[23]);
807 hook_from[1] += 40.0f;
809 int hit_no = CheckHit(cpoly, cpoly_num, hook_from, hook_to, hit, 1, 0);
812 sceVu0Normalize(normal, cpoly[hit_no].normal);
813 float slope = normal[1] < 0.0f ? -normal[1] : normal[1];
816 HookGroundLevel = 0.2f + hit[1];
820 sceVu0CopyVector(uki_from, point[18]);
821 sceVu0CopyVector(uki_to, point[18]);
822 uki_from[1] += 40.0f;
824 hit_no = CheckHit(cpoly, cpoly_num, uki_from, uki_to, hit, 1, 0);
827 sceVu0Normalize(normal, cpoly[hit_no].normal);
828 float slope = normal[1] < 0.0f ? -normal[1] : normal[1];
831 UkiGroundLevel = 1.0f + hit[1];
836 if (UkiGroundLevel < HookGroundLevel) {
837 LineGroundLevel = UkiGroundLevel;
839 LineGroundLevel = HookGroundLevel;
844 sceVu0CopyVector(rod_top, rod_position);
848 for (i = 0; i < 24; i++) {
851 sceVu0AddVector(point[i], point[i], velo[i]);
855 point[23][1] += weight;
857 for (i = 0; i < 3; i++) {
858 hookv[i][1] += -0.1f + weight;
860 sceVu0AddVector(hookp[i], hookp[i], hookv[i]);
863 for (i = 0; i < 4; i++) {
864 ukiv[i][1] += -0.1f + weight;
866 sceVu0AddVector(ukip[i], ukip[i], ukiv[i]);
869 for (iteration = 0; iteration < 16; iteration++) {
870 sceVu0CopyVector(point[0], rod_top);
871 sceVu0CopyVector(old_p[0], rod_top);
873 for (i = 1; i < 24; i++) {
880 float rest = 1.0f - weight;
881 float *near = point[i - 1];
882 float *far = point[i];
883 sceVu0SubVector(diff, near, far);
884 float length = DistVector(diff);
885 float stretch = length - distp;
886 float scale = rest * stretch / length;
887 weight = weight * stretch / length;
888 sceVu0ScaleVector(move0, diff, scale);
889 sceVu0ScaleVector(move1, diff, weight);
890 sceVu0SubVector(near, near, move0);
891 sceVu0AddVector(far, far, move1);
894 sceVu0CopyVector(hookp[0], point[23]);
896 for (i = 0; i < 3; i++) {
897 sceVu0SubVector(diff, hookp[hook_link[i][0]], hookp[hook_link[i][1]]);
898 float length = DistVector(diff);
899 sceVu0ScaleVector(move0, diff, 0.5f * (length - hook_dist[i]) / length);
900 sceVu0SubVector(hookp[hook_link[i][0]], hookp[hook_link[i][0]], move0);
901 sceVu0AddVector(hookp[hook_link[i][1]], hookp[hook_link[i][1]], move0);
904 sceVu0SubVector(diff, point[18], ukip[0]);
905 float length = DistVector(diff);
907 float scale = length * (1.0f - weight) / length;
908 weight = length * weight / length;
909 sceVu0ScaleVector(move0, diff, scale);
910 sceVu0ScaleVector(move1, diff, weight);
911 sceVu0SubVector(point[18], point[18], move0);
912 sceVu0AddVector(ukip[0], ukip[0], move1);
914 for (i = 0; i < 6; i++) {
915 sceVu0SubVector(diff, ukip[uki_link[i][0]], ukip[uki_link[i][1]]);
916 float length = DistVector(diff);
917 sceVu0ScaleVector(move0, diff, 0.5f * (length - uki_dist[i]) / length);
918 sceVu0SubVector(ukip[uki_link[i][0]], ukip[uki_link[i][0]], move0);
919 sceVu0AddVector(ukip[uki_link[i][1]], ukip[uki_link[i][1]], move0);
923 sceVu0CopyVector(point[23], fishhook);
924 sceVu0CopyVector(hookp[0], fishhook);
928 sceVu0CopyVector(point[18], uki);
929 sceVu0CopyVector(ukip[0], uki);
933 for (i = 0; i < 24; i++) {
934 sceVu0SubVector(velo[i], point[i], old_p[i]);
937 sceVu0ScaleVector(velo[i], velo[i], 0.96f);
939 sceVu0ScaleVector(velo[i], velo[i], 0.999f);
942 if (point[i][1] < LineGroundLevel) {
943 point[i][1] = LineGroundLevel;
949 if (point[i][1] < water) {
950 sceVu0ScaleVector(velo[i], velo[i], 0.4f);
957 sceVu0CopyVector(old_p[i], point[i]);
960 for (i = 0; i < 3; i++) {
961 sceVu0SubVector(hookv[i], hookp[i], hookop[i]);
963 if (hookp[i][1] < HookGroundLevel) {
964 hookp[i][1] = HookGroundLevel;
966 hookv[i][1] *= -0.6f;
970 sceVu0CopyVector(hookop[i], hookp[i]);
971 sceVu0ScaleVector(hookv[i], hookv[i], 0.99f);
974 for (i = 0; i < 4; i++) {
975 sceVu0SubVector(ukiv[i], ukip[i], ukiop[i]);
977 if (ukip[i][1] < UkiGroundLevel) {
978 ukip[i][1] = UkiGroundLevel;
984 if (i != 0 && ukip[i][1] < water && ukip[0][1] < water) {
985 sceVu0ScaleVector(ukiv[i], ukiv[i], 0.6f);
989 if (ukip[0][1] < water && !(ukip[i][1] < water)) {
990 float height = ukip[0][1] - ukip[i][1];
991 float depth = ukip[0][1] - ukip[i][1];
992 height = depth < 0.0f ? -depth : height;
996 if ((depth < 0.0f ? -depth : depth) > 0.001f) {
997 ukiv[i][1] += 0.3f * (water - ukip[0][1]) / height;
1001 if (ukip[i][1] < water && !(ukip[0][1] < water)) {
1002 float height = ukip[i][1] - ukip[0][1];
1003 height = height < 0.0f ? -height : height;
1004 float depth = ukip[0][1] - ukip[i][1];
1006 if ((depth < 0.0f ? -depth : depth) > 0.001f) {
1007 ukiv[i][1] += 0.3f * (water - ukip[i][1]) / height;
1011 sceVu0CopyVector(ukiop[i], ukip[i]);
1012 sceVu0ScaleVector(ukiv[i], ukiv[i], 0.999f);
1015 LineGroundLevel = HookGroundLevel = UkiGroundLevel = GroundLevel;
1021void FishLineDraw(
int above_water) {
1023 sceVu0FVECTOR center;
1024 sceVu0FVECTOR direction;
1025 sceVu0FMATRIX matrix;
1026 sceVu0FVECTOR uki_top;
1027 sceVu0FVECTOR hook_top;
1028 sceVu0FVECTOR esa_position;
1036 TexManager.ReloadTexture(GetVif1Packet(), fishing_texb);
1038 packet = GetVif1Packet();
1039 sceVif1PkCnt(packet, 0);
1040 sceVif1PkOpenDirectCode(packet, 0);
1041 sceVif1PkOpenGifTag(packet, *(u_long128 *) &GiftagAD);
1042 sceVif1PkAddGsAD(packet, SCE_GS_PRIM, SCE_GS_SET_PRIM(2, 1, 0, 0, 1, 0, 1, 0, 0));
1043 sceVif1PkAddGsAD(packet, SCE_GS_RGBAQ, SCE_GS_SET_RGBAQ(0x80, 0x80, 0x80, 0x80, 0));
1046 sceVif1PkAddGsAD(packet, SCE_GS_TEST_1, *(u_long *) &test);
1048 for (i = 0; i < 24; i++) {
1049 visible = MGRotTransPers(screen, point[i], 0);
1050 u_char above = point[i][1] > WaterLevel;
1051 int reg = SCE_GS_XYZF2;
1053 if (visible == 0 || prev_visible == 0) {
1061 }
else if (above || draw_under_water == 0) {
1065 sceVif1PkAddGsAD(packet, reg, (u_long) screen[0] | ((u_long) screen[1] << 16) | ((u_long) screen[2] << 32));
1066 prev_visible = visible;
1069 sceVif1PkAddGsAD(packet, SCE_GS_TEST_1, *(u_long *) &mgPixelTest);
1070 sceVif1PkCloseGifTag(packet);
1071 sceVif1PkCloseDirectCode(packet);
1074 VectorMax(uki_top, ukip[0], ukip[1], ukip[2], ukip[3]);
1077 if (uki_top[1] < WaterLevel) {
1080 }
else if (uki_top[1] > WaterLevel || draw_under_water == 0) {
1084 if (UkiFrame != NULL && draw) {
1085 sceVu0AddVector(center, ukip[1], ukip[2]);
1086 sceVu0AddVector(center, center, ukip[3]);
1087 sceVu0ScaleVector(center, center, 0.333333f);
1088 sceVu0SubVector(direction, ukip[0], center);
1089 sceVu0Normalize(matrix[1], direction);
1090 matrix[1][3] = 0.0f;
1091 sceVu0SubVector(direction, center, ukip[1]);
1092 sceVu0Normalize(matrix[2], direction);
1093 sceVu0OuterProduct(matrix[0], matrix[1], matrix[2]);
1094 matrix[0][3] = 0.0f;
1095 matrix[3][0] = matrix[3][1] = matrix[3][2] = 0.0f;
1096 matrix[3][3] = 1.0f;
1098 UkiFrameTop.SetTransMatrix(matrix);
1099 UkiFrameTop.SetPosition(ukip[0]);
1100 UkiFrame->SetReference(&UkiFrameTop);
1105 VectorMax(hook_top, hookp[0], hookp[1], hookp[2]);
1108 if (hook_top[1] < WaterLevel) {
1111 }
else if (hook_top[1] > WaterLevel || draw_under_water == 0) {
1115 if (HookFrame != NULL && draw) {
1116 sceVu0AddVector(center, hookp[1], hookp[2]);
1117 sceVu0ScaleVector(center, center, 0.5f);
1118 sceVu0SubVector(direction, hookp[0], center);
1119 sceVu0Normalize(matrix[1], direction);
1120 matrix[1][3] = 0.0f;
1121 sceVu0SubVector(center, hookp[1], hookp[0]);
1122 sceVu0SubVector(direction, hookp[2], hookp[0]);
1123 sceVu0OuterProduct(matrix[2], center, direction);
1124 sceVu0Normalize(matrix[2], matrix[2]);
1125 matrix[2][3] = 0.0f;
1126 sceVu0OuterProduct(matrix[0], matrix[1], matrix[2]);
1127 matrix[0][3] = 0.0f;
1128 matrix[3][0] = matrix[3][1] = matrix[3][2] = 0.0f;
1129 matrix[3][3] = 1.0f;
1130 HookFrame->SetTransMatrix(matrix);
1131 HookFrame->SetPosition(hookp[0]);
1134 if (EsaFrame != NULL) {
1135 sceVu0AddVector(esa_position, hookp[0], hookp[1]);
1136 sceVu0AddVector(esa_position, esa_position, hookp[2]);
1137 sceVu0ScaleVector(esa_position, esa_position, 0.3333f);
1138 EsaFrame->SetTransMatrix(matrix);
1139 EsaFrame->SetPosition(esa_position);
1140 TexManager.ReloadTexture(GetVif1Packet(), esa_texb);
virtual void LoadPackData2(unsigned int *pack, char *name, CDataAlloc2< 1 > *alloc, int texture_block_no, CDataAlloc2< 1 > *image_alloc, int visual_type)
virtual void Initialize()
void SetPosition(float *position)
void SetRotation(float *rotation)
void SetCPoly(CCPoly *polys, int count)
void SetFoodPos(int kind, float *position, float radius)
void SetReference(CFrame *reference)
virtual void Initialize()